SelectButton

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


import { SelectButton } from 'primereact/selectbutton';
         

SelectButton is used as a controlled component with value and onChange properties 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.

Off
On

<SelectButton value={value} onChange={(e) => setValue(e.value)} options={options} />
         

SelectButton allows selecting only one item by default and enabling multiple allows choosing more. In multiple case, model property should be an array instead of a single value.

Option 1
Option 2
Option 3

<SelectButton value={value} onChange={(e) => setValue(e.value)} optionLabel="name" options={items} multiple />
         

Options support templating using the itemTemplate property that references a function to render the content. Notice the usage of optionLabel, although not rendered visually, it is still required to be used as the list key.


<SelectButton value={value} onChange={(e) => setValue(e.value)} itemTemplate={justifyTemplate} optionLabel="value" options={justifyOptions} />
         

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

Off
On

<SelectButton invalid value={value} onChange={(e) => setValue(e.value)} options={options} />
         

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

Off
On
Option 1
Option 2

<SelectButton disabled options={options1} />
<SelectButton value={value} onChange={(e) => setValue(e.value)} options={options2} optionLabel="name" optionDisabled="constant" />
         

Screen Reader

The container element that wraps the buttons has a group role whereas each button element uses button role and aria-pressed is updated depending on selection state. Value to describe an option is automatically set using the aria-label property that refers to the label of an option so it is still suggested to define a label even the option display consists of presentational content like icons only.

Keyboard Support

KeyFunction
tabMoves focus to the buttons.
spaceToggles the checked state of a button.