-
Notifications
You must be signed in to change notification settings - Fork 0
/
p-a2384989.js
5 lines (5 loc) · 1.96 KB
/
p-a2384989.js
1
2
3
4
5
/*!
* Built by BASIS
* Copyright BASIS International Ltd.
*/
class t{constructor(t){this.el=t}async setFocus(){var t,e;const s=null===(e=(t=this.el.shadowRoot.querySelector("slot")).assignedElements)||void 0===e?void 0:e.call(t,{flatten:!0}).filter((t=>"dwc-menuitem"===t.tagName.toLowerCase()&&!t.hasAttribute("disabled")))[0];s&&await s.setFocus()}async removeFocus(){const t=document.activeElement;t&&this.el.contains(t)&&await t.removeFocus()}close(){this.getMenuItems().forEach((t=>t.close()))}getMenuItems(){var t,e;return(null===(e=(t=this.el.shadowRoot.querySelector("slot")).assignedElements)||void 0===e?void 0:e.call(t,{flatten:!0}).filter((t=>"dwc-menuitem"===t.tagName.toLowerCase())))||[]}getMenuItemsWithSeparators(){var t,e;return null===(e=(t=this.el.shadowRoot.querySelector("slot")).assignedElements)||void 0===e?void 0:e.call(t,{flatten:!0}).filter((t=>"dwc-menuitem"===t.tagName.toLowerCase()||"dwc-separator"===t.tagName.toLowerCase()))}getNextItem(t){let e=t.nextElementSibling;for(;e&&"dwc-menuitem"!==e.nodeName.toLowerCase()||(null==e?void 0:e.hasAttribute("disabled"));)e=e.nextElementSibling;return e}getPreviousItem(t){let e=t.previousElementSibling;for(;e&&"dwc-menuitem"!==e.nodeName.toLowerCase()||(null==e?void 0:e.hasAttribute("disabled"));)e=e.previousElementSibling;return e}async focusItem(t){this.resetTabTraversable(),t.tabTraversable=0,await t.setFocus()}async focusNextItem(t){const e=this.getNextItem(t);return e&&await this.focusItem(e),e}async focusPreviousItem(t){const e=this.getPreviousItem(t);return e&&await this.focusItem(e),e}closeDropdownsBut(t){this.getMenuItems().forEach((e=>{e.isSameNode(t)||e.close()}))}resetTabTraversable(){this.getMenuItems().forEach((t=>{t.tabTraversable=-1}))}markFirstFocusableItem(){const t=this.getMenuItems(),e=Array.from(t).find((t=>!t.hasAttribute("disabled")));e&&(e.tabTraversable=0)}updateItemsProperties(t={}){this.getMenuItems().forEach((e=>{for(const s in t){const i=t[s];void 0!==i&&(e[s]=i)}}))}}export{t as D}