From 171cd4f21c0fa60e6ca7855e3f5b18b29a0d8a5b Mon Sep 17 00:00:00 2001 From: Alexandre Bourdin Date: Mon, 26 Sep 2022 11:35:54 +0200 Subject: [PATCH] Merge pull request #9724 from overleaf/ab-tag-modals-autofocus [web] Add autofocus to React dashboard tag modals GitOrigin-RevId: 804fee108ab8e1c5bf97ade8032c4ea363baf7bb --- .../project-list/components/modals/create-tag-modal.tsx | 5 ++++- .../project-list/components/modals/edit-tag-modal.tsx | 3 +++ .../project-list/components/modals/rename-tag-modal.tsx | 3 +++ .../web/frontend/js/shared/hooks/use-ref-with-auto-focus.ts | 4 ++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/services/web/frontend/js/features/project-list/components/modals/create-tag-modal.tsx b/services/web/frontend/js/features/project-list/components/modals/create-tag-modal.tsx index f5336dbdd5..6ecee4bfab 100644 --- a/services/web/frontend/js/features/project-list/components/modals/create-tag-modal.tsx +++ b/services/web/frontend/js/features/project-list/components/modals/create-tag-modal.tsx @@ -5,6 +5,7 @@ import { Tag } from '../../../../../../app/src/Features/Tags/types' import AccessibleModal from '../../../../shared/components/accessible-modal' import useAsync from '../../../../shared/hooks/use-async' import { useProjectListContext } from '../../context/project-list-context' +import { useRefWithAutoFocus } from '../../../../shared/hooks/use-ref-with-auto-focus' import { createTag } from '../../util/api' import { MAX_TAG_LENGTH } from '../../util/tag' @@ -24,6 +25,7 @@ export default function CreateTagModal({ const { tags } = useProjectListContext() const { t } = useTranslation() const { isError, runAsync, status } = useAsync() + const { autoFocusedRef } = useRefWithAutoFocus() const [tagName, setTagName] = useState() const [validationError, setValidationError] = useState() @@ -69,6 +71,7 @@ export default function CreateTagModal({
- {status === 'pending' ? t('creating') + '…' : t('create')} + {status === 'pending' ? <>{t('creating')} … : t('create')} diff --git a/services/web/frontend/js/features/project-list/components/modals/edit-tag-modal.tsx b/services/web/frontend/js/features/project-list/components/modals/edit-tag-modal.tsx index f575057da5..6dd4913343 100644 --- a/services/web/frontend/js/features/project-list/components/modals/edit-tag-modal.tsx +++ b/services/web/frontend/js/features/project-list/components/modals/edit-tag-modal.tsx @@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next' import { Button, Form, Modal } from 'react-bootstrap' import AccessibleModal from '../../../../shared/components/accessible-modal' import useAsync from '../../../../shared/hooks/use-async' +import { useRefWithAutoFocus } from '../../../../shared/hooks/use-ref-with-auto-focus' import { deleteTag, renameTag } from '../../util/api' import { Tag } from '../../../../../../app/src/Features/Tags/types' @@ -22,6 +23,7 @@ export default function EditTagModal({ onClose, }: EditTagModalProps) { const { t } = useTranslation() + const { autoFocusedRef } = useRefWithAutoFocus() const { isLoading: isDeleteLoading, isError: isDeleteError, @@ -79,6 +81,7 @@ export default function EditTagModal({ () const [newTagName, setNewTagName] = useState() const [validationError, setValidationError] = useState() @@ -78,6 +80,7 @@ export default function RenameTagModal({ () { +export function useRefWithAutoFocus() { const autoFocusedRef = useRef(null) useEffect(() => { @@ -11,7 +11,7 @@ export function useRefWithAutoFocus() { } }) } - }, [autoFocusedRef]) + }, []) return { autoFocusedRef } }