Auto-focus first input element in creation forms

Co-authored-by: René Pfeuffer<rene.pfeuffer@cloudogu.com>
Committed-by: René Pfeuffer<rene.pfeuffer@cloudogu.com>
This commit is contained in:
Rene Pfeuffer
2024-12-19 13:54:02 +01:00
parent 45801c9813
commit 190961df28
7 changed files with 17 additions and 7 deletions

View File

@@ -0,0 +1,2 @@
- type: changed
description: Set focus to first input element in repository, user, group, branch and repository role creation forms

View File

@@ -35,8 +35,8 @@ const RepositoryRoleForm: FC<Props> = ({ role: initialRole, submitForm }) => {
name: "",
verbs: [],
_links: {
create: { href: createLink }
}
create: { href: createLink },
},
}
);
const availableVerbs = data?.verbs;
@@ -51,7 +51,7 @@ const RepositoryRoleForm: FC<Props> = ({ role: initialRole, submitForm }) => {
const handleVerbChange = (value: boolean, name: string) =>
setRole({
...role,
verbs: value ? [...role.verbs, name] : role.verbs.filter(v => v !== name)
verbs: value ? [...role.verbs, name] : role.verbs.filter((v) => v !== name),
});
const submit = (event: FormEvent<HTMLFormElement>) => {
@@ -72,6 +72,7 @@ const RepositoryRoleForm: FC<Props> = ({ role: initialRole, submitForm }) => {
onChange={handleNameChange}
value={role.name || ""}
disabled={!!initialRole}
autofocus
/>
<div className="field">
<label className="label">{t("repositoryRole.form.permissions")}</label>

View File

@@ -118,6 +118,7 @@ const GroupForm: FC<Props> = ({ submitForm, loading, group, transmittedName = ""
value={groupState.name}
validationError={nameValidationError}
helpText={t("groupForm.help.nameHelpText")}
autofocus
/>
);
} else if (group.external) {

View File

@@ -28,6 +28,8 @@ type Props = {
disabled?: boolean;
};
const autoFocus = (el) => el?.focus();
const BranchForm: FC<Props> = ({ submitForm, branches, disabled, transmittedName, loading }) => {
const [t] = useTranslation("repos");
const [name, setName] = useState(transmittedName || "");
@@ -45,15 +47,15 @@ const BranchForm: FC<Props> = ({ submitForm, branches, disabled, transmittedName
if (isValid()) {
submitForm({
name,
parent: source
parent: source,
});
}
};
orderBranches(branches);
const options = branches.map(branch => ({
const options = branches.map((branch) => ({
label: branch.name,
value: branch.name
value: branch.name,
}));
return (
@@ -65,9 +67,10 @@ const BranchForm: FC<Props> = ({ submitForm, branches, disabled, transmittedName
name="source"
label={t("branches.create.source")}
options={options}
onChange={setSource}
onChange={(e) => setSource(e.target.value)}
loading={loading}
disabled={disabled}
ref={autoFocus}
/>
<InputField
name="name"

View File

@@ -97,6 +97,7 @@ const NamespaceAndNameFields: FC<Props> = ({ repository, onChange, setValid, dis
helpText={t("help.nameHelpText")}
disabled={disabled}
required={true}
autofocus={namespaceStrategy !== CUSTOM_NAMESPACE_STRATEGY}
/>
</>
);

View File

@@ -72,6 +72,7 @@ const NamespaceInput: FC<Props> = ({
required={true}
aria-required={true}
nullable
ref={(el) => el?.focus()}
/>
);
}

View File

@@ -68,6 +68,7 @@ const CreateUserForm: FC<{ users: UserCollection }> = ({ users }) => {
validate: userValidator.isNameValid,
}}
testId="input-username"
autoFocus
/>
<Form.Input
name="displayName"