@dialpad/dialtone
Version:
Dialpad's Dialtone design system monorepo
2 lines • 6.14 kB
JavaScript
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require(`../../chunk-Bmb41Sf3.cjs`);const e=require(`../../common/constants/index.cjs`),t=require(`../../common/utils/index.cjs`),n=require(`../../_plugin-vue_export-helper-D8jCH6HB.cjs`),r=require(`../../common/mixins/keyboard-list-navigation.cjs`),i=require(`../list-item/list-item-constants.cjs`),a=require(`../popover/popover-constants.cjs`),o=require(`../popover/popover.cjs`),s=require(`./dropdown-constants.cjs`);let c=require(`vue`);var l={compatConfig:{MODE:3},name:`DtDropdown`,components:{DtPopover:o.default},mixins:[r.default({indexKey:`highlightIndex`,idKey:`highlightId`,listElementKey:`getListElement`,listItemRole:`menuitem`,afterHighlightMethod:`afterHighlight`,beginningOfListMethod:`beginningOfListMethod`,endOfListMethod:`endOfListMethod`,activeItemKey:`activeItemEl`,focusOnKeyboardNavigation:!0})],inheritAttrs:!1,props:{open:{type:Boolean,default:null},openOnContext:{type:Boolean,default:!1},padding:{type:String,default:`small`,validator:e=>Object.keys(s.DROPDOWN_PADDING_CLASSES).some(t=>t===e)},modal:{type:Boolean,default:!0},contentWidth:{type:String,default:null},maxHeight:{type:String,default:``},maxWidth:{type:String,default:``},listId:{type:String,default(){return t.getUniqueString()}},navigationType:{type:String,default:i.LIST_ITEM_NAVIGATION_TYPES.ARROW_KEYS,validator:e=>Object.values(i.LIST_ITEM_NAVIGATION_TYPES).includes(e)},fallbackPlacements:{type:Array,default:()=>[`auto`]},placement:{type:String,default:`bottom`},onBeginningOfList:{type:Function,default:null},onEndOfList:{type:Function,default:null},listClass:{type:[String,Array,Object],default:``},appendTo:{type:[HTMLElement,String],default:`body`,validator:e=>a.POPOVER_APPEND_TO_VALUES.includes(e)||e instanceof HTMLElement},tether:{type:Boolean,default:!0},transition:{type:String,default:`fade`}},emits:[`keydown`,`highlight`,`update:open`,`opened`],data(){return{LIST_ITEM_NAVIGATION_TYPES:i.LIST_ITEM_NAVIGATION_TYPES,DROPDOWN_PADDING_CLASSES:s.DROPDOWN_PADDING_CLASSES,EVENT_KEYNAMES:e.EVENT_KEYNAMES,openedWithKeyboard:!1,isOpen:null}},computed:{dropdownListeners(){return{"update:open":e=>{this.$emit(`update:open`,e)},opened:e=>{this.updateInitialHighlightIndex(e)},keydown:t=>{switch(t.code){case e.EVENT_KEYNAMES.up:case e.EVENT_KEYNAMES.arrowup:this.onUpKeyPress(t),t.stopPropagation(),t.preventDefault();break;case e.EVENT_KEYNAMES.down:case e.EVENT_KEYNAMES.arrowdown:this.onDownKeyPress(t),t.stopPropagation(),t.preventDefault();break;case e.EVENT_KEYNAMES.space:case e.EVENT_KEYNAMES.spacebar:this.onSpaceKey();break;case e.EVENT_KEYNAMES.enter:this.onEnterKey();break;case e.EVENT_KEYNAMES.home:this.onHomeKeyPress(t),t.stopPropagation(),t.preventDefault();break;case e.EVENT_KEYNAMES.end:this.onEndKeyPress(t),t.stopPropagation(),t.preventDefault();break;default:this.onKeyPress(t);break}this.$emit(`keydown`,t)}}},beginningOfListMethod(){return this.onBeginningOfList||this.jumpToEnd},endOfListMethod(){return this.onEndOfList||this.jumpToBeginning},activeItemEl(){return this.getListElement().querySelector(`#`+this.highlightId)},isArrowKeyNav(){return this.navigationType===this.LIST_ITEM_NAVIGATION_TYPES.ARROW_KEYS},listClasses(){return[`d-dropdown-list`,s.DROPDOWN_PADDING_CLASSES[this.padding],this.listClass,{"d-context-menu-list":this.openOnContext}]},shouldOpenWithArrowKeys(){return!this.openOnContext}},methods:{onMouseHighlight(e){let t=e.target.closest(`li`);t&&t.role&&this.highlightId!==t.id&&(this.setHighlightId(t.id),t.focus())},getListElement(){return this.$refs.listWrapper},clearHighlightIndex(){this.setHighlightIndex(-1)},afterHighlight(){this.highlightIndex!==this._itemsLength()-1&&this.$emit(`highlight`,this.highlightIndex)},updateInitialHighlightIndex(e){this.isOpen=e,e?(this.openedWithKeyboard&&this.isArrowKeyNav&&this.setHighlightIndex(0),this.$emit(`opened`,!0)):(this.clearHighlightIndex(),this.openedWithKeyboard=!1,this.$emit(`opened`,!1))},onSpaceKey(){this.open||(this.openedWithKeyboard=!0)},onEnterKey(){this.open||(this.openedWithKeyboard=!0)},onUpKeyPress(){if(!this.isOpen){this.openedWithKeyboard=!0;return}if(this.isArrowKeyNav)return this.onUpKey()},onDownKeyPress(){if(!this.isOpen){this.openedWithKeyboard=!0;return}if(this.isArrowKeyNav)return this.onDownKey()},onHomeKeyPress(){if(!(!this.isOpen||!this.isArrowKeyNav))return this.onHomeKey()},onEndKeyPress(){if(!(!this.isOpen||!this.isArrowKeyNav))return this.onEndKey()},onKeyPress(e){if(!(!this.isOpen||!this.isArrowKeyNav||!this.isValidLetter(e.key)))return e.stopPropagation(),e.preventDefault(),this.onNavigationKey(e.key)}}},u=[`id`];function d(e,t,n,r,i,a){let o=(0,c.resolveComponent)(`dt-popover`);return(0,c.openBlock)(),(0,c.createBlock)(o,(0,c.mergeProps)({ref:`popover`,"content-width":n.contentWidth,open:n.open,placement:n.placement,"initial-focus-element":i.openedWithKeyboard?`first`:`dialog`,"fallback-placements":n.fallbackPlacements,padding:`none`,role:`menu`,"append-to":n.appendTo,modal:n.modal,"max-height":n.maxHeight,"max-width":n.maxWidth,"open-with-arrow-keys":a.shouldOpenWithArrowKeys,"open-on-context":n.openOnContext},e.$attrs,{tether:n.tether,transition:n.transition},(0,c.toHandlers)(a.dropdownListeners)),{anchor:(0,c.withCtx)(({attrs:t})=>[(0,c.renderSlot)(e.$slots,`anchor`,(0,c.mergeProps)({ref:`anchor`},t))]),content:(0,c.withCtx)(({close:r})=>[(0,c.createElementVNode)(`ul`,{id:n.listId,ref:`listWrapper`,class:(0,c.normalizeClass)(a.listClasses),"data-qa":`dt-dropdown-list-wrapper`,onMouseleave:t[0]||(t[0]=(...e)=>a.clearHighlightIndex&&a.clearHighlightIndex(...e)),onMousemoveCapture:t[1]||(t[1]=(...e)=>a.onMouseHighlight&&a.onMouseHighlight(...e))},[(0,c.renderSlot)(e.$slots,`list`,{close:r})],42,u)]),footerContent:(0,c.withCtx)(({close:t})=>[(0,c.renderSlot)(e.$slots,`footer`,{close:t})]),_:3},16,[`content-width`,`open`,`placement`,`initial-focus-element`,`fallback-placements`,`append-to`,`modal`,`max-height`,`max-width`,`open-with-arrow-keys`,`open-on-context`,`tether`,`transition`])}var f=n.t(l,[[`render`,d]]);exports.default=f;
//# sourceMappingURL=dropdown.cjs.map