Replies: 1 comment
-
|
The The reason clicking on the The simplest fix is to wrap the whole thing in a clickable element yourself: <Field
className="flex items-center justify-start gap-2 rounded-md cursor-pointer transition-colors duration-300 px-4 py-2"
onClick={() => handleChange(!checked)}
>
<Checkbox
defaultChecked={defaultChecked}
checked={checked}
disabled={disabled}
onChange={handleChange}
as="div"
className="focus:outline-none"
>
{({ checked, disabled }) => (
<div>
{checked ? (
<CheckSquareIcon weight="fill" className="size-5" />
) : (
<SquareIcon className="size-5" />
)}
</div>
)}
</Checkbox>
{renderLabel && (
<Label className="truncate select-none cursor-pointer text-sm font-medium whitespace-nowrap">
{renderLabel()}
</Label>
)}
</Field>Alternatively, you could use a native <label className="flex items-center justify-start gap-2 rounded-md cursor-pointer transition-colors duration-300 px-4 py-2">
<Checkbox
checked={checked}
onChange={handleChange}
as="div"
className="focus:outline-none"
>
{({ checked }) => (
<div>
{checked ? <CheckSquareIcon weight="fill" className="size-5" /> : <SquareIcon className="size-5" />}
</div>
)}
</Checkbox>
<span className="truncate select-none text-sm font-medium whitespace-nowrap">
{renderLabel?.()}
</span>
</label>This is intended behavior — |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Version:
@headlessui/react": "^2.2.7"
I am rendering a <Checkbox/> with <Label/> - both within a <Field/> component.
The Field has a padding. Between the checkbox and the label is a gap (flexbox).
My problem:
The checkbox only gets toggled, if I click exactly on the Checkbox or Label area but it does not change when I click the padding area of the <Field/>. Is this a bug or intended and could I somehow change this behavior?
Clicking in the green are (padding of <Field/>) does not work (also not the gap of the Flexbox). I have to exactly hit the icon or label. I want the whole element to be clickable.

Beta Was this translation helpful? Give feedback.
All reactions