import { dropdown_styles_default } from "./chunk.DY6ZNNWZ.js"; import { getTabbableBoundary } from "./chunk.LXDTFLWU.js"; import { SlPopup } from "./chunk.SJLA5ROP.js"; import { getAnimation, setDefaultAnimation } from "./chunk.RCZVQXWP.js"; import { waitForEvent } from "./chunk.B4BZKR24.js"; import { animateTo, stopAnimations } from "./chunk.S7GYYU7Z.js"; import { LocalizeController } from "./chunk.NH3SRVOC.js"; import { e } from "./chunk.UZVKBFXH.js"; import { watch } from "./chunk.FA5RT4K4.js"; import { ShoelaceElement, e as e2, n } from "./chunk.SEXBCYCU.js"; import { x } from "./chunk.CXZZ2LVK.js"; import { __decorateClass } from "./chunk.KIILAQWQ.js"; // src/components/dropdown/dropdown.component.ts var SlDropdown = class extends ShoelaceElement { constructor() { super(...arguments); this.localize = new LocalizeController(this); this.open = false; this.placement = "bottom-start"; this.disabled = false; this.stayOpenOnSelect = false; this.distance = 0; this.skidding = 0; this.hoist = false; this.handleKeyDown = (event) => { if (this.open && event.key === "Escape") { event.stopPropagation(); this.hide(); this.focusOnTrigger(); } }; this.handleDocumentKeyDown = (event) => { var _a; if (event.key === "Escape" && this.open && !this.closeWatcher) { event.stopPropagation(); this.focusOnTrigger(); this.hide(); return; } if (event.key === "Tab") { if (this.open && ((_a = document.activeElement) == null ? void 0 : _a.tagName.toLowerCase()) === "sl-menu-item") { event.preventDefault(); this.hide(); this.focusOnTrigger(); return; } setTimeout(() => { var _a2, _b, _c; const activeElement = ((_a2 = this.containingElement) == null ? void 0 : _a2.getRootNode()) instanceof ShadowRoot ? (_c = (_b = document.activeElement) == null ? void 0 : _b.shadowRoot) == null ? void 0 : _c.activeElement : document.activeElement; if (!this.containingElement || (activeElement == null ? void 0 : activeElement.closest(this.containingElement.tagName.toLowerCase())) !== this.containingElement) { this.hide(); } }); } }; this.handleDocumentMouseDown = (event) => { const path = event.composedPath(); if (this.containingElement && !path.includes(this.containingElement)) { this.hide(); } }; this.handlePanelSelect = (event) => { const target = event.target; if (!this.stayOpenOnSelect && target.tagName.toLowerCase() === "sl-menu") { this.hide(); this.focusOnTrigger(); } }; } connectedCallback() { super.connectedCallback(); if (!this.containingElement) { this.containingElement = this; } } firstUpdated() { this.panel.hidden = !this.open; if (this.open) { this.addOpenListeners(); this.popup.active = true; } } disconnectedCallback() { super.disconnectedCallback(); this.removeOpenListeners(); this.hide(); } focusOnTrigger() { const trigger = this.trigger.assignedElements({ flatten: true })[0]; if (typeof (trigger == null ? void 0 : trigger.focus) === "function") { trigger.focus(); } } getMenu() { return this.panel.assignedElements({ flatten: true }).find((el) => el.tagName.toLowerCase() === "sl-menu"); } handleTriggerClick() { if (this.open) { this.hide(); } else { this.show(); this.focusOnTrigger(); } } async handleTriggerKeyDown(event) { if ([" ", "Enter"].includes(event.key)) { event.preventDefault(); this.handleTriggerClick(); return; } const menu = this.getMenu(); if (menu) { const menuItems = menu.getAllItems(); const firstMenuItem = menuItems[0]; const lastMenuItem = menuItems[menuItems.length - 1]; if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) { event.preventDefault(); if (!this.open) { this.show(); await this.updateComplete; } if (menuItems.length > 0) { this.updateComplete.then(() => { if (event.key === "ArrowDown" || event.key === "Home") { menu.setCurrentItem(firstMenuItem); firstMenuItem.focus(); } if (event.key === "ArrowUp" || event.key === "End") { menu.setCurrentItem(lastMenuItem); lastMenuItem.focus(); } }); } } } } handleTriggerKeyUp(event) { if (event.key === " ") { event.preventDefault(); } } handleTriggerSlotChange() { this.updateAccessibleTrigger(); } // // Slotted triggers can be arbitrary content, but we need to link them to the dropdown panel with `aria-haspopup` and // `aria-expanded`. These must be applied to the "accessible trigger" (the tabbable portion of the trigger element // that gets slotted in) so screen readers will understand them. The accessible trigger could be the slotted element, // a child of the slotted element, or an element in the slotted element's shadow root. // // For example, the accessible trigger of an is a