This is an automated email from the ASF dual-hosted git repository.

shuai pushed a commit to branch test
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git


The following commit(s) were added to refs/heads/test by this push:
     new f7bf234d fix: whene clise edit users profile modal sholud clear form 
state
f7bf234d is described below

commit f7bf234da90bf8a41b64ca050d90e9b8c591cbe8
Author: shuai <[email protected]>
AuthorDate: Wed Jun 12 18:04:48 2024 +0800

    fix: whene clise edit users profile modal sholud clear form state
---
 ui/src/components/SchemaForm/index.tsx       |  6 +++---
 ui/src/hooks/useChangeProfileModal/index.tsx |  1 +
 ui/src/utils/common.ts                       | 12 ++++++++++++
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/ui/src/components/SchemaForm/index.tsx 
b/ui/src/components/SchemaForm/index.tsx
index ba4acadd..6b7cbbf0 100644
--- a/ui/src/components/SchemaForm/index.tsx
+++ b/ui/src/components/SchemaForm/index.tsx
@@ -29,7 +29,7 @@ import { useTranslation } from 'react-i18next';
 import isEmpty from 'lodash/isEmpty';
 import classnames from 'classnames';
 
-import { scrollToElementTop } from '@/utils';
+import { scrollElementIntoView } from '@/utils';
 import type * as Type from '@/common/interface';
 
 import type {
@@ -202,7 +202,7 @@ const SchemaForm: ForwardRefRenderFunction<FormRef, 
FormProps> = (
       if (onChange instanceof Function) {
         onChange({ ...formData });
       }
-      scrollToElementTop(document.getElementById(errors[0]));
+      scrollElementIntoView(document.getElementById(errors[0]));
       return false;
     }
     const syncErrors = await syncValidator();
@@ -218,7 +218,7 @@ const SchemaForm: ForwardRefRenderFunction<FormRef, 
FormProps> = (
       if (onChange instanceof Function) {
         onChange({ ...formData });
       }
-      scrollToElementTop(document.getElementById(syncErrors[0].key));
+      scrollElementIntoView(document.getElementById(syncErrors[0].key));
       return false;
     }
     return true;
diff --git a/ui/src/hooks/useChangeProfileModal/index.tsx 
b/ui/src/hooks/useChangeProfileModal/index.tsx
index 891c7894..e4496461 100644
--- a/ui/src/hooks/useChangeProfileModal/index.tsx
+++ b/ui/src/hooks/useChangeProfileModal/index.tsx
@@ -94,6 +94,7 @@ const useChangeProfileModal = (props: IProps = {}, userData) 
=> {
   }>(null);
 
   const onClose = () => {
+    setFormData(initFormData(schema));
     setVisibleState(false);
   };
 
diff --git a/ui/src/utils/common.ts b/ui/src/utils/common.ts
index 27d303b3..97880bf7 100644
--- a/ui/src/utils/common.ts
+++ b/ui/src/utils/common.ts
@@ -60,6 +60,17 @@ function scrollToElementTop(element) {
   });
 }
 
+function scrollElementIntoView(element) {
+  if (!element) {
+    return;
+  }
+  element.scrollIntoView({
+    behavior: 'smooth',
+    block: 'center',
+    inline: 'center',
+  });
+}
+
 const scrollToDocTop = () => {
   setTimeout(() => {
     window.scrollTo({
@@ -274,6 +285,7 @@ function changeTheme(mode: 'default' | 'light' | 'dark' | 
'system') {
 export {
   thousandthDivision,
   formatCount,
+  scrollElementIntoView,
   scrollToElementTop,
   scrollToDocTop,
   bgFadeOut,

Reply via email to