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) 2.9 kB
"use strict";var e=require("primevue/utils"),t=require("primevue/ripple"),l=require("vue");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o={name:"SelectButton",emits:["update:modelValue","focus","blur","change"],props:{modelValue:null,options:Array,optionLabel:null,optionValue:null,optionDisabled:null,multiple:Boolean,disabled:Boolean,dataKey:null,ariaLabelledBy:null},methods:{getOptionLabel(t){return this.optionLabel?e.ObjectUtils.resolveFieldData(t,this.optionLabel):t},getOptionValue(t){return this.optionValue?e.ObjectUtils.resolveFieldData(t,this.optionValue):t},getOptionRenderKey(t){return this.dataKey?e.ObjectUtils.resolveFieldData(t,this.dataKey):this.getOptionLabel(t)},isOptionDisabled(t){return!!this.optionDisabled&&e.ObjectUtils.resolveFieldData(t,this.optionDisabled)},onOptionSelect(t,l){if(this.disabled||this.isOptionDisabled(l))return;let i,o=this.isSelected(l),s=this.getOptionValue(l);i=this.multiple?o?this.modelValue.filter((t=>!e.ObjectUtils.equals(t,s,this.equalityKey))):this.modelValue?[...this.modelValue,s]:[s]:s,this.$emit("update:modelValue",i),this.$emit("change",{event:t,value:i})},isSelected(t){let l=!1,i=this.getOptionValue(t);if(this.multiple){if(this.modelValue)for(let t of this.modelValue)if(e.ObjectUtils.equals(t,i,this.equalityKey)){l=!0;break}}else l=e.ObjectUtils.equals(this.modelValue,i,this.equalityKey);return l},onFocus(e){this.$emit("focus",e)},onBlur(e){this.$emit("blur",e)},getButtonClass(e){return["p-button p-component",{"p-highlight":this.isSelected(e),"p-disabled":this.isOptionDisabled(e)}]}},computed:{containerClass(){return["p-selectbutton p-buttonset p-component",{"p-disabled":this.disabled}]},equalityKey(){return this.optionValue?null:this.dataKey}},directives:{ripple:i(t).default}};const s=["aria-label","aria-pressed","onClick","onKeydown","tabindex","aria-labelledby"],a={class:"p-button-label"};o.render=function(e,t,i,o,n,r){const u=l.resolveDirective("ripple");return l.openBlock(),l.createElementBlock("div",{class:l.normalizeClass(r.containerClass),role:"group"},[(l.openBlock(!0),l.createElementBlock(l.Fragment,null,l.renderList(i.options,((o,n)=>l.withDirectives((l.openBlock(),l.createElementBlock("div",{key:r.getOptionRenderKey(o),"aria-label":r.getOptionLabel(o),role:"button","aria-pressed":r.isSelected(o),onClick:e=>r.onOptionSelect(e,o,n),onKeydown:[l.withKeys(l.withModifiers((e=>r.onOptionSelect(e,o,n)),["prevent"]),["enter"]),l.withKeys(l.withModifiers((e=>r.onOptionSelect(e,o)),["prevent"]),["space"])],tabindex:r.isOptionDisabled(o)?null:"0",onFocus:t[0]||(t[0]=e=>r.onFocus(e)),onBlur:t[1]||(t[1]=e=>r.onBlur(e)),"aria-labelledby":i.ariaLabelledBy,class:l.normalizeClass(r.getButtonClass(o))},[l.renderSlot(e.$slots,"option",{option:o,index:n},(()=>[l.createElementVNode("span",a,l.toDisplayString(r.getOptionLabel(o)),1)]))],42,s)),[[u]]))),128))],2)},module.exports=o;