diff --git a/src/components/DomEvents.js b/src/components/DomEvents.js index ca9794fe..0a7b13ab 100644 --- a/src/components/DomEvents.js +++ b/src/components/DomEvents.js @@ -157,8 +157,9 @@ function DomEvents() { -
+
{({ width, height }) => ( /, '')); } -function Preview({ markup, accessibleRoles, elements, dispatch, variant }) { +function Preview({ + markup, + accessibleRoles, + elements, + dispatch, + variant, + forwardedRef, +}) { // Okay, listen up. `highlighted` can be a number of things, as I wanted to // keep a single variable to represent the state. This to reduce bug count // by creating out-of-sync states. @@ -33,7 +46,13 @@ function Preview({ markup, accessibleRoles, elements, dispatch, variant }) { element: highlighted, }); - // TestingLibraryDom?.getSuggestedQuery(highlighted, 'get').toString() : null + const refSetter = useCallback((node) => { + if (typeof forwardedRef === 'function') { + forwardedRef(node || null); + } + + htmlRoot.current = node; + }, []); useEffect(() => { const container = document.createElement('div'); @@ -154,7 +173,7 @@ function Preview({ markup, accessibleRoles, elements, dispatch, variant }) { className="preview" onClick={handleClick} onMouseMove={handleMove} - ref={htmlRoot} + ref={refSetter} dangerouslySetInnerHTML={{ __html: actualMarkup, }} diff --git a/src/components/StickyList.js b/src/components/StickyList.js index b4e60d2b..8e372b42 100644 --- a/src/components/StickyList.js +++ b/src/components/StickyList.js @@ -3,7 +3,6 @@ import { FixedSizeList as List } from 'react-window'; function StickyList( { - follow = false, mode = 'bottom', height, itemCount, @@ -17,17 +16,20 @@ function StickyList( ) { const innerRef = useRef(); useEffect(() => { - if (ref.current && follow && innerRef.current) { - if ( - mode === 'bottom' && - innerRef.current.offsetHeight > ref.current.props.height - ) { - ref.current.scrollTo(innerRef.current.offsetHeight); - } else if (mode === 'top') { - ref.current.scrollTo(0); - } + if (!ref.current || !innerRef.current) { + return; } - }, [itemCount, follow]); + + if (innerRef.current.offsetHeight <= ref.current.props.height) { + return; + } + + if (mode === 'bottom') { + ref.current.scrollTo(innerRef.current.offsetHeight); + } else { + ref.current.scrollTo(0); + } + }, [itemCount]); return (