-
-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected behavior from CheckboxCheck
with custom children when unchecked
#3814
Comments
Hi @bengry! Could you please provide a StackBlitz or CodeSandbox with the code you're trying to implement and its current behavior? This will help determine if |
Sure, you can see my use-case demoed here. What I'm trying to achieve is to render |
It seems that export const MenuItemCheckbox = forwardRef<
HTMLDivElement,
MenuItemCheckboxProps
>(function MenuItemCheckbox(props, ref) {
const menu = Ariakit.useMenuContext()!;
const checked = menu.useState((state) => {
// Ariakit should probably provide an isChecked/useChecked helper to simplify
// this implementation
const name = props.name;
const value = props.value;
const storeValue = state.values[name];
if (value == null) return !!storeValue;
if (!Array.isArray(storeValue)) return false;
return storeValue.includes(`${value}`);
})
return (
<Ariakit.MenuItemCheckbox
ref={ref}
{...props}
className={clsx('menu-item', props.className)}
>
<VisualCheckbox checked={checked} />
{props.children}
</Ariakit.MenuItemCheckbox>
);
}); |
Thanks, this makes sense. Isn't the |
In a case where supplying a custom
<CheckboxCheck>
where you want to render something even when the item is unchecked (e.g. an empty checkbox), this won't work:In this case the checkbox would only render when
checked=true
.I tried to work around this using
render
:But then you get duplicated checkmarks when
checked={true}
.So I tried this workaround:
Expecting to override the default children and avoid the duplicated checkboxes, but that doesn't work because Ariakit checked if children is truthy, rather than just
!== undefined
.This is of course still workaroundable by using a function for the
render
prop and omittingchildren
, or passing in an empty Fragment asCheckboxCheck
'schildren
, but that seems like a hack more than anything.I'd expect Ariakit to only supply the default SVG checkmark when
children
are not specified at all, not just when they're falsey.The text was updated successfully, but these errors were encountered: