diff --git a/packages/actify/src/components/Select/Select.tsx b/packages/actify/src/components/Select/Select.tsx index 5014998..7c5bf4d 100644 --- a/packages/actify/src/components/Select/Select.tsx +++ b/packages/actify/src/components/Select/Select.tsx @@ -38,19 +38,14 @@ const Select = (props: SelectProps) => { Tag = OutlinedField } - React.useLayoutEffect(() => { - const width = ref?.current?.getBoundingClientRect().width - setReferenceWidth(width) - }, []) - React.useEffect(() => { - const updateWidth = () => { + const resizeObserver = new ResizeObserver(() => { const width = ref?.current?.getBoundingClientRect().width setReferenceWidth(width) - } - window.addEventListener('resize', updateWidth) + }) + resizeObserver.observe(ref?.current as Element) return () => { - window.removeEventListener('resize', updateWidth) + resizeObserver.disconnect() } }, [])