Skip to content

Commit 17eedaa

Browse files
committed
fix: initial height of event log pane
1 parent 7c9f409 commit 17eedaa

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

src/components/DomEvents.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ function DomEvents() {
157157
<MarkupEditor markup={markup} dispatch={dispatch} />
158158
</div>
159159

160-
<div className="flex-auto h-56 md:h-full" ref={setPreviewRef}>
160+
<div className="flex-auto h-56 md:h-full">
161161
<Preview
162+
forwardedRef={setPreviewRef}
162163
markup={markup}
163164
elements={result.elements}
164165
accessibleRoles={result.accessibleRoles}
@@ -196,7 +197,6 @@ function DomEvents() {
196197
<AutoSizer>
197198
{({ width, height }) => (
198199
<StickyList
199-
follow={true}
200200
mode="bottom"
201201
ref={listRef}
202202
height={height}

src/components/Preview.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import React, { useState, useEffect, useRef, useMemo } from 'react';
1+
import React, {
2+
useState,
3+
useEffect,
4+
useRef,
5+
useMemo,
6+
useCallback,
7+
} from 'react';
28
import Scrollable from './Scrollable';
39
import PreviewHint from './PreviewHint';
410
import AddHtml from './AddHtml';
@@ -8,7 +14,14 @@ function selectByCssPath(rootNode, cssPath) {
814
return rootNode?.querySelector(cssPath.toString().replace(/^body > /, ''));
915
}
1016

11-
function Preview({ markup, accessibleRoles, elements, dispatch, variant }) {
17+
function Preview({
18+
markup,
19+
accessibleRoles,
20+
elements,
21+
dispatch,
22+
variant,
23+
forwardedRef,
24+
}) {
1225
// Okay, listen up. `highlighted` can be a number of things, as I wanted to
1326
// keep a single variable to represent the state. This to reduce bug count
1427
// by creating out-of-sync states.
@@ -33,7 +46,13 @@ function Preview({ markup, accessibleRoles, elements, dispatch, variant }) {
3346
element: highlighted,
3447
});
3548

36-
// TestingLibraryDom?.getSuggestedQuery(highlighted, 'get').toString() : null
49+
const refSetter = useCallback((node) => {
50+
if (typeof forwardedRef === 'function') {
51+
forwardedRef(node || null);
52+
}
53+
54+
htmlRoot.current = node;
55+
}, []);
3756

3857
useEffect(() => {
3958
const container = document.createElement('div');
@@ -154,7 +173,7 @@ function Preview({ markup, accessibleRoles, elements, dispatch, variant }) {
154173
className="preview"
155174
onClick={handleClick}
156175
onMouseMove={handleMove}
157-
ref={htmlRoot}
176+
ref={refSetter}
158177
dangerouslySetInnerHTML={{
159178
__html: actualMarkup,
160179
}}

src/components/StickyList.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { FixedSizeList as List } from 'react-window';
33

44
function StickyList(
55
{
6-
follow = false,
76
mode = 'bottom',
87
height,
98
itemCount,
@@ -17,17 +16,14 @@ function StickyList(
1716
) {
1817
const innerRef = useRef();
1918
useEffect(() => {
20-
if (ref.current && follow && innerRef.current) {
21-
if (
22-
mode === 'bottom' &&
23-
innerRef.current.offsetHeight > ref.current.props.height
24-
) {
19+
if (ref.current && innerRef.current) {
20+
if (mode === 'bottom') {
2521
ref.current.scrollTo(innerRef.current.offsetHeight);
2622
} else if (mode === 'top') {
2723
ref.current.scrollTo(0);
2824
}
2925
}
30-
}, [itemCount, follow]);
26+
}, [itemCount]);
3127

3228
return (
3329
<List

0 commit comments

Comments
 (0)