-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(702): static catalog filter at the top of page #778
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome 🎉 , thanks @tplevko
useEffect(() => { | ||
document.getElementById('catalog-list')!.scrollTop = 0; | ||
}, [props.tiles]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tplevko This is a great addition 🎉 , I would just suggest if possible, using Ref
to get the element instead.
Maybe something like this could work:
const catalogBodyRef = useRef<HTMLDivElement>(null);
useEffect(() => {
catalogBodyRef.current?.scrollTop = 0;
}, [props.tiles]);
return (
<div id="catalog-list" className="catalog-list" ref={catalogBodyRef}>
...
This way we're resilient against changes and more important, we delegate the object fetching to react.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks for the hint! Works with no issue.
I also moved the div, so we would have static displayed element counter at the top.
vokoscreenNG-2024-02-02_12-17-32.mp4
10176fe
to
f33f003
Compare
@@ -28,25 +30,31 @@ export const BaseCatalog: FunctionComponent<BaseCatalogProps> = (props) => { | |||
[onTileClick, props.tiles], | |||
); | |||
|
|||
useEffect(() => { | |||
catalogBodyRef.current!.scrollTop = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this case, we can leave it because the div
is static, we just need to be aware that this might not be the case always 👀 and we can go 💥
fixes #702
vokoscreenNG-2024-02-02_11-56-08.mp4