8000 [FIX] html_editor: focus image link popover URL input by default · odoo/odoo@da58fe6 · GitHub
[go: up one dir, main page]

Skip to content

Commit da58fe6

Browse files
committed
[FIX] html_editor: focus image link popover URL input by default
Steps to reproduce: - Insert an image (e.g., type /media) - Convert image into link. - URL input is not automatically focused when the image link popover opens. - Popover remains open on Escape because it does not receive focus. Before this commit: - When converting an image into a link, the image link popover did not have a label input. As a result, the URL input did not receive focus by default. - Pressing Escape key did not close the popover because it never gained focus. After this commit: - The URL input in the image link popover is now focused by default, and pressing the Escape key closes the popover. task-4752206 closes #208221 Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
1 parent 39007b7 commit da58fe6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

addons/html_editor/static/src/main/link/link_popover.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class LinkPopover extends Component {
6868
});
6969

7070
this.editingWrapper = useRef("editing-wrapper");
71-
this.inputRef = useRef(this.state.isImage || "label");
71+
this.inputRef = useRef(this.state.isImage ? "url" : "label");
7272
useEffect(
7373
(el) => {
7474
if (el) {

addons/html_editor/static/tests/link/popover.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,18 @@ describe("Link creation", () => {
510510
'<p><a href="https://test.com">Hello[]</a></p>'
511511
);
512512
});
513+
test("when you open image link popover, url input should be focus by default", async () => {
514+
const { el } = await setupEditor(`<p>[<img src="${base64Img}">]</p>`);
515+
await waitFor(".o-we-toolbar");
516+
await click(".o-we-toolbar .fa-link");
517+
await waitFor(".o-we-linkpopover", { timeout: 1500 });
518+
expect(".o-we-linkpopover input.o_we_href_input_link").toBeFocused();
519+
520+
await press("escape");
521+
await waitForNone(".o-we-linkpopover", { timeout: 1500 });
522+
expect(".o-we-linkpopover").toHaveCount(0);
523+
expect(getContent(el)).toBe(`<p><img src="${base64Img}"></p>`);
524+
});
513525
test("should be correctly unlink/link", async () => {
514526
const { el } = await setupEditor('<p>aaaa[b<a href="http://test.com/">cd</a>e]f</p>');
515527
await waitFor(".o-we-toolbar");

0 commit comments

Comments
 (0)
0