Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/shared/components/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Checkbox as KitCheckbox } from "@omniroute/ui-kit/checkbox";

interface CheckboxProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "type"> {
label?: React.ReactNode;
/** The kit's "–" mixed state (a DOM property applied via ref, not an HTML attribute). */
indeterminate?: boolean;
}

/**
Expand All @@ -14,10 +16,18 @@ interface CheckboxProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>
* the native <input> as in the legacy Checkbox.
*/
const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(function Checkbox(
{ label, className, ...props },
{ label, className, indeterminate, ...props },
ref
) {
return <KitCheckbox ref={ref} label={label} className={className} {...props} />;
return (
<KitCheckbox
ref={ref}
label={label}
className={className}
indeterminate={indeterminate}
{...props}
/>
);
});

export default Checkbox;
14 changes: 14 additions & 0 deletions tests/unit/ui/adapters/textarea-checkbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,18 @@ describe("Textarea / Checkbox adapters", () => {
expect(container.querySelector("label")).toBeNull();
expect(container.querySelector("input[type=checkbox]")).not.toBeNull();
});

it("Checkbox forwards indeterminate to the kit's mixed state and clears it", () => {
const { getByLabelText, rerender } = render(
<Checkbox aria-label="all" checked={false} onChange={() => {}} indeterminate />
);
const box = getByLabelText("all") as HTMLInputElement;
expect(box.indeterminate).toBe(true);
expect(box.matches(":indeterminate")).toBe(true);
rerender(
<Checkbox aria-label="all" checked={false} onChange={() => {}} indeterminate={false} />
);
expect(box.indeterminate).toBe(false);
expect(box.matches(":indeterminate")).toBe(false);
});
});