Checkbox
A control for toggling between checked and unchecked, keeping the native input.
Installation
Shadwire follows shadcn/ui's open code model: the component's source is copied into your application and becomes yours. Install it with the CLI:
The checkbox registry item installs these files:
-
app/components/ui_component.rb -
app/components/ui/checkbox_component.rb -
app/helpers/ui/checkbox_helper.rb -
vendor/shadwire/shadwire.css
Haven't installed the CLI yet? gem install shadwire, then shadwire init.
Usage
The component styles a native <input type="checkbox">,
so semantics, focus and keyboard handling come from the browser. The check mark is drawn by
the .shadwire-checkbox utility in
shadwire.css.
Or render the component
Ui::CheckboxComponent
directly:
Examples
Default
A styled native checkbox, tied to a ui_label through for:/id:.
Checked
Use checked: true to render it checked; pair it with supporting text.
We send at most one email a week.
Disabled
disabled: true disables the native input.
With form_with
Use form.field_name/form.field_id. Unlike form.check_box, there is no hidden input, so treat a missing parameter as unchecked.
API reference
ui_checkbox(**options)
wraps
Ui::CheckboxComponent.new(**options).
| Argument | Type | Default | Description |
|---|---|---|---|
checked |
Boolean | false |
Renders the input checked. |
disabled |
Boolean | false |
Disables the native input. |
class / class_name |
String | nil |
Extra classes, merged after the base classes. |
**attrs |
Hash | {} |
Free HTML attributes (name, id, value, data:, aria:, …). |