Checkbox
Compound API — bind:checked
Checkbox.Root + Checkbox.Indicator.
State: not selected
tsx
import { component$, useSignal } from "@builder.io/qwik";
import { Checkbox, CheckboxCheckIcon } from "~/components/ui/base/checkbox";
export default component$(() => {
const checked = useSignal(false);
return (
<div class="flex items-center gap-2">
<Checkbox.Root bind:checked={checked} aria-labelledby="demo-cb-compound-label">
<Checkbox.Indicator>
<CheckboxCheckIcon />
</Checkbox.Indicator>
</Checkbox.Root>
<span id="demo-cb-compound-label" class="text-sm text-muted-foreground">
State: {checked.value ? "selected" : "not selected"}
</span>
</div>
);
});
CheckboxControl
A single component with an icon; always with a direct headless tree inside (suitable with bind:checked).
State: not selected
tsx
import { component$, useSignal } from "@builder.io/qwik";
import { CheckboxControl } from "~/components/ui/base/checkbox";
export default component$(() => {
const ok = useSignal(false);
return (
<div class="flex items-center gap-2">
<CheckboxControl bind:checked={ok} aria-label="I agree" />
<span class="text-sm text-muted-foreground">
State: {ok.value ? "selected" : "not selected"}
</span>
</div>
);
});
CheckboxField — click on label
Combines CheckboxControl and Label; clicking the text toggles the same signal as the checkbox.
tsx
import { component$, useSignal } from "@builder.io/qwik";
import { CheckboxField } from "~/components/ui/base/checkbox";
export default component$(() => {
const accepted = useSignal(false);
return (
<CheckboxField bind:checked={accepted} label="I agree to the terms" />
);
});
Custom row (Label + onClick$)
The same behavior manually: aria-labelledby + toggling the signal in onClick on the label (without htmlFor / for`).
tsx
import { $, component$, useSignal } from "@builder.io/qwik";
import { CheckboxControl } from "~/components/ui/base/checkbox";
import { Label } from "~/components/ui/base/label";
export default component$(() => {
const v = useSignal(false);
const id = "my-cb";
const lid = "my-cb-lbl";
return (
<div class="flex items-center gap-2">
<CheckboxControl bind:checked={v} id={id} aria-labelledby={lid} />
<Label id={lid} class="cursor-pointer" onClick$={$(() => { v.value = !v.value; })}>
Custom text
</Label>
</div>
);
});
Metadata
Source: meta.generated.json (see npm run generate)
File base/checkbox/meta.generated.json not found or path not allowed.