lara-light-indigo

SelectButton

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

Single Selection
Off
On
Multiple Selection
Option 1
Option 2
Option 3
Custom Content
Import via Module

import { SelectButton } from 'primereact/selectbutton';
 
Import via CDN

<script src="https://unpkg.com/primereact/core/core.min.js"></script>
<script src="https://unpkg.com/primereact/selectbutton/selectbutton.min.js"></script>
 
Getting Started

Dropdown is used as a controlled component with value and onChange properties along with the options collection. There are two alternatives of how to define the options property; One way is providing a collection of SelectItem instances having label-value pairs whereas other way is providing an array of arbitrary objects along with the optionLabel and optionValue properties to specify the label/value field pair. In addition, options can be simple primitive values such as a string array, in this case no optionLabel or optionValue is necessary.

Options as SelectItems


const citySelectItems = [
    {label: 'New York', value: 'NY'},
    {label: 'Rome', value: 'RM'},
    {label: 'London', value: 'LDN'},
    {label: 'Istanbul', value: 'IST'},
    {label: 'Paris', value: 'PRS'}
];
 

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

Options as any type


const cities = [
    {name: 'New York', code: 'NY'},
    {name: 'Rome', code: 'RM'},
    {name: 'London', code: 'LDN'},
    {name: 'Istanbul', code: 'IST'},
    {name: 'Paris', code: 'PRS'}
];
 

<SelectButton optionLabel="name" value={city} options={cities} onChange={(e) => setValue(e.value)}></SelectButton>
<SelectButton optionLabel="name" optionValue="code" value={city} options={cities} onChange={(e) => setValue(e.value)}></SelectButton>
 

When optionValue is not defined, value of an option refers to the option object itself.

Multiple

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.

Custom Content

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


<SelectButton optionLabel="name" optionValue="code" value={city} options={cities} onChange={(e) => setValue(e.value)} itemTemplate={itemTemplate} />
 

const itemTemplate = (option) => {
    // custom item content
}
 
SelectItem API
NameTypeDefaultDescription
labelstringnullLabel of the option.
valuestringnullValue of the option.
classNamestringnullClassName of the option.
titlestringnullTooltip text of the option. (Not supported)
disabledbooleanfalseWhether the option is disabled or not.
Properties
NameTypeDefaultDescription
idstringnullUnique identifier of the element.
valueanynullValue of the component.
optionsarraynullAn array of objects to display as the available options.
optionLabelstringnullName of the label field of an option when an arbitrary objects instead of SelectItems are used as options.
optionValuestringnullName of the value field of an option when arbitrary objects are used as options instead of SelectItems.
optionDisabledfunction | stringnullProperty name or getter function to use as the disabled flag of an option, defaults to false when not defined.
tabIndexnumbernullIndex of the element in tabbing order.
multiplebooleanfalseWhen specified, allows selecting multiple values.
unselectablebooleantrueWhether selection can be cleared.
disabledbooleanfalseWhen present, it specifies that the element should be disabled.
stylestringnullInline style of the element.
classNamestringnullStyle class of the element.
dataKeystringnullA property to uniquely match the value in options for better performance.
tooltipanynullContent of the tooltip.
tooltipOptionsobjectnullConfiguration of the tooltip, refer to the tooltip documentation for more information.
ariaLabelledBystringnullEstablishes relationships between the component and label(s) where its value should be one or more element IDs.
itemTemplatefunctionnullFunction that gets the option and returns the content.
Events
NameParametersDescription
onChangeevent.originalEvent: browser event
event.value: Single value or an array of values that are selected.
Callback to invoke on value change.
Dependencies

None.

Component Scale

Input Style

Ripple Effect

Free Themes

Built-in component themes created by the PrimeReact Theme Designer.

Bootstrap
Blue
Purple
Blue
Purple
Material Design
Indigo
Deep Purple
Indigo
Deep Purple
Material Design Compact
Indigo
Deep Purple
Indigo
Deep Purple
Tailwind
Tailwind Light
Fluent UI
Blue
PrimeOne Design - 2022 NEW
Lara Indigo
Lara Blue
Lara Purple
Lara Teal
Lara Indigo
Lara Blue
Lara Purple
Lara Teal
PrimeOne Design - 2021
Saga Blue
Saga Green
Saga Orange
Saga Purple
Vela Blue
Vela Green
Vela Orange
Vela Purple
Arya Blue
Arya Green
Arya Orange
Arya Purple
Premium Themes

Premium themes are only available exclusively for PrimeReact Theme Designer subscribers and therefore not included in PrimeReact core.

Soho Light
Soho Dark
Viva Light
Viva Dark
Mira
Nano

Legacy Free Themes

Nova
Nova Alt
Nova Accent
Luna Blue
Luna Green
Luna Amber
Luna Pink
Rhea

Premium Create-React-App Templates

Beautifully crafted premium create-react-app application templates by the PrimeTek design team.

Sakai
Atlantis
Freya
Ultima
Diamond
Sapphire
Serenity
Babylon
Avalon
Apollo
Roma