feat: auto-focus first fields.

This commit is contained in:
elforjani3
2020-12-01 15:14:05 +02:00
parent b5b9764676
commit d299785bfb
8 changed files with 59 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import React, { useEffect, useRef } from 'react';
import {
FormGroup,
InputGroup,
@@ -40,6 +40,14 @@ function ItemFormPrimarySection({
// #ownProps
itemType,
}) {
const nameFieldRef = useRef(null);
useEffect(() => {
// Auto focus item name field once component mount.
if (nameFieldRef.current) {
nameFieldRef.current.focus();
}
}, []);
const itemTypeHintContent = (
<>
@@ -112,7 +120,11 @@ function ItemFormPrimarySection({
helperText={<ErrorMessage name={'name'} />}
inline={true}
>
<InputGroup medium={true} {...field} />
<InputGroup
medium={true}
{...field}
inputRef={(ref) => (nameFieldRef.current = ref)}
/>
</FormGroup>
)}
</FastField>