Skip to content

Commit

Permalink
fixed deselected - really this time
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnMarieW committed Oct 14, 2024
1 parent f13e653 commit 6ff0b21
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/ts/components/core/chip/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,24 @@ const Chip = (props: Props) => {
...others
} = props;

const onChange = (checked: boolean) => {
setProps({ checked });
};
// Fetch ChipGroupContext and check if the chip is part of a group
const chipGroupContext = React.useContext(ChipGroupContext);
const hasChipGroup = !!chipGroupContext;

const { chipOnClick } = React.useContext(ChipGroupContext) || {};
// Change handler
const onChange = (checked: boolean) => setProps({ checked });

console.log("chipOnClick", chipOnClick)
// Build eventProps conditionally
const eventProps = hasChipGroup
? { onClick: chipGroupContext?.chipOnClick }
: { checked, onChange };

return (
<MantineChip
checked={chipOnClick ? undefined : checked}
onChange={onChange}
onClick={chipOnClick}
data-dash-is-loading={
(loading_state && loading_state.is_loading) || undefined
}
{...eventProps} // Spread eventProps (onClick or checked/onChange)
{...others}
>
{children}
Expand Down

0 comments on commit 6ff0b21

Please sign in to comment.