From 5e8e88cdf5520634eef398e9b775b868aa6895a3 Mon Sep 17 00:00:00 2001 From: SharglutDev Date: Fri, 10 Jan 2025 16:54:04 +0100 Subject: [PATCH] front: fix stdcm add via scroll - 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 --- .../stdcm/components/StdcmForm/StdcmVias.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/front/src/applications/stdcm/components/StdcmForm/StdcmVias.tsx b/front/src/applications/stdcm/components/StdcmForm/StdcmVias.tsx index e2cba5798b8..af2bed6c812 100644 --- a/front/src/applications/stdcm/components/StdcmForm/StdcmVias.tsx +++ b/front/src/applications/stdcm/components/StdcmForm/StdcmVias.tsx @@ -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]);