UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue) [![Discord Chat](https://img.shields.io/discord/55794023

2 lines (1 loc) 6.2 kB
import e from"primevue/ripple";import{DomHandler as t,ObjectUtils as n}from"primevue/utils";import i from"primevue/basecomponent";import{resolveDirective as o,openBlock as r,createElementBlock as a,mergeProps as l,Fragment as s,renderList as u,withDirectives as d,renderSlot as c,normalizeClass as p,createElementVNode as f,toDisplayString as h}from"vue";function b(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=y(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 m(){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 y(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 g(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function v(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 O={name:"SelectButton",extends:{name:"BaseSelectButton",extends:i,props:{modelValue:null,options:Array,optionLabel:null,optionValue:null,optionDisabled:null,multiple:Boolean,unselectable:{type:Boolean,default:!1},disabled:Boolean,dataKey:null,"aria-labelledby":{type:String,default:null}},css:{classes:{root:function(e){return["p-selectbutton p-buttonset p-component",{"p-disabled":e.props.disabled}]},button:function(e){var t=e.instance,n=e.option;return["p-button p-component",{"p-highlight":t.isSelected(n),"p-disabled":t.isOptionDisabled(n)}]},label:"p-button-label"}},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)}})},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){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(v(l=this.modelValue)||g(l)||y(l)||m(),[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=b(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}},S=["aria-labelledby"],w=["tabindex","aria-label","role","aria-checked","aria-disabled","onClick","onKeydown","onBlur","data-p-highlight","data-p-disabled"];O.render=function(e,t,n,i,b,m){var y=o("ripple");return r(),a("div",l({ref:"container",class:e.cx("root"),role:"group","aria-labelledby":e.ariaLabelledby},e.ptm("root"),{"data-pc-name":"selectbutton"}),[(r(!0),a(s,null,u(e.options,(function(n,i){return d((r(),a("div",l({key:m.getOptionRenderKey(n),tabindex:i===b.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)}),[c(e.$slots,"option",{option:n,index:i,class:p(e.cx("label"))},(function(){return[f("span",l({class:e.cx("label")},m.getPTOptions(n,"label")),h(m.getOptionLabel(n)),17)]}))],16,w)),[[y]])})),128))],16,S)};export{O as default};