Skip to content

Commit 1006b51

Browse files
author
Hector Arce De Las Heras
committed
Improve animations pillSelector
1 parent 8a63ace commit 1006b51

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/components/pillSelector/pillSelectorControlled.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,18 @@ const PillSelectorControlledComponent = React.forwardRef(
4747
);
4848

4949
React.useEffect(() => {
50+
let resizeObserver: ResizeObserver;
5051
if (!props.multiSelect && measuredRef?.current && props.pillSelected?.[0] && styles?.thumb) {
5152
updateMeasurements();
53+
resizeObserver = new ResizeObserver(() => {
54+
updateMeasurements();
55+
});
56+
// Start observing the element
57+
resizeObserver.observe(measuredRef.current);
5258
}
59+
return () => {
60+
resizeObserver?.disconnect();
61+
};
5362
}, [props.multiSelect, measuredRef, props.pills, props.pillSelected?.[0]]);
5463

5564
return (

src/components/pillSelector/pillSelectorStandAlone.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const PillSelectorStandAloneComponent = (
4242
<PillSelectorWrapper
4343
ref={listEl as React.RefObject<HTMLDivElement>}
4444
data-testid={`${dataTestId}PillSelector`}
45+
hasThumb={!!(!props.multiSelect && props.styles?.thumb)}
4546
isSelected={isPillSelected}
4647
role={ROLES.RADIOGROUP}
4748
styles={props.styles}

0 commit comments

Comments
 (0)