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" allowEmpty :invalid="value === null"  />

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 ToggleButton internally and has group role. 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 next the focusable element in the page tab sequence.
shift + tabMoves focus to the previous the focusable element in the page tab sequence.
spaceToggles the checked state of a button.