Skip to content

Commit

Permalink
feat: add scroll to feedback input in MoreInfo
Browse files Browse the repository at this point in the history
- When user's select "yes" or "no" and the form is rendered scroll to show the full form
  • Loading branch information
Mike-Heneghan committed Feb 2, 2024
1 parent ffdce5d commit a71b56e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions editor.planx.uk/src/components/Feedback/MoreInfoFeedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getInternalFeedbackMetadata,
insertFeedbackMutation,
} from "lib/feedback";
import React, { useState } from "react";
import React, { useEffect, useRef, useState } from "react";
import FeedbackOption from "ui/public/FeedbackOption";

import { FeedbackFormInput, UserFeedback } from ".";
Expand All @@ -36,6 +36,16 @@ const MoreInfoFeedbackComponent: React.FC = () => {
const [currentFeedbackView, setCurrentFeedbackView] =
useState<View>("yes/no");
const [feedbackOption, setFeedbackOption] = useState<Sentiment | null>(null);
const feedbackComponentRef = useRef<HTMLDivElement | null>(null);

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

const handleFeedbackOptionClick = (event: Sentiment) => {
switch (event) {
Expand Down Expand Up @@ -142,7 +152,11 @@ const MoreInfoFeedbackComponent: React.FC = () => {
}
}

return <MoreInfoFeedbackView />;
return (
<Box ref={feedbackComponentRef}>
<MoreInfoFeedbackView />
</Box>
);
};

export default MoreInfoFeedbackComponent;

0 comments on commit a71b56e

Please sign in to comment.