From 79372809713067e59194e7af77663b1c616f226b Mon Sep 17 00:00:00 2001 From: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com> Date: Tue, 21 Sep 2021 11:25:21 -0500 Subject: [PATCH] Fix `` scroll event handler --- ts/components/Modal.tsx | 11 ++++++++--- ts/util/lint/exceptions.json | 9 ++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ts/components/Modal.tsx b/ts/components/Modal.tsx index 8f6ffcf96894..ae28069feb55 100644 --- a/ts/components/Modal.tsx +++ b/ts/components/Modal.tsx @@ -38,6 +38,7 @@ export function Modal({ theme, }: Readonly): ReactElement { const modalRef = useRef(null); + const bodyRef = useRef(null); const [scrolled, setScrolled] = useState(false); const [hasOverflow, setHasOverflow] = useState(false); @@ -107,10 +108,14 @@ export function Modal({ ? getClassName('__body--overflow') : null )} - onScroll={event => { - setScrolled((event.target as HTMLDivElement).scrollTop > 2); + onScroll={() => { + const scrollTop = bodyRef.current?.scrollTop || 0; + setScrolled(scrollTop > 2); + }} + ref={bodyEl => { + measureRef(bodyEl); + bodyRef.current = bodyEl; }} - ref={measureRef} > {children} diff --git a/ts/util/lint/exceptions.json b/ts/util/lint/exceptions.json index ed28f0c6faaa..6be041ac4ec3 100644 --- a/ts/util/lint/exceptions.json +++ b/ts/util/lint/exceptions.json @@ -12659,6 +12659,13 @@ "reasonCategory": "usageTrusted", "updated": "2021-08-05T00:22:31.660Z" }, + { + "rule": "React-useRef", + "path": "ts/components/Modal.tsx", + "line": " const bodyRef = useRef(null);", + "reasonCategory": "usageTrusted", + "updated": "2021-09-21T01:40:08.534Z" + }, { "rule": "React-useRef", "path": "ts/components/ProfileEditor.tsx", @@ -14367,4 +14374,4 @@ "reasonCategory": "usageTrusted", "updated": "2021-09-17T21:02:59.414Z" } -] +] \ No newline at end of file