UNPKG

primevue

Version:

PrimeVue is an open source UI library for Vue featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBloc

2 lines (1 loc) 6.03 kB
import e from"primevue/ripple";import{DomHandler as t,ObjectUtils as n}from"primevue/utils";import i from"primevue/basecomponent";import o from"primevue/selectbutton/style";import{resolveDirective as r,openBlock as a,createElementBlock as l,mergeProps as s,Fragment as u,renderList as d,withDirectives as c,renderSlot as p,normalizeClass as f,createElementVNode as h,toDisplayString as b}from"vue";function m(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=g(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,o=function(){};return{s:o,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:o}}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 r,a=!0,l=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){l=!0,r=e},f:function(){try{a||null==n.return||n.return()}finally{if(l)throw r}}}}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 O(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)?O(e,t):void 0}}function v(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function x(e){if(Array.isArray(e))return O(e)}function O(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 S={name:"SelectButton",extends:{name:"BaseSelectButton",extends:i,props:{modelValue:null,options:Array,optionLabel:null,optionValue:null,optionDisabled:null,multiple:Boolean,unselectable:{type:Boolean,default:!0},allowEmpty:{type:Boolean,default:!0},disabled:Boolean,dataKey:null,ariaLabelledby:{type:String,default:null}},style:o,provide:function(){return{$parentInstance:this}}},emits:["update:modelValue","focus","blur","change"],data:function(){return{focusedIndex:0}},mounted:function(){this.defaultTabIndexes()},methods:{defaultTabIndexes:function(){for(var e=t.find(this.$refs.container,'[data-pc-section="button"]'),i=t.findSingle(this.$refs.container,'[data-p-highlight="true"]'),o=0;o<e.length;o++)(!0===t.getAttribute(e[o],"data-p-highlight")&&n.equals(e[o],i)||null===i&&0==o)&&(this.focusedIndex=o)},getOptionLabel:function(e){return this.optionLabel?n.resolveFieldData(e,this.optionLabel):e},getOptionValue:function(e){return this.optionValue?n.resolveFieldData(e,this.optionValue):e},getOptionRenderKey:function(e){return this.dataKey?n.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&&n.resolveFieldData(e,this.optionDisabled)},onOptionSelect:function(e,t,i){var o=this;if(!this.disabled&&!this.isOptionDisabled(t)){var r=this.isSelected(t);if(!r||this.unselectable&&this.allowEmpty){var a,l,s=this.getOptionValue(t);a=this.multiple?r?this.modelValue.filter((function(e){return!n.equals(e,s,o.equalityKey)})):this.modelValue?[].concat(x(l=this.modelValue)||v(l)||g(l)||y(),[s]):[s]:r?null:s,this.focusedIndex=i,this.$emit("update:modelValue",a),this.$emit("change",{event:e,value:a})}}},isSelected:function(e){var t=!1,i=this.getOptionValue(e);if(this.multiple){if(this.modelValue){var o,r=m(this.modelValue);try{for(r.s();!(o=r.n()).done;){if(n.equals(o.value,i,this.equalityKey)){t=!0;break}}}catch(e){r.e(e)}finally{r.f()}}}else t=n.equals(this.modelValue,i,this.equalityKey);return t},onKeydown:function(e,t,n){switch(e.code){case"Space":this.onOptionSelect(e,t,n),e.preventDefault();break;case"ArrowDown":case"ArrowRight":this.changeTabIndexes(e,"next"),e.preventDefault();break;case"ArrowUp":case"ArrowLeft":this.changeTabIndexes(e,"prev"),e.preventDefault()}},changeTabIndexes:function(e,t){for(var n,i,o=0;o<=this.$refs.container.children.length-1;o++)"0"===this.$refs.container.children[o].getAttribute("tabindex")&&(n={elem:this.$refs.container.children[o],index:o});this.focusedIndex=i="prev"===t?0===n.index?this.$refs.container.children.length-1:n.index-1:n.index===this.$refs.container.children.length-1?0:n.index+1,this.$refs.container.children[i].focus()},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)}},computed:{equalityKey:function(){return this.optionValue?null:this.dataKey}},directives:{ripple:e}},w=["aria-labelledby"],I=["tabindex","aria-label","role","aria-checked","aria-disabled","onClick","onKeydown","onBlur","data-p-highlight","data-p-disabled"];S.render=function(e,t,n,i,o,m){var y=r("ripple");return a(),l("div",s({ref:"container",class:e.cx("root"),role:"group","aria-labelledby":e.ariaLabelledby},e.ptm("root"),{"data-pc-name":"selectbutton"}),[(a(!0),l(u,null,d(e.options,(function(n,i){return c((a(),l("div",s({key:m.getOptionRenderKey(n),tabindex:i===o.focusedIndex?"0":"-1","aria-label":m.getOptionLabel(n),role:e.multiple?"checkbox":"radio","aria-checked":m.isSelected(n),"aria-disabled":e.optionDisabled,class:e.cx("button",{option:n}),onClick:function(e){return m.onOptionSelect(e,n,i)},onKeydown:function(e){return m.onKeydown(e,n,i)},onFocus:t[0]||(t[0]=function(e){return m.onFocus(e)}),onBlur:function(e){return m.onBlur(e,n)}},m.getPTOptions(n,"button"),{"data-p-highlight":m.isSelected(n),"data-p-disabled":m.isOptionDisabled(n)}),[p(e.$slots,"option",{option:n,index:i,class:f(e.cx("label"))},(function(){return[h("span",s({class:e.cx("label")},m.getPTOptions(n,"label")),b(m.getOptionLabel(n)),17)]}))],16,I)),[[y]])})),128))],16,w)};export{S as default};