1+ import { useResizeObserver } from '@react-aria/utils' ;
12import { ForwardedRef , forwardRef , useEffect , useMemo , useState } from 'react' ;
23import { useHover , useMove } from 'react-aria' ;
34
@@ -153,7 +154,7 @@ interface HandlerProps extends BasePropsWithoutChildren {
153154}
154155
155156const Handler = ( props : HandlerProps ) => {
156- const { direction = 'right' , isDisabled } = props ;
157+ const { direction = 'right' , isDisabled, ... otherProps } = props ;
157158 const { hoverProps, isHovered } = useHover ( { } ) ;
158159 const isHorizontal = direction === 'left' || direction === 'right' ;
159160 const localIsHovered = useDebouncedValue ( isHovered , 150 ) ;
@@ -170,7 +171,7 @@ const Handler = (props: HandlerProps) => {
170171 } ,
171172 'data-direction' : direction ,
172173 } ,
173- props ,
174+ otherProps ,
174175 ) }
175176 >
176177 < div data-element = "Track" />
@@ -222,12 +223,29 @@ function ResizablePanel(
222223 maxSize = isControllable ? undefined : 'min(50%, 400px)' ,
223224 ...restProps
224225 } = props ;
225-
226226 const [ isDragging , setIsDragging ] = useState ( false ) ;
227227 const isHorizontal = direction === 'left' || direction === 'right' ;
228228
229229 ref = useCombinedRefs ( ref ) ;
230230
231+ const onResize = useEvent ( ( ) => {
232+ if ( ref ?. current ) {
233+ const offsetProp = isHorizontal ? 'offsetWidth' : 'offsetHeight' ;
234+ const containerSize = ref . current [ offsetProp ] ;
235+
236+ if ( Math . abs ( containerSize - size ) < 1 && ! isDisabled ) {
237+ setVisualSize ( size ) ;
238+ } else {
239+ setVisualSize ( containerSize ) ;
240+ }
241+ }
242+ } ) ;
243+
244+ useResizeObserver ( {
245+ ref,
246+ onResize,
247+ } ) ;
248+
231249 function clamp ( size : number ) {
232250 if ( typeof maxSize === 'number' ) {
233251 size = Math . min ( maxSize , size ) ;
@@ -296,16 +314,7 @@ function ResizablePanel(
296314 } ) ;
297315
298316 useEffect ( ( ) => {
299- if ( ref . current ) {
300- const offsetProp = isHorizontal ? 'offsetWidth' : 'offsetHeight' ;
301- const containerSize = ref . current [ offsetProp ] ;
302-
303- if ( Math . abs ( containerSize - size ) < 1 && ! isDisabled ) {
304- setVisualSize ( size ) ;
305- } else {
306- setVisualSize ( containerSize ) ;
307- }
308- }
317+ onResize ( ) ;
309318 } , [ size , isDisabled ] ) ;
310319
311320 useEffect ( ( ) => {
0 commit comments