mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-11-30 16:48:21 +01:00
58 lines
1.3 KiB
Plaintext
58 lines
1.3 KiB
Plaintext
# Checkbox
|
|
|
|
A control that allows the user to toggle between checked and not checked.
|
|
|
|
<WidgetExample name="checkbox-basic" />
|
|
|
|
## Use cases
|
|
|
|
- **Suitable**: A single binary choice (accepting terms, a subscription toggle)
|
|
- **Suitable**: Checkable items in a form
|
|
- **Not suitable**: Mutually exclusive choices (use `radio-group`)
|
|
|
|
## Usage
|
|
|
|
```tsx
|
|
import { Checkbox } from "@lcui/react"
|
|
```
|
|
|
|
```tsx
|
|
<Checkbox />
|
|
```
|
|
|
|
Use `checked` to control the checked state; a `change` event is emitted when it changes.
|
|
|
|
## Examples
|
|
|
|
### Description
|
|
|
|
Pair `FieldContent` and `FieldDescription` to add helper text to the option.
|
|
|
|
<WidgetExample name="checkbox-description" />
|
|
|
|
### Group
|
|
|
|
Combine several `Field`s to build a checkbox list.
|
|
|
|
<WidgetExample name="checkbox-group" />
|
|
|
|
### Indeterminate
|
|
|
|
`indeterminate` expresses the "some children are selected" visual state, showing a minus icon.
|
|
|
|
<WidgetExample name="checkbox-indeterminate" />
|
|
|
|
### Disabled
|
|
|
|
<WidgetExample name="checkbox-disabled" />
|
|
|
|
## Caveats
|
|
|
|
:::caution
|
|
**Indeterminate is a state, not a default.** The indeterminate state (`indeterminate="true"`) expresses the "some children are selected" visual state (for example, a parent checkbox when only some children are checked). Clicking an indeterminate checkbox transitions it to the checked state.
|
|
:::
|
|
|
|
## API Reference
|
|
|
|
<FieldTable name="checkbox" />
|