Skip to content
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

Merged
merged 5 commits into from
Feb 2, 2024

Conversation

Mike-Heneghan
Copy link
Contributor

@Mike-Heneghan Mike-Heneghan commented Jan 30, 2024

What

Main Feedback:

  • Add ref and useEffect to scroll down when it changes and isn't the "banner" or "thanks"

MoreInfo Feedback:

  • Add ref and useEffect to scroll down when it changes is "input"

Why

  • When the currentFeedbackView changes the component can render partially off screen

Risks

  • This might have a negative impact on accessibility / usability?

Screen recording

Before:

Screen.Recording.2024-01-30.at.16.53.09.mov

After:

Screen.Recording.2024-02-01.at.15.35.56.mov

Copy link

github-actions bot commented Jan 30, 2024

Removed vultr server and associated DNS entries

Copy link
Contributor

@DafyddLlyr DafyddLlyr left a 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}>
Copy link
Contributor

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?

@Mike-Heneghan Mike-Heneghan force-pushed the mh/wire-up-feedback-forms branch from 9d86a34 to 5c8a4c3 Compare January 31, 2024 17:57
@Mike-Heneghan Mike-Heneghan self-assigned this Feb 1, 2024
Mike-Heneghan added a commit that referenced this pull request Feb 1, 2024
- As per: #2716 (comment)
- More consistent within the codebase to use Box rather than div
Comment on lines 105 to 107
case "banner":
return false;
case "thanks":
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case "banner":
return false;
case "thanks":
return false;
case "banner":
case "thanks":
return false;

Copy link
Contributor

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.

Comment on lines +39 to +48
const feedbackComponentRef = useRef<HTMLDivElement | null>(null);

useEffect(() => {
if (currentFeedbackView === "input") {
feedbackComponentRef.current?.scrollIntoView({
behavior: "smooth",
block: "start",
});
}
}, [currentFeedbackView]);
Copy link
Contributor

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!

@Mike-Heneghan Mike-Heneghan force-pushed the mh/wire-up-feedback-forms branch 2 times, most recently from 09c59ee to 94537fa Compare February 2, 2024 11:49
Base automatically changed from mh/wire-up-feedback-forms to main February 2, 2024 14:08
Mike-Heneghan added a commit that referenced this pull request Feb 2, 2024
Mike-Heneghan and others added 5 commits February 2, 2024 14:11
- 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
@Mike-Heneghan Mike-Heneghan merged commit 12b78fd into main Feb 2, 2024
12 checks passed
@Mike-Heneghan Mike-Heneghan deleted the mh/scroll-to-feedback branch February 2, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants