diff --git a/addons/web/static/src/core/dropdown/dropdown.js b/addons/web/static/src/core/dropdown/dropdown.js index 3925792f75f..c86f524f395 100644 --- a/addons/web/static/src/core/dropdown/dropdown.js +++ b/addons/web/static/src/core/dropdown/dropdown.js @@ -100,6 +100,7 @@ export class Dropdown extends Component { if (["left", "right"].includes(direction) && localization.direction === "rtl") { direction = direction === "left" ? "right" : "left"; } + this.defaultDirection = direction; const positioningOptions = { popper: "menuRef", position, @@ -186,6 +187,11 @@ export class Dropdown extends Component { return; } } + + if (!stateSlice.open) { + this.state.directionCaretClass = DIRECTION_CARET_CLASS[this.defaultDirection]; + } + // Update the state Object.assign(this.state, stateSlice); // Notify over the bus diff --git a/addons/web/static/src/core/signature/name_and_signature.xml b/addons/web/static/src/core/signature/name_and_signature.xml index 21530b274a3..b572b302ba2 100644 --- a/addons/web/static/src/core/signature/name_and_signature.xml +++ b/addons/web/static/src/core/signature/name_and_signature.xml @@ -70,7 +70,7 @@
- + diff --git a/addons/web/static/tests/core/dropdown_tests.js b/addons/web/static/tests/core/dropdown_tests.js index eb072562844..56ccb9b9c08 100644 --- a/addons/web/static/tests/core/dropdown_tests.js +++ b/addons/web/static/tests/core/dropdown_tests.js @@ -1079,6 +1079,46 @@ QUnit.module("Components", ({ beforeEach }) => { ); }); + QUnit.test("caret should be repositioned to default direction when closed", async (assert) => { + class Parent extends Component { + static components = { Dropdown }; + static template = xml` +
+ + 🍋 +
+ + `; + } + // The fixture should be shown for this test, as the positioning container is the html node + target.style.position = "fixed"; + target.style.top = "0"; + target.style.left = "0"; + + env = await makeTestEnv(); + await mount(Parent, target, { env }); + const dropdown = target.querySelector(".o-dropdown"); + assert.doesNotHaveClass(dropdown, "show"); + assert.hasClass(dropdown, "dropdown"); + + // open + await click(target, ".dropdown-toggle"); + await nextTick(); // awaits for the caret to get patched + assert.hasClass(dropdown, "show"); + assert.hasClass(dropdown, "dropend"); + + // close + await click(target, ".dropdown-toggle"); + assert.doesNotHaveClass(dropdown, "show"); + assert.hasClass(dropdown, "dropdown"); + + // open + await click(target, ".dropdown-toggle"); + await nextTick(); // awaits for the caret to get patched + assert.hasClass(dropdown, "show"); + assert.hasClass(dropdown, "dropend"); + }); + QUnit.test( "multi-level dropdown: mouseentering a dropdown item should close any subdropdown", async (assert) => {