Skip to content

Commit

Permalink
feat(KVStoreModal): add useRef for smooth scrolling (#3077)
Browse files Browse the repository at this point in the history
Co-authored-by: portuu3 <[email protected]>
  • Loading branch information
flopez7 and portuu3 authored Feb 21, 2025
1 parent ad26574 commit 88e5ec2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/apps/staking/src/components/modals/KVStoreModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
Tooltip,
Typography,
} from '@mui/material';
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useRef } from 'react'; // <-- Importa useRef
import { useSnackbar } from '../../providers/SnackProvider';
import BaseModal from './BaseModal';

Expand All @@ -44,6 +44,7 @@ const KVStoreModal: React.FC<Props> = ({
>([]);
const [loading, setLoading] = useState(false);
const { showError } = useSnackbar();
const formContainerRef = useRef<HTMLDivElement | null>(null);

useEffect(() => {
if (open) {
Expand All @@ -54,8 +55,7 @@ const KVStoreModal: React.FC<Props> = ({
setFormData(preparedData);
setPendingChanges([]);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open]);
}, [open, initialData]);

const updatePendingChanges = (key: string, value: string) => {
setPendingChanges((prev) => {
Expand Down Expand Up @@ -125,6 +125,12 @@ const KVStoreModal: React.FC<Props> = ({

const handleAddField = () => {
setFormData((prev) => [...prev, { key: '', value: '' }]);

setTimeout(() => {
formContainerRef.current?.lastElementChild?.scrollIntoView({
behavior: 'smooth',
});
}, 100);
};

const handleSave = async () => {
Expand Down Expand Up @@ -169,6 +175,7 @@ const KVStoreModal: React.FC<Props> = ({
Edit KVStore
</Typography>
<Box
ref={formContainerRef}
sx={{
maxHeight: '400px',
overflowY: 'auto',
Expand Down

0 comments on commit 88e5ec2

Please sign in to comment.