diff --git a/addons/web/static/src/core/select_menu/select_menu.js b/addons/web/static/src/core/select_menu/select_menu.js index 1aed04b605b..f0f4e15efec 100644 --- a/addons/web/static/src/core/select_menu/select_menu.js +++ b/addons/web/static/src/core/select_menu/select_menu.js @@ -4,6 +4,7 @@ import { Component, useState, useRef } from "@odoo/owl"; import { Dropdown } from "@web/core/dropdown/dropdown"; import { DropdownItem } from "@web/core/dropdown/dropdown_item"; import { _lt } from "@web/core/l10n/translation"; +import { shallowEqual } from "@web/core/utils/objects"; import { useDebounced } from "@web/core/utils/timing"; import { scrollTo } from "@web/core/utils/scrolling"; import { fuzzyLookup } from "@web/core/utils/search"; @@ -89,9 +90,15 @@ export class SelectMenu extends Component { get displayValue() { if (this.props.value !== undefined) { const choices = [...this.props.choices, ...this.props.groups.flatMap((g) => g.choices)]; - const value = choices.find((c) => c.value === this.props.value); + const value = choices.find((c) => { + if (typeof c.value === "object" && typeof this.props.value === "object") { + return shallowEqual(c.value, this.props.value); + } + return c.value === this.props.value; + }); return value ? value.label : this.props.value; } + return ""; } onOpened() { diff --git a/addons/web/static/tests/core/select_menu_tests.js b/addons/web/static/tests/core/select_menu_tests.js index 60a4da27444..3ef884d0579 100644 --- a/addons/web/static/tests/core/select_menu_tests.js +++ b/addons/web/static/tests/core/select_menu_tests.js @@ -178,6 +178,58 @@ QUnit.module("Web Components", (hooks) => { assert.equal(document.activeElement, target.querySelector(".o_select_menu_input input")); }); + QUnit.test("value props accept array", async (assert) => { + class Parent extends Component { + setup() { + this.choices = [ + { label: "Z", value: [1, 2] }, + { label: "A", value: [1, 3] }, + ]; + this.value = [1, 2]; + } + } + Parent.components = { SelectMenu }; + Parent.template = xml` + + `; + + await mount(Parent, target, { env }); + assert.equal( + target.querySelector(".o_select_menu_toggler_slot").innerText, + "Z", + `The select value shoud be "Z"` + ); + }); + + QUnit.test("value props accept object", async (assert) => { + class Parent extends Component { + setup() { + this.choices = [ + { label: "Z", value: { hello: "world" } }, + { label: "A", value: { paper: "company" } }, + ]; + this.value = { paper: "company" }; + } + } + Parent.components = { SelectMenu }; + Parent.template = xml` + + `; + + await mount(Parent, target, { env }); + assert.equal( + target.querySelector(".o_select_menu_toggler_slot").innerText, + "A", + `The select value shoud be "A"` + ); + }); + QUnit.test( "Clear button calls 'onSelect' with null value and appears only when value is not null", async (assert) => {