mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #9724 from overleaf/ab-tag-modals-autofocus
[web] Add autofocus to React dashboard tag modals GitOrigin-RevId: 804fee108ab8e1c5bf97ade8032c4ea363baf7bb
This commit is contained in:
parent
4013288971
commit
171cd4f21c
4 changed files with 12 additions and 3 deletions
|
@ -5,6 +5,7 @@ import { Tag } from '../../../../../../app/src/Features/Tags/types'
|
||||||
import AccessibleModal from '../../../../shared/components/accessible-modal'
|
import AccessibleModal from '../../../../shared/components/accessible-modal'
|
||||||
import useAsync from '../../../../shared/hooks/use-async'
|
import useAsync from '../../../../shared/hooks/use-async'
|
||||||
import { useProjectListContext } from '../../context/project-list-context'
|
import { useProjectListContext } from '../../context/project-list-context'
|
||||||
|
import { useRefWithAutoFocus } from '../../../../shared/hooks/use-ref-with-auto-focus'
|
||||||
import { createTag } from '../../util/api'
|
import { createTag } from '../../util/api'
|
||||||
import { MAX_TAG_LENGTH } from '../../util/tag'
|
import { MAX_TAG_LENGTH } from '../../util/tag'
|
||||||
|
|
||||||
|
@ -24,6 +25,7 @@ export default function CreateTagModal({
|
||||||
const { tags } = useProjectListContext()
|
const { tags } = useProjectListContext()
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { isError, runAsync, status } = useAsync<Tag>()
|
const { isError, runAsync, status } = useAsync<Tag>()
|
||||||
|
const { autoFocusedRef } = useRefWithAutoFocus<HTMLInputElement>()
|
||||||
|
|
||||||
const [tagName, setTagName] = useState<string>()
|
const [tagName, setTagName] = useState<string>()
|
||||||
const [validationError, setValidationError] = useState<string>()
|
const [validationError, setValidationError] = useState<string>()
|
||||||
|
@ -69,6 +71,7 @@ export default function CreateTagModal({
|
||||||
<Modal.Body>
|
<Modal.Body>
|
||||||
<Form name="createTagForm" onSubmit={handleSubmit}>
|
<Form name="createTagForm" onSubmit={handleSubmit}>
|
||||||
<input
|
<input
|
||||||
|
ref={autoFocusedRef}
|
||||||
className="form-control"
|
className="form-control"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="New Tag Name"
|
placeholder="New Tag Name"
|
||||||
|
@ -102,7 +105,7 @@ export default function CreateTagModal({
|
||||||
status === 'pending' || !tagName?.length || !!validationError
|
status === 'pending' || !tagName?.length || !!validationError
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{status === 'pending' ? t('creating') + '…' : t('create')}
|
{status === 'pending' ? <>{t('creating')} …</> : t('create')}
|
||||||
</Button>
|
</Button>
|
||||||
</Modal.Footer>
|
</Modal.Footer>
|
||||||
</AccessibleModal>
|
</AccessibleModal>
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next'
|
||||||
import { Button, Form, Modal } from 'react-bootstrap'
|
import { Button, Form, Modal } from 'react-bootstrap'
|
||||||
import AccessibleModal from '../../../../shared/components/accessible-modal'
|
import AccessibleModal from '../../../../shared/components/accessible-modal'
|
||||||
import useAsync from '../../../../shared/hooks/use-async'
|
import useAsync from '../../../../shared/hooks/use-async'
|
||||||
|
import { useRefWithAutoFocus } from '../../../../shared/hooks/use-ref-with-auto-focus'
|
||||||
import { deleteTag, renameTag } from '../../util/api'
|
import { deleteTag, renameTag } from '../../util/api'
|
||||||
import { Tag } from '../../../../../../app/src/Features/Tags/types'
|
import { Tag } from '../../../../../../app/src/Features/Tags/types'
|
||||||
|
|
||||||
|
@ -22,6 +23,7 @@ export default function EditTagModal({
|
||||||
onClose,
|
onClose,
|
||||||
}: EditTagModalProps) {
|
}: EditTagModalProps) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const { autoFocusedRef } = useRefWithAutoFocus<HTMLInputElement>()
|
||||||
const {
|
const {
|
||||||
isLoading: isDeleteLoading,
|
isLoading: isDeleteLoading,
|
||||||
isError: isDeleteError,
|
isError: isDeleteError,
|
||||||
|
@ -79,6 +81,7 @@ export default function EditTagModal({
|
||||||
<Modal.Body>
|
<Modal.Body>
|
||||||
<Form name="editTagRenameForm" onSubmit={handleSubmit}>
|
<Form name="editTagRenameForm" onSubmit={handleSubmit}>
|
||||||
<input
|
<input
|
||||||
|
ref={autoFocusedRef}
|
||||||
className="form-control"
|
className="form-control"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Tag Name"
|
placeholder="Tag Name"
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { Tag } from '../../../../../../app/src/Features/Tags/types'
|
||||||
import AccessibleModal from '../../../../shared/components/accessible-modal'
|
import AccessibleModal from '../../../../shared/components/accessible-modal'
|
||||||
import useAsync from '../../../../shared/hooks/use-async'
|
import useAsync from '../../../../shared/hooks/use-async'
|
||||||
import { useProjectListContext } from '../../context/project-list-context'
|
import { useProjectListContext } from '../../context/project-list-context'
|
||||||
|
import { useRefWithAutoFocus } from '../../../../shared/hooks/use-ref-with-auto-focus'
|
||||||
import { renameTag } from '../../util/api'
|
import { renameTag } from '../../util/api'
|
||||||
import { MAX_TAG_LENGTH } from '../../util/tag'
|
import { MAX_TAG_LENGTH } from '../../util/tag'
|
||||||
|
|
||||||
|
@ -24,6 +25,7 @@ export default function RenameTagModal({
|
||||||
const { tags } = useProjectListContext()
|
const { tags } = useProjectListContext()
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { isLoading, isError, runAsync, status } = useAsync()
|
const { isLoading, isError, runAsync, status } = useAsync()
|
||||||
|
const { autoFocusedRef } = useRefWithAutoFocus<HTMLInputElement>()
|
||||||
|
|
||||||
const [newTagName, setNewTagName] = useState<string>()
|
const [newTagName, setNewTagName] = useState<string>()
|
||||||
const [validationError, setValidationError] = useState<string>()
|
const [validationError, setValidationError] = useState<string>()
|
||||||
|
@ -78,6 +80,7 @@ export default function RenameTagModal({
|
||||||
<Modal.Body>
|
<Modal.Body>
|
||||||
<Form name="renameTagForm" onSubmit={handleSubmit}>
|
<Form name="renameTagForm" onSubmit={handleSubmit}>
|
||||||
<input
|
<input
|
||||||
|
ref={autoFocusedRef}
|
||||||
className="form-control"
|
className="form-control"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Tag Name"
|
placeholder="Tag Name"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { useRef, useEffect } from 'react'
|
import { useRef, useEffect } from 'react'
|
||||||
|
|
||||||
export function useRefWithAutoFocus<T extends HTMLElement = any>() {
|
export function useRefWithAutoFocus<T extends HTMLElement = HTMLElement>() {
|
||||||
const autoFocusedRef = useRef<T>(null)
|
const autoFocusedRef = useRef<T>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -11,7 +11,7 @@ export function useRefWithAutoFocus<T extends HTMLElement = any>() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}, [autoFocusedRef])
|
}, [])
|
||||||
|
|
||||||
return { autoFocusedRef }
|
return { autoFocusedRef }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue