[FIX] web_editor: focus issue in banner
Before this commit: - Inserting a banner did not set focus inside the banner; instead, focus was placed after the banner. After this commit: - Now, upon creating a banner, focus is now correctly set inside the banner. task-3432167 X-original-commit: 7327d20626ec9164f47e00f7094a36b8794db5de Part-of: odoo/odoo#151735
This commit is contained in:
@@ -2116,6 +2116,15 @@ export class OdooEditor extends EventTarget {
|
||||
return didDeselectTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* `activateContenteditable` serves as an interface for external use,
|
||||
* allowing users to conveniently trigger `_activateContenteditable`
|
||||
* from outside the odooEditor.
|
||||
*/
|
||||
activateContenteditable() {
|
||||
this._activateContenteditable();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -2304,7 +2304,8 @@ export class Wysiwyg extends Component {
|
||||
</div>
|
||||
`).childNodes[0];
|
||||
this.odooEditor.execCommand('insert', bannerElement);
|
||||
setSelection(bannerElement.querySelector('.o_editor_banner > div'), 0);
|
||||
this.odooEditor.activateContenteditable();
|
||||
setSelection(bannerElement.querySelector('.o_editor_banner > div > p'), 0);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,5 +81,24 @@ QUnit.module(
|
||||
</div><p><br></p>`,
|
||||
);
|
||||
});
|
||||
QUnit.test("should have focus inside banner when new banner is created", async function (assert) {
|
||||
const { editor, editable } = onMount();
|
||||
const node = editable.querySelector("p");
|
||||
setSelection(node, 0);
|
||||
insertText(editor, "Test");
|
||||
setSelection(node.firstChild, 3, node.firstChild, 3);
|
||||
insertText(editor, '/banner');
|
||||
triggerEvent(editor.editable, "keydown", { key: "Enter" });
|
||||
await nextTick();
|
||||
assert.strictEqual(
|
||||
editable.innerHTML,
|
||||
`<p>Test</p><div class="o_editor_banner o_not_editable lh-1 d-flex align-items-center alert alert-info pb-0 pt-3" role="status" data-oe-protected="true" contenteditable="false">
|
||||
<i class="fs-4 fa fa-info-circle mb-3" aria-label="Banner Info"></i>
|
||||
<div class="w-100 ms-3" data-oe-protected="false" contenteditable="true">
|
||||
<p placeholder=\"Type "/" for commands\" class=\"oe-hint oe-command-temporary-hint\"><br></p>
|
||||
</div>
|
||||
</div><p><br></p>`,
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user