mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: allows to get a menu by its identifier (#26968)
Usage: ```javascript this.menu.getByIdentifier("foo"); ```
This commit is contained in:
parent
38c1312dfb
commit
46371fe9e4
@ -265,4 +265,17 @@ module("Integration | Component | FloatKit | d-menu", function (hooks) {
|
||||
|
||||
assert.dom(".fk-d-menu__content.test-content").doesNotExist();
|
||||
});
|
||||
|
||||
test("get a menu by identifier", async function (assert) {
|
||||
await render(hbs`<DMenu @inline={{true}} @identifier="test">test</DMenu>`);
|
||||
await open();
|
||||
|
||||
const activeMenu = getOwner(this)
|
||||
.lookup("service:menu")
|
||||
.getByIdentifier("test");
|
||||
|
||||
await activeMenu.close();
|
||||
|
||||
assert.dom(".fk-d-menu__content.test-content").doesNotExist();
|
||||
});
|
||||
});
|
||||
|
@ -78,8 +78,22 @@ export default class Menu extends Service {
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the active menu
|
||||
* @param {DMenuInstance} [menu] - the menu to close, if not provider will close any active menu
|
||||
* Returns an existing menu by its identifier if found
|
||||
*
|
||||
* @param {String} identifier - the menu identifier to retrieve
|
||||
*
|
||||
* @returns {Promise<DMenuInstance>}
|
||||
*/
|
||||
getByIdentifier(identifier) {
|
||||
return this.registeredMenus.find(
|
||||
(registeredMenu) => registeredMenu.options.identifier === identifier
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the given menu
|
||||
*
|
||||
* @param {DMenuInstance | String} [menu | identifier] - the menu to close, can accept an instance or an identifier
|
||||
*/
|
||||
@action
|
||||
async close(menu) {
|
||||
|
Loading…
Reference in New Issue
Block a user