File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed
src/components/design-library-list Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -114,16 +114,21 @@ const DesignLibraryItem = props => {
114114 }
115115
116116 useEffect ( ( ) => {
117- if ( ! itemRef . current ) {
118- return
119- }
120-
121117 // Use a timeout to ensure designs have finished rendering before calculating visibility.
122118 const timeoutRef = setTimeout ( ( ) => {
123- const containerRect = document . querySelector ( '.ugb-modal-design-library__designs' ) . getBoundingClientRect ( )
124- const itemRect = itemRef . current . getBoundingClientRect ( )
119+ const itemEl = itemRef . current
120+ const containerEl = itemEl ?. closest ( '.ugb-modal-design-library__designs' ) || document . querySelector ( '.ugb-modal-design-library__designs' )
121+
122+ if ( ! itemEl || ! containerEl ) {
123+ return
124+ }
125+
126+ const containerRect = containerEl . getBoundingClientRect ( )
127+ const itemRect = itemEl . getBoundingClientRect ( )
128+
129+ const BOUNDARY = 250
125130
126- const render = itemRect . bottom >= containerRect . top - 250 && itemRect . top <= containerRect . bottom + 250
131+ const render = itemRect . bottom >= containerRect . top - BOUNDARY && itemRect . top <= containerRect . bottom + BOUNDARY
127132
128133 setShouldRender ( render )
129134 } , 250 )
You can’t perform that action at this time.
0 commit comments