Skip to content

Commit 05f8fad

Browse files
committed
ISSUE #4548 - fix ticket group rule value autofocus
1 parent ebab5d2 commit 05f8fad

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

frontend/src/v5/ui/routes/viewer/tickets/ticketsForm/ticketGroups/groups/groupRulesForm/groupRulesForm.component.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export const GroupRulesForm = ({ onSave, onClose, rule, existingRules = [] }: IG
100100
<InputsContainer>
101101
<FormTextField
102102
required
103+
autoFocus
103104
name="name"
104105
label={formatMessage({ id: 'tickets.groups.filterPanel.name', defaultMessage: 'Name' })}
105106
formError={errors.name}

frontend/src/v5/ui/routes/viewer/tickets/ticketsForm/ticketGroups/groups/groupRulesForm/groupRulesInputs/ruleFieldValues/fieldValueInput/fieldValueInput.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { get } from 'lodash';
2424
import { ListboxComponent } from './listboxComponent/listboxComponent.component';
2525
import { Autocomplete } from './fieldValueInput.styles';
2626

27-
export const FieldValueInput = ({ name, disabled }) => {
27+
export const FieldValueInput = ({ name, autoFocus = false, disabled }) => {
2828
const { formState: { errors } } = useFormContext();
2929
const fields = useSelector(selectMetaKeys);
3030

@@ -49,7 +49,7 @@ export const FieldValueInput = ({ name, disabled }) => {
4949
error={!!get(errors, name)}
5050
InputProps={{
5151
...InputProps,
52-
autoFocus: true,
52+
autoFocus,
5353
}}
5454
{...renderInputParams}
5555
/>

frontend/src/v5/ui/routes/viewer/tickets/ticketsForm/ticketGroups/groups/groupRulesForm/groupRulesInputs/ruleFieldValues/ruleFieldValues.component.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { useFormContext, useFieldArray } from 'react-hook-form';
19-
import { useEffect } from 'react';
19+
import { useEffect, useState } from 'react';
2020
import AddValueIcon from '@assets/icons/outlined/add_circle-outlined.svg';
2121
import RemoveValueIcon from '@assets/icons/outlined/remove_circle-outlined.svg';
2222
import { range } from 'lodash';
@@ -26,12 +26,16 @@ import { FieldValueInput } from './fieldValueInput/fieldValueInput.component';
2626

2727
export const RuleFieldValues = ({ disabled }) => {
2828
const name = 'field.values';
29+
const [autoFocus, setAutoFocus] = useState(false);
2930
const { control, watch, setValue } = useFormContext<IFormRule>();
3031
const { fields, append, remove } = useFieldArray({ control, name });
3132

3233
const operator = watch('field.operator');
3334

34-
const appendEmptyValue = () => append({ value: '' });
35+
const appendEmptyValue = () => {
36+
append({ value: '' });
37+
setAutoFocus(!!fields.length);
38+
};
3539

3640
useEffect(() => {
3741
if (fields.length) return;
@@ -53,7 +57,7 @@ export const RuleFieldValues = ({ disabled }) => {
5357
<>
5458
{fields.map((field, i) => (
5559
<ValuesContainer key={field.id}>
56-
<FieldValueInput name={`field.values.${i}.value`} disabled={disabled} />
60+
<FieldValueInput name={`field.values.${i}.value`} autoFocus={autoFocus} disabled={disabled} />
5761
<ValueIconContainer onClick={() => remove(i)} disabled={disabled || fields.length === 1}>
5862
<RemoveValueIcon />
5963
</ValueIconContainer>

0 commit comments

Comments
 (0)