فهرست منبع

Merge pull request #9572 from overleaf/ab-new-project-autofocus

[web] Autofocus on new project name input field

GitOrigin-RevId: 4e26b2b5b6d39df942dc8ed293d3e4212028e4b0
Davinder Singh 4 سال پیش
والد
کامیت
e65ede1d6a

+ 5 - 1
services/web/frontend/js/features/project-list/components/new-project-button/modal-content-new-project-form.tsx

@@ -6,6 +6,7 @@ import {
   getUserFacingMessage,
   postJSON,
 } from '../../../../infrastructure/fetch-json'
+import { useRefWithAutoFocus } from '../../../../shared/hooks/use-ref-with-auto-focus'
 
 type NewProjectData = {
   project_id: string
@@ -25,6 +26,7 @@ type Props = {
 
 function ModalContentNewProjectForm({ onCancel, template = 'none' }: Props) {
   const { t } = useTranslation()
+  const { autoFocusedRef } = useRefWithAutoFocus<HTMLInputElement>()
   const [projectName, setProjectName] = useState('')
   const { isLoading, isError, error, runAsync } = useAsync<NewProjectData>()
 
@@ -62,8 +64,10 @@ function ModalContentNewProjectForm({ onCancel, template = 'none' }: Props) {
         {isError && (
           <Alert bsStyle="danger">{getUserFacingMessage(error)}</Alert>
         )}
-        <FormControl
+        <input
           type="text"
+          className="form-control"
+          ref={autoFocusedRef}
           placeholder={t('project_name')}
           onChange={handleChangeName}
           value={projectName}

+ 2 - 2
services/web/frontend/js/shared/hooks/use-ref-with-auto-focus.js → services/web/frontend/js/shared/hooks/use-ref-with-auto-focus.ts

@@ -1,7 +1,7 @@
 import { useRef, useEffect } from 'react'
 
-export function useRefWithAutoFocus() {
-  const autoFocusedRef = useRef()
+export function useRefWithAutoFocus<T extends HTMLElement = any>() {
+  const autoFocusedRef = useRef<T>(null)
 
   useEffect(() => {
     if (autoFocusedRef.current) {