SelectButton

SelectButton is used to choose single or multiple items from a list using buttons.


import SelectButton from 'primevue/selectbutton';

SelectButton is used as a controlled component with modelValue property along with an options collection. Label and value of an option are defined with the optionLabel and optionValue properties respectively. Note that, when options are simple primitive values such as a string array, no optionLabel and optionValue would be necessary.


<SelectButton v-model="value" :options="options" aria-labelledby="basic" />

SelectButton allows selecting only one item by default and setting multiple option enables choosing more than one item. In multiple case, model property should be an array.


<SelectButton v-model="value" :options="options" optionLabel="name" multiple aria-labelledby="multiple" />

Label of an option is used as the display text of an item by default, for custom content support define an option template that gets the option instance as a parameter.


<SelectButton v-model="value" :options="options" optionLabel="value" dataKey="value" aria-labelledby="custom">
    <template #option="slotProps">
        <i :class="slotProps.option.icon"></i>
    </template>
</SelectButton>

Invalid state is displayed using the invalid prop to indicate a failed validation. You can use this style when integrating with form validation libraries.


<SelectButton v-model="value" :options="options" aria-labelledby="basic" invalid />

When disabled is present, the element cannot be edited and focused entirely. Certain options can also be disabled using the optionDisabled property.


<SelectButton v-model="value" :options="options" disabled />
<SelectButton v-model="value" :options="options2" optionDisabled="constant" optionLabel="name" />

Screen Reader

SelectButton component uses hidden native checkbox role for multiple selection and hidden radio role for single selection that is only visible to screen readers. Value to describe the component can be provided via aria-labelledby property.

Keyboard Support

Keyboard interaction is derived from the native browser handling of checkboxs in a group.

KeyFunction
tabMoves focus to the first selected option, if there is none then first option receives the focus.
right arrowup arrowMoves focus to the previous option.
left arrowdown arrowMoves focus to the next option.
spaceToggles the checked state of a button.