-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: scroll to feedback view on view change #2716
Conversation
Removed vultr server and associated DNS entries |
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.
Super nice improvement 👌 Make a big difference!
@@ -364,7 +375,11 @@ const Feedback: React.FC = () => { | |||
} | |||
} | |||
|
|||
return <Feedback />; | |||
return ( | |||
<div ref={feedbackComponentRef}> |
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.
nit: Throughout the codebase we tend to use MUI components, could we change this div
to a Box
for consistency?
9d86a34
to
5c8a4c3
Compare
f2a6b23
to
8735f3e
Compare
- As per: #2716 (comment) - More consistent within the codebase to use Box rather than div
8735f3e
to
cdc5118
Compare
case "banner": | ||
return false; | ||
case "thanks": | ||
return false; |
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.
case "banner": | |
return false; | |
case "thanks": | |
return false; | |
case "banner": | |
case "thanks": | |
return false; |
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.
nit: Sorry - small nitpick but a bit more readable / consistent with rest of codebase.
const feedbackComponentRef = useRef<HTMLDivElement | null>(null); | ||
|
||
useEffect(() => { | ||
if (currentFeedbackView === "input") { | ||
feedbackComponentRef.current?.scrollIntoView({ | ||
behavior: "smooth", | ||
block: "start", | ||
}); | ||
} | ||
}, [currentFeedbackView]); |
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.
A custom hook might be a slightly cleaner way of reusing this logic across both components / files?
Something like -
const useScrollIntoView = (currentFeedbackView) => {
const feedbackComponentRef = useRef<HTMLDivElement | null>(null);
const shouldScrollToView = () => **logic here**
useEffect(() => {
if (shouldScrollToView()) {
feedbackComponentRef.current?.scrollIntoView({
behavior: 'smooth',
block: 'start',
});
}
}, [currentFeedbackView]);
return feedbackComponentRef;
};
Alternatively just a wrapper for the feedback components with this logic could work also. If this makes things more complex or there's something I'm missing here no sweat!
09c59ee
to
94537fa
Compare
- As per: #2716 (comment) Co-authored-by: Dafydd Llŷr Pearson <[email protected]>
- When the currentFeedbackView changes the component can render partially off screen - Add ref and useEffect to scroll down when it changes and isn't the "banner" or "thanks"
- As per: #2716 (comment) - More consistent within the codebase to use Box rather than div
- When user's select "yes" or "no" and the form is rendered scroll to show the full form
…crolled to - The logical condition in the useEffect was somewhat hard to read - Added a case statement to make the logic more explicit / readable
- As per: #2716 (comment) Co-authored-by: Dafydd Llŷr Pearson <[email protected]>
4337884
to
e0aa9f6
Compare
What
Main Feedback:
MoreInfo Feedback:
Why
Risks
Screen recording
Before:
Screen.Recording.2024-01-30.at.16.53.09.mov
After:
Screen.Recording.2024-02-01.at.15.35.56.mov