From 568ac95f88ffd61523fbdcc43f027472202d0913 Mon Sep 17 00:00:00 2001 From: acyza <101238421+acyza@users.noreply.github.com> Date: Tue, 21 Mar 2023 02:54:14 +0800 Subject: [PATCH 1/6] fix: invalid autofocus --- src/DialogWrap.tsx | 2 +- tests/index.spec.tsx | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/DialogWrap.tsx b/src/DialogWrap.tsx index 344a9631..2b44303e 100644 --- a/src/DialogWrap.tsx +++ b/src/DialogWrap.tsx @@ -41,7 +41,7 @@ const DialogWrap: React.FC = (props: IDialogPropTypes) => { { expect(wrapper.find('.rc-dialog-footer').text()).toBe('test'); }); - // 失效了,需要修复 - it.skip('support input autoFocus', () => { + it('support input autoFocus', () => { render( From 3de72fdceb102a98d828f4eb497e1b7be2d16a0e Mon Sep 17 00:00:00 2001 From: acyza <101238421+acyza@users.noreply.github.com> Date: Tue, 21 Mar 2023 03:49:08 +0800 Subject: [PATCH 2/6] fix: test fail --- src/DialogWrap.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DialogWrap.tsx b/src/DialogWrap.tsx index 2b44303e..29d768d6 100644 --- a/src/DialogWrap.tsx +++ b/src/DialogWrap.tsx @@ -1,5 +1,5 @@ -import * as React from 'react'; import Portal from '@rc-component/portal'; +import * as React from 'react'; import Dialog from './Dialog'; import type { IDialogPropTypes } from './IDialogPropTypes'; @@ -41,7 +41,7 @@ const DialogWrap: React.FC = (props: IDialogPropTypes) => { Date: Tue, 21 Mar 2023 03:59:14 +0800 Subject: [PATCH 3/6] chore: update --- src/DialogWrap.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DialogWrap.tsx b/src/DialogWrap.tsx index 29d768d6..df777f54 100644 --- a/src/DialogWrap.tsx +++ b/src/DialogWrap.tsx @@ -41,7 +41,7 @@ const DialogWrap: React.FC = (props: IDialogPropTypes) => { Date: Tue, 21 Mar 2023 08:15:39 +0800 Subject: [PATCH 4/6] chore: update --- src/DialogWrap.tsx | 3 ++- src/util.ts | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/DialogWrap.tsx b/src/DialogWrap.tsx index df777f54..8fcc77f9 100644 --- a/src/DialogWrap.tsx +++ b/src/DialogWrap.tsx @@ -2,6 +2,7 @@ import Portal from '@rc-component/portal'; import * as React from 'react'; import Dialog from './Dialog'; import type { IDialogPropTypes } from './IDialogPropTypes'; +import { isNil } from './util'; // fix issue #10656 /* @@ -41,7 +42,7 @@ const DialogWrap: React.FC = (props: IDialogPropTypes) => { Date: Tue, 21 Mar 2023 08:37:37 +0800 Subject: [PATCH 5/6] chore: update --- src/Dialog/index.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Dialog/index.tsx b/src/Dialog/index.tsx index 3dc6a661..ab287323 100644 --- a/src/Dialog/index.tsx +++ b/src/Dialog/index.tsx @@ -48,6 +48,7 @@ export default function Dialog(props: IDialogPropTypes) { const contentRef = useRef(); const [animatedVisible, setAnimatedVisible] = React.useState(visible); + const [originFocusEl, setOriginFocusEl] = React.useState(); // ========================== Init ========================== const ariaId = useId(); @@ -59,7 +60,10 @@ export default function Dialog(props: IDialogPropTypes) { } function focusDialogContent() { - if (!contains(wrapperRef.current, document.activeElement)) { + if (originFocusEl) return originFocusEl.focus(); + if (contains(wrapperRef.current, document.activeElement)) { + setOriginFocusEl(document.activeElement as HTMLElement); + } else { contentRef.current?.focus(); } } From a2ab585dbd37cb45a09ced85d35ddd5cc5f4c5f3 Mon Sep 17 00:00:00 2001 From: acyza <101238421+acyza@users.noreply.github.com> Date: Tue, 21 Mar 2023 09:18:56 +0800 Subject: [PATCH 6/6] chore: update --- src/Dialog/index.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Dialog/index.tsx b/src/Dialog/index.tsx index ab287323..33983508 100644 --- a/src/Dialog/index.tsx +++ b/src/Dialog/index.tsx @@ -60,8 +60,9 @@ export default function Dialog(props: IDialogPropTypes) { } function focusDialogContent() { - if (originFocusEl) return originFocusEl.focus(); - if (contains(wrapperRef.current, document.activeElement)) { + if (originFocusEl) { + originFocusEl.focus(); + } else if (contains(wrapperRef.current, document.activeElement)) { setOriginFocusEl(document.activeElement as HTMLElement); } else { contentRef.current?.focus();