Select a complete group
A native indeterminate checkbox represents a partial choice without replacing the input semantics.
Keyboard
- Tab visits each native checkbox.
- Space toggles the focused choice; the parent reflects none, some or all.
States covered
- Partially selected
- All selected
- None selected
Install this complete example and its component dependencies.
npx shadcn@latest add https://ui.bld8.dev/r/example-checkbox-mixed.jsonComplete source
/*!
MIT License
Copyright (c) 2026 Jaison
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import {useState} from 'react';
import {Checkbox} from '@bld8/ui';
export default function ChannelExample(){
const [selected,setSelected]=useState(['product']);
const options=[{value:'product',label:'Product news channel'},{value:'research',label:'Research notes channel'}];
return <fieldset style={{border:0,padding:0,margin:0,display:'grid',gap:12}}>
<legend className="bui-label">Notification channels</legend>
<Checkbox label="Include all channels" hint="A dash means some channels are included."
checked={selected.length===options.length} indeterminate={selected.length>0&&selected.length<options.length}
onCheckedChange={checked=>setSelected(checked?options.map(option=>option.value):[])}/>
{options.map(option=><Checkbox key={option.value} name="channels" value={option.value} label={option.label}
checked={selected.includes(option.value)} onCheckedChange={checked=>setSelected(checked?[...selected,option.value]:selected.filter(value=>value!==option.value))}/>)}
<p role="status">{selected.length} channels included</p>
</fieldset>;
}