-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract common sub-menu logic into reusable mixin (#8273)
- Loading branch information
1 parent
91db0a0
commit 4dc1add
Showing
3 changed files
with
55 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2019 - 2024 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
*/ | ||
import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js'; | ||
import { ContextMenuMixin } from '@vaadin/context-menu/src/vaadin-context-menu-mixin.js'; | ||
|
||
/** | ||
* @polymerMixin | ||
* @mixes ContextMenuMixin | ||
* @mixes OverlayClassMixin | ||
*/ | ||
export const SubMenuMixin = (superClass) => | ||
class SubMenuMixinClass extends ContextMenuMixin(OverlayClassMixin(superClass)) { | ||
constructor() { | ||
super(); | ||
|
||
this.openOn = 'opensubmenu'; | ||
} | ||
|
||
/** | ||
* Tag name prefix used by overlay, list-box and items. | ||
* @protected | ||
* @return {string} | ||
*/ | ||
get _tagNamePrefix() { | ||
return 'vaadin-menu-bar'; | ||
} | ||
|
||
/** | ||
* Overriding the observer to not add global "contextmenu" listener. | ||
*/ | ||
_openedChanged(opened) { | ||
this._overlayElement.opened = opened; | ||
} | ||
|
||
/** | ||
* Overriding the public method to reset expanded button state. | ||
*/ | ||
close() { | ||
super.close(); | ||
|
||
// Only handle 1st level submenu | ||
if (this.hasAttribute('is-root')) { | ||
this.getRootNode().host._close(); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters