Skip to content

Commit 2d526f4

Browse files
authored
fix(Date Input): make the focus go back to the input with error (#4129)
1 parent 3ce4ff8 commit 2d526f4

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

app/components/formElements/inputs/date/SplitDateInput.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ const SplitDateInput = ({
4444
const yearError = yearField.error();
4545
const fieldError = dayError ?? monthError ?? yearError ?? dateError;
4646

47+
const dayHasError = dayError !== null || dateError !== null;
48+
const monthHasError = monthError !== null;
49+
const yearHasError = yearError !== null;
50+
4751
const hasError = Boolean(fieldError);
4852
const errorId = `${name}-error`;
4953

@@ -52,7 +56,6 @@ const SplitDateInput = ({
5256
className={classNames("kern-fieldset", {
5357
"kern-fieldset--error": hasError,
5458
})}
55-
{...dateField.getControlProps()}
5659
>
5760
{label && <InputLabel name={name} label={label} suffix={suffix} />}
5861
<div className="kern-hint">
@@ -79,8 +82,8 @@ const SplitDateInput = ({
7982
"kern-form-input__input--error": dayError,
8083
},
8184
)}
82-
aria-invalid={dayError !== null}
83-
aria-describedby={dayError ? errorId : undefined}
85+
aria-invalid={dayHasError}
86+
aria-describedby={dayHasError ? errorId : undefined}
8487
/>
8588
</div>
8689

@@ -104,8 +107,8 @@ const SplitDateInput = ({
104107
"kern-form-input__input--error": monthError,
105108
},
106109
)}
107-
aria-invalid={monthError !== null}
108-
aria-describedby={monthError ? errorId : undefined}
110+
aria-invalid={monthHasError}
111+
aria-describedby={monthHasError ? errorId : undefined}
109112
/>
110113
</div>
111114

@@ -127,8 +130,8 @@ const SplitDateInput = ({
127130
"kern-form-input__input--error": yearError,
128131
},
129132
)}
130-
aria-invalid={yearError !== null}
131-
aria-describedby={yearError ? errorId : undefined}
133+
aria-invalid={yearHasError}
134+
aria-describedby={yearHasError ? errorId : undefined}
132135
/>
133136
</div>
134137
</div>

0 commit comments

Comments
 (0)