FIX: do not auto close on empty identifiers (#27001)

Prior to this fix all menus with empty identifier or groupIdentifier would be considered to be part of the same identifiers/groupIdentifiers and would auto close any existing d-menu with no identifier/groupIdentifier when opened.
This commit is contained in:
Joffrey JAFFEUX 2024-05-13 14:43:26 +02:00 committed by GitHub
parent 742a3b138d
commit f840f37a54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 3 deletions

View File

@ -311,6 +311,22 @@ module("Integration | Component | FloatKit | d-menu", function (hooks) {
assert.dom(".fk-d-menu__content.second").exists();
});
test("empty @identifier/@groupIdentifier", async function (assert) {
await render(
hbs`<DMenu @inline={{true}} @class="first">1</DMenu><DMenu @inline={{true}} @class="second">2</DMenu>`
);
await click(".first.fk-d-menu__trigger");
assert.dom(".fk-d-menu__content.first").exists();
assert.dom(".fk-d-menu__content.second").doesNotExist();
await click(".second.fk-d-menu__trigger");
assert.dom(".fk-d-menu__content.first").exists("it doesnt autoclose");
assert.dom(".fk-d-menu__content.second").exists();
});
test("@class", async function (assert) {
await render(hbs`<DMenu @inline={{true}} @class="first">1</DMenu>`);

View File

@ -52,9 +52,12 @@ export default class Menu extends Service {
if (instance.options.identifier || instance.options.groupIdentifier) {
for (const registeredMenu of this.registeredMenus) {
if (
(registeredMenu.options.identifier === instance.options.identifier ||
registeredMenu.options.groupIdentifier ===
instance.options.groupIdentifier) &&
((instance.options.identifier &&
registeredMenu.options.identifier ===
instance.options.identifier) ||
(instance.options.groupIdentifier &&
registeredMenu.options.groupIdentifier ===
instance.options.groupIdentifier)) &&
registeredMenu !== instance
) {
await this.close(registeredMenu);