Checkbox
A custom checkbox backed by a native checkbox input and Tavix icons. Use it for independent selections such as preferences, permissions, and terms of service.
Import Checkbox
Import Checkbox from Tavix:
import { Checkbox, Checkbox2 } from "tavix";Component API
<Checkbox
disabled={false}
className
size
{...props}
/>Props
disabled: Prevents interaction whentrue. Defaults tofalse.className: Additional classes applied to the checkbox wrapper.size: Font size applied to the wrapper while preserving scalable icon sizing....props: Additional native checkbox attributes and event handlers, such aschecked,defaultChecked,name,value,required, andonChange.
Behavior
- Renders a native checkbox input for standard form and browser behavior.
- Uses the native checked state to determine whether the checkbox is selected.
- Supports both controlled and uncontrolled usage through native checkbox props.
- Calls the native
onChangehandler with the browser change event. - Prevents interaction and applies the disabled state when
disabledistrue. - Forwards native form attributes such as
nameandvalue. - Uses Tavix icons to display the checkbox state.
- Preserves scalable icon sizing through the
sizewrapper setting.
Examples
Basic checkbox
<Checkbox
name="terms"
value="accepted"
aria-label="Accept terms"
onChange={handleChange}
/>Controlled checkbox
const [accepted, setAccepted] = useState(false);
<Checkbox
name="terms"
checked={accepted}
onChange={(event) => {
setAccepted(event.target.checked);
}}
aria-label="Accept terms and conditions"
/>;Initially checked
Use defaultChecked when the checkbox should be uncontrolled but selected initially:
<Checkbox
name="notifications"
value="enabled"
defaultChecked
aria-label="Enable notifications"
/>;Disabled checkbox
<Checkbox
name="archived"
checked
disabled
aria-label="Archived setting"
/>;Checkbox with a visible label
<label>
<Checkbox name="newsletter" value="subscribed" />
Subscribe to the newsletter
</label>Accessibility
- Provide a visible label using a
<label>element whenever possible. - Use
aria-labelwhen no visible text label surrounds the checkbox. - Use
aria-labelledbywhen the accessible name is provided by another element. - Use
disabledwhen the user cannot change the checkbox state. - Use
requiredwhen the checkbox must be selected before form submission.
Form usage
Checkboxes use native form semantics. Give related controls distinct name and value attributes when submitting multiple selections:
<Checkbox name="features" value="analytics" aria-label="Analytics" />
<Checkbox name="features" value="exports" aria-label="Exports" />
<Checkbox name="features" value="alerts" aria-label="Alerts" />Notes
checkedanddefaultCheckedfollow native checkbox behavior.- Use
checkedwithonChangefor a controlled checkbox. - Use
defaultCheckedfor an uncontrolled checkbox with an initial state. - The component forwards native checkbox props to the underlying input.
classNamestyles the checkbox wrapper rather than replacing native form behavior.