Skip to content

Commit

Permalink
feat: scroll to feedback view on view change
Browse files Browse the repository at this point in the history
- 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"
  • Loading branch information
Mike-Heneghan committed Jan 30, 2024
1 parent 1f9d3b6 commit f2a6b23
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions editor.planx.uk/src/components/Feedback/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {
getInternalFeedbackMetadata,
insertFeedbackMutation,
} from "lib/feedback";
import { useStore } from "pages/FlowEditor/lib/store";
import { BackButton } from "pages/Preview/Questions";
import React, { useState, useEffect } from "react";
import React, { useEffect, useRef,useState } from "react";
import { usePrevious } from "react-use";
import FeedbackOption from "ui/public/FeedbackOption";

import FeedbackForm from "./FeedbackForm";
import FeedbackPhaseBanner from "./FeedbackPhaseBanner";
import { useStore } from "pages/FlowEditor/lib/store";


const FeedbackWrapper = styled(Box)(({ theme }) => ({
backgroundColor: theme.palette.background.paper,
Expand Down Expand Up @@ -98,6 +98,17 @@ const Feedback: React.FC = () => {
}
}, [breadcrumbs]);

const feedbackComponentRef = useRef<HTMLDivElement | null>(null);

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

function handleFeedbackViewClick(event: ClickEvents) {
switch (event) {
case "close":
Expand Down Expand Up @@ -364,7 +375,11 @@ const Feedback: React.FC = () => {
}
}

return <Feedback />;
return (
<div ref={feedbackComponentRef}>
<Feedback />
</div>
);
};

export default Feedback;

0 comments on commit f2a6b23

Please sign in to comment.