From bc2cb8be8ccdab79bfbe91d3fa781fff33ce0f7c Mon Sep 17 00:00:00 2001 From: Stephan Meijer Date: Wed, 17 Jun 2020 15:45:07 +0200 Subject: [PATCH 1/2] fix: initial height of event log pane --- src/components/DomEvents.js | 4 ++-- src/components/Preview.js | 27 +++++++++++++++++++++++---- src/components/StickyList.js | 10 +++------- 3 files changed, 28 insertions(+), 13 deletions(-) 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..c9ecdb69 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,14 @@ function StickyList( ) { const innerRef = useRef(); useEffect(() => { - if (ref.current && follow && innerRef.current) { - if ( - mode === 'bottom' && - innerRef.current.offsetHeight > ref.current.props.height - ) { + if (ref.current && innerRef.current) { + if (mode === 'bottom') { ref.current.scrollTo(innerRef.current.offsetHeight); } else if (mode === 'top') { ref.current.scrollTo(0); } } - }, [itemCount, follow]); + }, [itemCount]); return ( Date: Wed, 17 Jun 2020 16:08:40 +0200 Subject: [PATCH 2/2] chore: reduce nesting of conditions --- src/components/StickyList.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/StickyList.js b/src/components/StickyList.js index c9ecdb69..8e372b42 100644 --- a/src/components/StickyList.js +++ b/src/components/StickyList.js @@ -16,12 +16,18 @@ function StickyList( ) { const innerRef = useRef(); useEffect(() => { - if (ref.current && innerRef.current) { - if (mode === 'bottom') { - ref.current.scrollTo(innerRef.current.offsetHeight); - } else if (mode === 'top') { - ref.current.scrollTo(0); - } + if (!ref.current || !innerRef.current) { + return; + } + + if (innerRef.current.offsetHeight <= ref.current.props.height) { + return; + } + + if (mode === 'bottom') { + ref.current.scrollTo(innerRef.current.offsetHeight); + } else { + ref.current.scrollTo(0); } }, [itemCount]);