SelectButton

Slider is a component to provide input with a drag handle.


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. Default property name for the optionLabel is label and value for the optionValue. If optionValue is omitted and the object has no value property, the object itself becomes the value of an option. 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 style is added using the p-invalid class to indicate a failed validation.



<SelectButton v-model="value" :options="options" aria-labelledby="basic" class="p-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" />

Compatibility with popular Vue form libraries.

VeeValidate is a popular library for handling forms in Vue.

 


<div class="card flex justify-content-center">
    <form @submit="onSubmit" class="flex flex-column align-items-center gap-2">
        <label for="item" :class="['flex justify-content-center', { 'p-error': errorMessage }]"> Engine State </label>
        <SelectButton id="item" v-model="value" :class="{ 'p-invalid': errorMessage }" aria-describedby="text-error" :options="options" />
        <small id="text-error" class="p-error">{{ errorMessage || '&nbsp;' }}</small>
        <Button type="submit" label="Submit" />
    </form>
    <Toast />
</div>

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.