Skip to content

Commit

Permalink
front: fix stdcm add via scroll
Browse files Browse the repository at this point in the history
- Focus the CI input of the new added via
- Reset the state giving the via index to scroll to after the action to enable the animation even when the user adds 2 vias in a row at the same index

Signed-off-by: SharglutDev <[email protected]>
  • Loading branch information
SharglutDev committed Jan 13, 2025
1 parent 4aeb5fd commit 5e8e88c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions front/src/applications/stdcm/components/StdcmForm/StdcmVias.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,19 @@ const StdcmVias = ({ disabled = false }: StdcmConfigCardProps) => {

requestId = requestAnimationFrame(scrollWithAnimation);

const cancelListener = () => cancelAnimationFrame(requestId);
const newElementCIInput: HTMLInputElement | null = newElement.querySelector('.ci-input input');

newElement.parentElement!.addEventListener('animationend', cancelListener);
if (newElementCIInput) newElementCIInput.focus({ preventScroll: true });

const handleAnimationEnd = () => {
cancelAnimationFrame(requestId);
setNewIntermediateOpIndex(undefined);
};

newElement.parentElement!.addEventListener('animationend', handleAnimationEnd);
return () => {
newElement.parentElement!.removeEventListener('animationend', cancelListener);
cancelListener();
newElement.parentElement!.removeEventListener('animationend', handleAnimationEnd);
cancelAnimationFrame(requestId);
};
}, [newIntermediateOpIndex]);

Expand Down

0 comments on commit 5e8e88c

Please sign in to comment.