Scroll to top on submit

This commit is contained in:
AbdBarho
2023-01-17 07:05:46 +01:00
parent b8f5eacc13
commit e49654dfb7
+11 -1
View File
@@ -27,6 +27,8 @@ export const Task = ({ frontendId, task, trigger, mutate }) => {
const replyContent = useRef<TaskContent>(null);
const [showUnchangedWarning, setShowUnchangedWarning] = useState(false);
const rootEl = useRef<HTMLDivElement>(null);
const taskType = TaskTypes.find((taskType) => taskType.type === task.type && taskType.mode === task.mode);
const { trigger: sendRejection } = useSWRMutation("/api/reject_task", post, {
@@ -89,6 +91,7 @@ export const Task = ({ frontendId, task, trigger, mutate }) => {
content: replyContent.current,
});
setTaskStatus("SUBMITTED");
scrollToTop(rootEl.current);
break;
}
default:
@@ -138,7 +141,7 @@ export const Task = ({ frontendId, task, trigger, mutate }) => {
}
return (
<div>
<div ref={rootEl}>
{taskTypeComponent()}
<TaskControls
task={task}
@@ -164,3 +167,10 @@ export const Task = ({ frontendId, task, trigger, mutate }) => {
</div>
);
};
const scrollToTop = (element: HTMLElement) => {
while (element) {
element.scrollTop = 0;
element = element.parentElement;
}
};