Skip to content

Commit 555b3ec

Browse files
committed
feat(KVStoreModal): add useRef for smooth scrolling
1 parent 44f16df commit 555b3ec

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/apps/staking/src/components/modals/KVStoreModal.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
Tooltip,
2020
Typography,
2121
} from '@mui/material';
22-
import React, { useEffect, useState } from 'react';
22+
import React, { useEffect, useState, useRef } from 'react'; // <-- Importa useRef
2323
import { useSnackbar } from '../../providers/SnackProvider';
2424
import { CaseConverter } from '../../utils/case-converter';
2525
import BaseModal from './BaseModal';
@@ -45,6 +45,7 @@ const KVStoreModal: React.FC<Props> = ({
4545
>([]);
4646
const [loading, setLoading] = useState(false);
4747
const { showError } = useSnackbar();
48+
const formContainerRef = useRef<HTMLDivElement | null>(null);
4849

4950
useEffect(() => {
5051
if (open) {
@@ -55,8 +56,7 @@ const KVStoreModal: React.FC<Props> = ({
5556
setFormData(preparedData);
5657
setPendingChanges([]);
5758
}
58-
// eslint-disable-next-line react-hooks/exhaustive-deps
59-
}, [open]);
59+
}, [open, initialData]);
6060

6161
const updatePendingChanges = (key: string, value: string) => {
6262
setPendingChanges((prev) => {
@@ -126,6 +126,12 @@ const KVStoreModal: React.FC<Props> = ({
126126

127127
const handleAddField = () => {
128128
setFormData((prev) => [...prev, { key: '', value: '' }]);
129+
130+
setTimeout(() => {
131+
formContainerRef.current?.lastElementChild?.scrollIntoView({
132+
behavior: 'smooth',
133+
});
134+
}, 100);
129135
};
130136

131137
const handleSave = async () => {
@@ -170,6 +176,7 @@ const KVStoreModal: React.FC<Props> = ({
170176
Edit KVStore
171177
</Typography>
172178
<Box
179+
ref={formContainerRef}
173180
sx={{
174181
maxHeight: '400px',
175182
overflowY: 'auto',

0 commit comments

Comments
 (0)