ToggleButton is used to select a boolean value using a button.
import { ToggleButton } from 'primereact/togglebutton';
<script src="https://unpkg.com/primereact/core/core.min.js"></script>
<script src="https://unpkg.com/primereact/togglebutton/togglebutton.min.js"></script>
ToggleButton is used as a controlled input with checked and onChange properties.
<ToggleButton checked={checked1} onChange={(e) => setChecked1(e.value)} />
Icons and Labels can be customized using onLabel, offLabel, onIcon and offIcon properties.
<ToggleButton onLabel="I confirm" offLabel="I reject" onIcon="pi pi-check" offIcon="pi pi-times" checked={checked2} onChange={(e) => setChecked2(e.value)} />
Any valid attribute is passed to the root element implicitly, extended properties are as follows;
Name | Type | Default | Description |
---|---|---|---|
id | string | null | Unique identifier of the element. |
onIcon | string | null | Icon for the on state. |
offIcon | string | null | Icon for the off state. |
onLabel | string | yes | Label for the on state. |
offLabel | string | no | Label for the off state. |
style | string | null | Inline style of the element. |
className | string | null | Style class of the element. |
checked | boolean | false | Specifies the on/off state of the button. |
tabIndex | number | 0 | Index of the element in tabbing order. |
iconPos | string | left | Position of the icon, valid values are "left" and "right". |
tooltip | any | null | Content of the tooltip. |
tooltipOptions | object | null | Configuration of the tooltip, refer to the tooltip documentation for more information. |
Name | Parameters | Description |
---|---|---|
onChange | event.originalEvent: Browser event event.value: Value as the checked state. | Callback to invoke on value change. |
onFocus | event: Browser event | Callback to invoke when autocomplete gets focus. |
onBlur | event: Browser event | Callback to invoke when autocomplete loses focus. |
Following is the list of structural style classes, for theming classes visit theming page.
Name | Element |
---|---|
p-togglebutton | Container element |
p-button-icon-left | Icon element. |
p-button-text | Label element. |
This section is under development. After the necessary tests and improvements are made, it will be shared with the users as soon as possible.
None.
Built-in component themes created by the PrimeReact Theme Designer.
Premium themes are only available exclusively for PrimeReact Theme Designer subscribers and therefore not included in PrimeReact core.
Beautifully crafted premium create-react-app application templates by the PrimeTek design team.