lara-light-indigo

Checkbox

Checkbox is an extension to standard checkbox element with skinning capabilities.

Basic
Multiple
Dynamic Values, Preselection, Value Binding and Disabled Option
Import via Module

import { Checkbox } from 'primereact/checkbox';
 
Import via CDN

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

Checkbox is used as a controlled input with checked and onChange properties.


<Checkbox onChange={e => setChecked(e.checked)} checked={checked}></Checkbox>
 
Multiple Values

Multiple checkboxes can be grouped using a list of values.


<div className="col-12">
    <Checkbox inputId="cb1" value="New York" onChange={onCityChange} checked={cities.includes('New York')}></Checkbox>
    <label htmlFor="cb1" className="p-checkbox-label">New York</label>
</div>
<div className="col-12">
    <Checkbox inputId="cb2" value="San Francisco" onChange={onCityChange} checked={cities.includes('San Francisco')}></Checkbox>
    <label htmlFor="cb2" className="p-checkbox-label">San Francisco</label>
</div>
<div className="col-12">
    <Checkbox inputId="cb3" value="Los Angeles" onChange={onCityChange} checked={cities.includes('Los Angeles')}></Checkbox>
    <label htmlFor="cb3" className="p-checkbox-label">Los Angeles</label>
</div>
 

const [cities, setCities] = useState([]);

const onCityChange = (e) => {
    let selectedCities = [...cities];
    if(e.checked)
        selectedCities.push(e.value);
    else
        selectedCities.splice(selectedCities.indexOf(e.value), 1);

    setCities(selectedCities);
}
 
Properties
NameTypeDefaultDescription
idstringnullUnique identifier of the element.
inputIdstringnullUnique identifier of the inner native radiobutton.
valueanynullValue of the checkbox.
namestringnullName of the checkbox element .
checkedbooleanfalseSpecifies whether a checkbox should be checked or not.
trueValueanytrueValue in checked state.
falseValueanyfalseValue in unchecked state.
stylestringnullInline style of the element.
classNamestringnullStyle class of the element.
disabledbooleanfalseWhen present, it specifies that the element value cannot be altered.
requiredbooleanfalseWhen present, it specifies that an input field must be filled out before submitting the form.
readOnlybooleanfalseWhen present, it specifies that the element cannot be typed.
tabIndexnumbernullIndex of the element in tabbing order.
iconstringpi pi-checkIcon class of the checkbox icon.
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.
Events
NameParametersDescription
onChangeevent.originalEvent: Original event
event.value: Value of the checkbox
event.checked: Checked state as a boolean.
Callback to invoke on value change
onMouseDownevent: Browser eventCallback to invoke to when a mouse button is pressed.
onContextMenuevent: Browser eventCallback to invoke on right-click.
Styling

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
p-checkboxContainer element
p-checkbox-boxContainer of icon.
p-checkbox-iconIcon element.
p-checkbox-labelLabel element and it is an external CSS class.
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