accessibleprimevue
Version:
Note: This is the forked version of the Primefaces/PrimeVue repository. Since V3 has reached its EOL this is use to fix identified accessibility bugs in the v3 version of primevue. PrimeVue is an open source UI library for Vue featuring a rich set of 80+
2 lines (1 loc) • 17.5 kB
JavaScript
"use strict";var e=require("primevue/button"),t=require("primevue/icons/angledoubledown"),n=require("primevue/icons/angledoubleup"),i=require("primevue/icons/angledown"),o=require("primevue/icons/angleup"),r=require("primevue/ripple"),s=require("primevue/utils"),l=require("primevue/basecomponent"),c=require("primevue/orderlist/style"),d=require("vue");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=a(e),p=a(t),h=a(n),m=a(i),f=a(o),v=a(r);function b(e){return O(e)||I(e)||g(e)||y()}function y(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function g(e,t){if(e){if("string"==typeof e)return x(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?x(e,t):void 0}}function I(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function O(e){if(Array.isArray(e))return x(e)}function x(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i}var w={name:"OrderList",extends:{name:"BaseOrderList",extends:a(l).default,props:{modelValue:{type:Array,default:null},selection:{type:Array,default:null},dataKey:{type:String,default:null},listStyle:{type:null,default:null},metaKeySelection:{type:Boolean,default:!1},autoOptionFocus:{type:Boolean,default:!0},focusOnHover:{type:Boolean,default:!0},responsive:{type:Boolean,default:!0},breakpoint:{type:String,default:"960px"},stripedRows:{type:Boolean,default:!1},tabindex:{type:Number,default:0},listProps:{type:null,default:null},moveUpButtonProps:{type:null,default:null},moveTopButtonProps:{type:null,default:null},moveDownButtonProps:{type:null,default:null},moveBottomButtonProps:{type:null,default:null},ariaLabelledby:{type:String,default:null},ariaLabel:{type:String,default:null}},style:a(c).default,provide:function(){return{$parentInstance:this}}},inheritAttrs:!1,emits:["update:modelValue","reorder","update:selection","selection-change","focus","blur"],itemTouched:!1,reorderDirection:null,styleElement:null,list:null,data:function(){return{id:this.$attrs.id,d_selection:this.selection,focused:!1,focusedOptionIndex:-1}},watch:{"$attrs.id":function(e){this.id=e||s.UniqueComponentId()}},beforeUnmount:function(){this.destroyStyle()},updated:function(){this.reorderDirection&&(this.updateListScroll(),this.reorderDirection=null)},mounted:function(){this.id=this.id||s.UniqueComponentId(),this.responsive&&this.createStyle()},methods:{getItemKey:function(e,t){return this.dataKey?s.ObjectUtils.resolveFieldData(e,this.dataKey):t},getPTOptions:function(e,t,n){return this.ptm(t,{context:{active:this.isSelected(e),focused:"".concat(this.id,"_").concat(n)===this.focusedOptionId}})},isSelected:function(e){return-1!=s.ObjectUtils.findIndexInList(e,this.d_selection)},onListFocus:function(e){this.focused=!0,this.findCurrentFocusedIndex(),this.scrollInView(this.focusedOptionIndex),this.$emit("focus",e)},onListBlur:function(e){this.focused=!1,this.focusedOptionIndex=-1,this.$emit("blur",e)},onListKeyDown:function(e){switch(e.code){case"ArrowDown":this.onArrowDownKey(e);break;case"ArrowUp":this.onArrowUpKey(e);break;case"Home":this.onHomeKey(e);break;case"End":this.onEndKey(e);break;case"Enter":case"NumpadEnter":this.onEnterKey(e);break;case"Space":this.onSpaceKey(e);break;case"KeyA":e.ctrlKey&&(this.d_selection=b(this.modelValue),this.$emit("update:selection",this.d_selection),e.preventDefault())}},onOptionMouseDown:function(e,t){this.changeFocusedOptionIndex(t)},onOptionMouseMove:function(e){this.focusOnHover&&this.focused&&this.changeFocusedOptionIndex(e)},onArrowDownKey:function(e){var t=-1!==this.focusedOptionIndex?this.findNextOptionIndex():this.findFirstSelectedOptionIndex();this.changeFocusedOptionIndex(t),e.shiftKey&&this.onEnterKey(e),e.preventDefault()},onArrowUpKey:function(e){var t=-1!==this.focusedOptionIndex?this.findPrevOptionIndex():this.findLastSelectedOptionIndex();this.changeFocusedOptionIndex(t),e.shiftKey&&this.onEnterKey(e),e.preventDefault()},onHomeKey:function(e){if(e.ctrlKey&&e.shiftKey){var t=this.findMatchedOptionIndex();this.d_selection=b(this.modelValue).slice(0,t+1),this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:e,value:this.d_selection})}else this.changeFocusedOptionIndex(0);e.preventDefault()},onEndKey:function(e){if(e.ctrlKey&&e.shiftKey){var t=this.findMatchedOptionIndex();this.d_selection=b(this.modelValue).slice(t,items.length),this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:e,value:this.d_selection})}else this.changeFocusedOptionIndex(this.findAllItems().length-1);e.preventDefault()},onEnterKey:function(e){var t=this.findMatchedOptionIndex();this.onItemClick(e,this.modelValue[t],t),e.preventDefault()},onSpaceKey:function(e){if(e.preventDefault(),e.shiftKey&&this.d_selection&&this.d_selection.length>0){var t=s.ObjectUtils.findIndexInList(this.d_selection[0],b(this.modelValue)),n=this.findMatchedOptionIndex();this.d_selection=b(this.modelValue).slice(Math.min(t,n),Math.max(t,n)+1),this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:e,value:this.d_selection})}else this.onEnterKey(e)},findAllItems:function(){return s.DomHandler.find(this.list,'[data-pc-section="item"]')},findFocusedItem:function(){return s.DomHandler.findSingle(this.list,'[data-pc-section="item"][id='.concat(this.focusedOptionIndex,"]"))},findCurrentFocusedIndex:function(){-1===this.focusedOptionIndex&&(this.focusedOptionIndex=this.findFirstSelectedOptionIndex(),this.autoOptionFocus&&-1===this.focusedOptionIndex&&(this.focusedOptionIndex=this.findFirstFocusedOptionIndex()))},findFirstFocusedOptionIndex:function(){var e=s.DomHandler.findSingle(this.list,'[data-pc-section="item"]');return s.DomHandler.getAttribute(e,"id")},findFirstSelectedOptionIndex:function(){if(this.hasSelectedOption){var e=s.DomHandler.findSingle(this.list,'[data-p-highlight="true"]');return s.DomHandler.getAttribute(e,"id")}return-1},findLastSelectedOptionIndex:function(){if(this.hasSelectedOption){var e=s.DomHandler.find(this.list,'[data-p-highlight="true"]');return s.ObjectUtils.findIndexInList(e[e.length-1],this.list.children)}return-1},findMatchedOptionIndex:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.focusedOptionIndex;return b(this.findAllItems()).findIndex((function(t){return t.id===e}))},findNextOptionIndex:function(){var e=this.findMatchedOptionIndex();return e>-1?e+1:0},findPrevOptionIndex:function(){var e=this.findMatchedOptionIndex();return e>-1?e-1:0},changeFocusedOptionIndex:function(e){var t=this.findAllItems(),n=e>=t.length?t.length-1:e<0?0:e;this.focusedOptionIndex=t[n]?t[n].getAttribute("id"):-1,this.scrollInView(this.focusedOptionIndex)},scrollInView:function(e){var t=s.DomHandler.findSingle(this.list,'[data-pc-section="item"][id="'.concat(e,'"]'));t&&t.scrollIntoView&&t.scrollIntoView({block:"nearest",inline:"start",behavior:"smooth"})},moveUp:function(e){if(this.d_selection){for(var t=b(this.modelValue),n=0;n<this.d_selection.length;n++){var i=s.ObjectUtils.findIndexInList(this.d_selection[n],t);if(0===i)break;var o=t[i-1];t[i-1]=t[i],t[i]=o}this.reorderDirection="up",this.$emit("update:modelValue",t),this.$emit("reorder",{originalEvent:e,value:t,direction:this.reorderDirection})}},moveTop:function(e){if(this.d_selection){for(var t=b(this.modelValue),n=0;n<this.d_selection.length;n++){var i=s.ObjectUtils.findIndexInList(this.d_selection[n],t);if(0===i)break;var o=t.splice(i,1)[0];t.unshift(o)}this.reorderDirection="top",this.$emit("update:modelValue",t),this.$emit("reorder",{originalEvent:e,value:t,direction:this.reorderDirection})}},moveDown:function(e){if(this.d_selection){for(var t=b(this.modelValue),n=this.d_selection.length-1;n>=0;n--){var i=s.ObjectUtils.findIndexInList(this.d_selection[n],t);if(i===t.length-1)break;var o=t[i+1];t[i+1]=t[i],t[i]=o}this.reorderDirection="down",this.$emit("update:modelValue",t),this.$emit("reorder",{originalEvent:e,value:t,direction:this.reorderDirection})}},moveBottom:function(e){if(this.d_selection){for(var t=b(this.modelValue),n=this.d_selection.length-1;n>=0;n--){var i=s.ObjectUtils.findIndexInList(this.d_selection[n],t);if(i===t.length-1)break;var o=t.splice(i,1)[0];t.push(o)}this.reorderDirection="bottom",this.$emit("update:modelValue",t),this.$emit("reorder",{originalEvent:e,value:t,direction:this.reorderDirection})}},onItemClick:function(e,t,n){this.itemTouched=!1;var i=s.ObjectUtils.findIndexInList(t,this.d_selection),o=-1!=i,r=!this.itemTouched&&this.metaKeySelection,l=this.findAllItems()[n].getAttribute("id");if(this.focusedOptionIndex=l,r){var c=e.metaKey||e.ctrlKey;o&&c?this.d_selection=this.d_selection.filter((function(e,t){return t!==i})):(this.d_selection=c&&this.d_selection?b(this.d_selection):[],s.ObjectUtils.insertIntoOrderedArray(t,n,this.d_selection,this.modelValue))}else o?this.d_selection=this.d_selection.filter((function(e,t){return t!==i})):(this.d_selection=this.d_selection?b(this.d_selection):[],s.ObjectUtils.insertIntoOrderedArray(t,n,this.d_selection,this.modelValue));this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:e,value:this.d_selection})},onItemTouchEnd:function(){this.itemTouched=!0},updateListScroll:function(){var e=s.DomHandler.find(this.list,'[data-pc-section="item"][data-p-highlight="true"]');if(e&&e.length)switch(this.reorderDirection){case"up":s.DomHandler.scrollInView(this.list,e[0]);break;case"top":this.list.scrollTop=0;break;case"down":s.DomHandler.scrollInView(this.list,e[e.length-1]);break;case"bottom":this.list.scrollTop=this.list.scrollHeight}},createStyle:function(){if(!this.styleElement&&!this.isUnstyled){var e;this.$el.setAttribute(this.attributeSelector,""),this.styleElement=document.createElement("style"),this.styleElement.type="text/css",s.DomHandler.setAttribute(this.styleElement,"nonce",null===(e=this.$primevue)||void 0===e||null===(e=e.config)||void 0===e||null===(e=e.csp)||void 0===e?void 0:e.nonce),document.head.appendChild(this.styleElement);var t="\n@media screen and (max-width: ".concat(this.breakpoint,") {\n .p-orderlist[").concat(this.attributeSelector,"] {\n flex-direction: column;\n }\n\n .p-orderlist[").concat(this.attributeSelector,"] .p-orderlist-controls {\n padding: var(--content-padding);\n flex-direction: row;\n }\n\n .p-orderlist[").concat(this.attributeSelector,"] .p-orderlist-controls .p-button {\n margin-right: var(--inline-spacing);\n margin-bottom: 0;\n }\n\n .p-orderlist[").concat(this.attributeSelector,"] .p-orderlist-controls .p-button:last-child {\n margin-right: 0;\n }\n}\n");this.styleElement.innerHTML=t}},destroyStyle:function(){this.styleElement&&(document.head.removeChild(this.styleElement),this.styleElement=null)},moveDisabled:function(){if(!this.d_selection||!this.d_selection.length)return!0},listRef:function(e){this.list=e?e.$el:void 0}},computed:{attributeSelector:function(){return s.UniqueComponentId()},focusedOptionId:function(){return-1!==this.focusedOptionIndex?this.focusedOptionIndex:null},moveUpAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.moveUp:void 0},moveTopAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.moveTop:void 0},moveDownAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.moveDown:void 0},moveBottomAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.moveBottom:void 0},hasSelectedOption:function(){return s.ObjectUtils.isNotEmpty(this.d_selection)}},components:{OLButton:u.default,AngleUpIcon:f.default,AngleDownIcon:m.default,AngleDoubleUpIcon:h.default,AngleDoubleDownIcon:p.default},directives:{ripple:v.default}};function D(e){return D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},D(e)}function S(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function _(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?S(Object(n),!0).forEach((function(t){A(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):S(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function A(e,t,n){var i;return(t="symbol"==D(i=B(t,"string"))?i:String(i))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function B(e,t){if("object"!=D(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=D(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var E=["id","onClick","onMousedown","onMousemove","aria-selected","data-p-highlight","data-p-focused"];w.render=function(e,t,n,i,o,r){var s=d.resolveComponent("AngleUpIcon"),l=d.resolveComponent("OLButton"),c=d.resolveComponent("AngleDoubleUpIcon"),a=d.resolveComponent("AngleDownIcon"),u=d.resolveComponent("AngleDoubleDownIcon"),p=d.resolveDirective("ripple");return d.openBlock(),d.createElementBlock("div",d.mergeProps({class:e.cx("root")},e.ptmi("root")),[d.createElementVNode("div",d.mergeProps({class:e.cx("controls")},e.ptm("controls")),[d.renderSlot(e.$slots,"controlsstart"),d.createVNode(l,d.mergeProps({type:"button",onClick:r.moveUp,"aria-label":r.moveUpAriaLabel,disabled:r.moveDisabled()},e.moveUpButtonProps,{pt:e.ptm("moveUpButton"),unstyled:e.unstyled}),{icon:d.withCtx((function(){return[d.renderSlot(e.$slots,"moveupicon",{},(function(){return[d.createVNode(s,d.mergeProps(e.ptm("moveUpButton").icon,{"data-pc-section":"moveupicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),d.createVNode(l,d.mergeProps({type:"button",onClick:r.moveTop,"aria-label":r.moveTopAriaLabel,disabled:r.moveDisabled()},e.moveTopButtonProps,{pt:e.ptm("moveTopButton"),unstyled:e.unstyled}),{icon:d.withCtx((function(){return[d.renderSlot(e.$slots,"movetopicon",{},(function(){return[d.createVNode(c,d.mergeProps(e.ptm("moveTopButton").icon,{"data-pc-section":"movetopicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),d.createVNode(l,d.mergeProps({type:"button",onClick:r.moveDown,"aria-label":r.moveDownAriaLabel,disabled:r.moveDisabled()},e.moveDownButtonProps,{pt:e.ptm("moveDownButton"),unstyled:e.unstyled}),{icon:d.withCtx((function(){return[d.renderSlot(e.$slots,"movedownicon",{},(function(){return[d.createVNode(a,d.mergeProps(e.ptm("moveDownButton").icon,{"data-pc-section":"movedownicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),d.createVNode(l,d.mergeProps({type:"button",onClick:r.moveBottom,"aria-label":r.moveBottomAriaLabel,disabled:r.moveDisabled()},e.moveBottomButtonProps,{pt:e.ptm("moveBottomButton"),unstyled:e.unstyled}),{icon:d.withCtx((function(){return[d.renderSlot(e.$slots,"movebottomicon",{},(function(){return[d.createVNode(u,d.mergeProps(e.ptm("moveBottomButton").icon,{"data-pc-section":"movebottomicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),d.renderSlot(e.$slots,"controlsend")],16),d.createElementVNode("div",d.mergeProps({class:e.cx("container")},e.ptm("container")),[e.$slots.header?(d.openBlock(),d.createElementBlock("div",d.mergeProps({key:0,class:e.cx("header")},e.ptm("header")),[d.renderSlot(e.$slots,"header")],16)):d.createCommentVNode("",!0),d.createVNode(d.TransitionGroup,d.mergeProps({ref:r.listRef,id:o.id+"_list",name:"p-orderlist-flip",tag:"ul",class:e.cx("list"),style:e.listStyle,role:"listbox","aria-multiselectable":"true",tabindex:e.tabindex,"aria-activedescendant":o.focused?r.focusedOptionId:void 0,"aria-label":e.ariaLabel,"aria-labelledby":e.ariaLabelledby,onFocus:r.onListFocus,onBlur:r.onListBlur,onKeydown:r.onListKeyDown},_(_(_({},e.listProps),e.ptm("list")),e.ptm("transition"))),{default:d.withCtx((function(){return[(d.openBlock(!0),d.createElementBlock(d.Fragment,null,d.renderList(e.modelValue,(function(n,i){return d.withDirectives((d.openBlock(),d.createElementBlock("li",d.mergeProps({key:r.getItemKey(n,i),id:o.id+"_"+i,role:"option",class:e.cx("item",{item:n,id:"".concat(o.id,"_").concat(i)}),onClick:function(e){return r.onItemClick(e,n,i)},onTouchend:t[0]||(t[0]=function(){return r.onItemTouchEnd&&r.onItemTouchEnd.apply(r,arguments)}),onMousedown:function(e){return r.onOptionMouseDown(e,i)},onMousemove:function(e){return r.onOptionMouseMove(i)},"aria-selected":r.isSelected(n)},r.getPTOptions(n,"item",i),{"data-p-highlight":r.isSelected(n),"data-p-focused":"".concat(o.id,"_").concat(i)===r.focusedOptionId}),[d.renderSlot(e.$slots,"item",{item:n,index:i})],16,E)),[[p]])})),128))]})),_:3},16,["id","class","style","tabindex","aria-activedescendant","aria-label","aria-labelledby","onFocus","onBlur","onKeydown"])],16)],16)},module.exports=w;