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) • 6.81 kB
JavaScript
this.primevue=this.primevue||{},this.primevue.selectbutton=function(e,t,n,i,l){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=o(e);function a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=u(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,l=function(){};return{s:l,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:l}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,r=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return r=e.done,e},e:function(e){a=!0,o=e},f:function(){try{r||null==n.return||n.return()}finally{if(a)throw o}}}}function s(){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 u(e,t){if(e){if("string"==typeof e)return f(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)?f(e,t):void 0}}function d(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function c(e){if(Array.isArray(e))return f(e)}function f(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 p={name:"SelectButton",extends:{name:"BaseSelectButton",extends:o(n).default,props:{modelValue:null,options:Array,optionLabel:null,optionValue:null,optionDisabled:null,multiple:Boolean,unselectable:{type:Boolean,default:!0},allowEmpty:{type:Boolean,default:!0},invalid:{type:Boolean,default:!1},disabled:Boolean,dataKey:null,ariaLabelledby:{type:String,default:null}},style:o(i).default,provide:function(){return{$parentInstance:this}}},inheritAttrs:!1,emits:["update:modelValue","focus","blur","change"],data:function(){return{focusedIndex:0}},mounted:function(){this.defaultTabIndexes()},methods:{defaultTabIndexes:function(){for(var e=t.DomHandler.find(this.$refs.container,'[data-pc-section="button"]'),n=t.DomHandler.findSingle(this.$refs.container,'[data-p-highlight="true"]'),i=0;i<e.length;i++)(!0===t.DomHandler.getAttribute(e[i],"data-p-highlight")&&t.ObjectUtils.equals(e[i],n)||null===n&&0==i)&&(this.focusedIndex=i)},getOptionLabel:function(e){return this.optionLabel?t.ObjectUtils.resolveFieldData(e,this.optionLabel):e},getOptionValue:function(e){return this.optionValue?t.ObjectUtils.resolveFieldData(e,this.optionValue):e},getOptionRenderKey:function(e){return this.dataKey?t.ObjectUtils.resolveFieldData(e,this.dataKey):this.getOptionLabel(e)},getPTOptions:function(e,t){return this.ptm(t,{context:{active:this.isSelected(e),disabled:this.isOptionDisabled(e),option:e}})},isOptionDisabled:function(e){return!!this.optionDisabled&&t.ObjectUtils.resolveFieldData(e,this.optionDisabled)},onOptionSelect:function(e,n,i){var l=this;if(!this.disabled&&!this.isOptionDisabled(n)){var o=this.isSelected(n);if(!o||this.unselectable&&this.allowEmpty){var r,a,f=this.getOptionValue(n);r=this.multiple?o?this.modelValue.filter((function(e){return!t.ObjectUtils.equals(e,f,l.equalityKey)})):this.modelValue?[].concat(c(a=this.modelValue)||d(a)||u(a)||s(),[f]):[f]:o?null:f,this.focusedIndex=i,this.$emit("update:modelValue",r),this.$emit("change",{event:e,value:r})}}},isSelected:function(e){var n=!1,i=this.getOptionValue(e);if(this.multiple){if(this.modelValue){var l,o=a(this.modelValue);try{for(o.s();!(l=o.n()).done;){if(t.ObjectUtils.equals(l.value,i,this.equalityKey)){n=!0;break}}}catch(e){o.e(e)}finally{o.f()}}}else n=t.ObjectUtils.equals(this.modelValue,i,this.equalityKey);return n},onKeydown:function(e,t,n){switch(e.code){case"Space":this.onOptionSelect(e,t,n),e.preventDefault();break;case"ArrowDown":case"ArrowRight":this.onArrowRightKey(e.target),e.preventDefault();break;case"ArrowUp":case"ArrowLeft":this.onArrowLeftKey(e.target),e.preventDefault()}},onArrowRightKey:function(e){var n=this.findNextElement(e);n&&(this.focusedIndex=t.ObjectUtils.findIndexInList(n,this.findAllElements()),t.DomHandler.focus(n))},onArrowLeftKey:function(e){var n=this.findPrevElement(e);n&&(this.focusedIndex=t.ObjectUtils.findIndexInList(n,this.findAllElements()),t.DomHandler.focus(n))},findAllElements:function(){return t.DomHandler.find(this.$refs.container,'[data-pc-section="button"]')},findNextElement:function(e){return e.nextElementSibling?t.DomHandler.getAttribute(e.nextElementSibling,"data-p-disabled")?this.findNextElement(e.nextElementSibling):e.nextElementSibling:null},findPrevElement:function(e){return e.previousElementSibling?t.DomHandler.getAttribute(e.previousElementSibling,"data-p-disabled")?this.findPrevElement(e.previousElementSibling):e.previousElementSibling:null},onFocus:function(e){this.$emit("focus",e)},onBlur:function(e,t){e.target&&e.relatedTarget&&e.target.parentElement!==e.relatedTarget.parentElement&&this.defaultTabIndexes(),this.$emit("blur",e,t)},findTabindex:function(e,t){return this.disabled||this.isOptionDisabled(e)||t!==this.focusedIndex?"-1":"0"}},computed:{equalityKey:function(){return this.optionValue?null:this.dataKey}},directives:{ripple:r.default}},b=["aria-labelledby"],h=["tabindex","aria-label","role","aria-checked","aria-disabled","onClick","onKeydown","onBlur","data-p-highlight","data-p-disabled"];return p.render=function(e,t,n,i,o,r){var a=l.resolveDirective("ripple");return l.openBlock(),l.createElementBlock("div",l.mergeProps({ref:"container",class:e.cx("root"),role:"group","aria-labelledby":e.ariaLabelledby},e.ptmi("root")),[(l.openBlock(!0),l.createElementBlock(l.Fragment,null,l.renderList(e.options,(function(n,i){return l.withDirectives((l.openBlock(),l.createElementBlock("div",l.mergeProps({key:r.getOptionRenderKey(n),tabindex:r.findTabindex(n,i),"aria-label":r.getOptionLabel(n),role:e.multiple?"checkbox":"radio","aria-checked":r.isSelected(n),"aria-disabled":r.isOptionDisabled(n),class:e.cx("button",{option:n}),onClick:function(e){return r.onOptionSelect(e,n,i)},onKeydown:function(e){return r.onKeydown(e,n,i)},onFocus:t[0]||(t[0]=function(e){return r.onFocus(e)}),onBlur:function(e){return r.onBlur(e,n)}},r.getPTOptions(n,"button"),{"data-p-highlight":r.isSelected(n),"data-p-disabled":r.isOptionDisabled(n)}),[l.renderSlot(e.$slots,"option",{option:n,index:i,class:l.normalizeClass(e.cx("label"))},(function(){return[l.createElementVNode("span",l.mergeProps({class:e.cx("label")},r.getPTOptions(n,"label")),l.toDisplayString(r.getOptionLabel(n)),17)]}))],16,h)),[[a]])})),128))],16,b)},p}(primevue.ripple,primevue.utils,primevue.basecomponent,primevue.selectbutton.style,Vue);