Skip to content

Commit 87252e1

Browse files
authored
Fix aria-invalid attributes to have a valid 'true' value (#3639)
This PR fixes an issue with the `aria-invalid` attributes on some form elements. In theory this shouldn't matter and behaves the same as other attributes. MDN also mentions that any other value than the known set of values will be treated as `true`. However, some tools, including the Accessibility tab in Google Chrome will complain because we set it to `aria-invalid=""`. We already used `'true'` for `aria-checked` as well, so this change makes it more consistent. It will also make sure that `aria-invalid:flex` in Tailwind CSS works as expected because this compiles to: ```css .aria-invalid\:flex { &[aria-invalid="true"] { display: flex; } } ``` Which means that the current implementation didn't work in this case either. Fixes: #3623
1 parent 1be0e67 commit 87252e1

File tree

4 files changed

+4
-3
lines changed

4 files changed

+4
-3
lines changed

packages/@headlessui-react/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Use correct `ownerDocument` when using internal `<Portal/>` element ([#3594](https://github.com/tailwindlabs/headlessui/pull/3594))
1313
- Bump `@tanstack/react-virtual` to be fix warnings in React 19 projects ([#3588](https://github.com/tailwindlabs/headlessui/pull/3588))
14+
- Fix `aria-invalid` attributes to have a valid `'true'` value ([#3639](https://github.com/tailwindlabs/headlessui/pull/3639))
1415

1516
## [2.2.0] - 2024-10-25
1617

packages/@headlessui-react/src/components/input/input.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function InputFn<TTag extends ElementType = typeof DEFAULT_INPUT_TAG>(
6666
id,
6767
'aria-labelledby': labelledBy,
6868
'aria-describedby': describedBy,
69-
'aria-invalid': invalid ? '' : undefined,
69+
'aria-invalid': invalid ? 'true' : undefined,
7070
disabled: disabled || undefined,
7171
autoFocus,
7272
},

packages/@headlessui-react/src/components/select/select.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function SelectFn<TTag extends ElementType = typeof DEFAULT_SELECT_TAG>(
6969
id,
7070
'aria-labelledby': labelledBy,
7171
'aria-describedby': describedBy,
72-
'aria-invalid': invalid ? '' : undefined,
72+
'aria-invalid': invalid ? 'true' : undefined,
7373
disabled: disabled || undefined,
7474
autoFocus,
7575
},

packages/@headlessui-react/src/components/textarea/textarea.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function TextareaFn<TTag extends ElementType = typeof DEFAULT_TEXTAREA_TAG>(
6666
id,
6767
'aria-labelledby': labelledBy,
6868
'aria-describedby': describedBy,
69-
'aria-invalid': invalid ? '' : undefined,
69+
'aria-invalid': invalid ? 'true' : undefined,
7070
disabled: disabled || undefined,
7171
autoFocus,
7272
},

0 commit comments

Comments
 (0)