Skip to content

Commit

Permalink
Bug: aria-invalid is overriden in TextInput (#4365)
Browse files Browse the repository at this point in the history
* Add failing test

* Add failing test

* Add fix

* Create grumpy-shirts-march.md
  • Loading branch information
pksjce authored and lukasoppermann committed Apr 16, 2024
1 parent cc467ec commit 81ac811
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/grumpy-shirts-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Bugfix: `aria-invalid` is overriden in TextInput
2 changes: 1 addition & 1 deletion packages/react/src/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ const TextInput = React.forwardRef<HTMLInputElement, TextInputProps>(
onBlur={handleInputBlur}
type={type}
aria-required={required}
aria-invalid={validationStatus === 'error' ? 'true' : undefined}
{...inputProps}
data-component="input"
aria-invalid={validationStatus === 'error' ? 'true' : undefined}
/>
<TextInputInnerVisualSlot
visualPosition="trailing"
Expand Down
6 changes: 6 additions & 0 deletions packages/react/src/__tests__/TextInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,10 @@ describe('TextInput', () => {
it('should render a password input', () => {
expect(render(<TextInput name="password" type="password" />)).toMatchSnapshot()
})

it('should not override prop aria-invalid', () => {
const onChange = jest.fn()
const {getByRole} = HTMLRender(<TextInput onChange={onChange} aria-invalid="true" value="" />)
expect(getByRole('textbox')).toHaveAttribute('aria-invalid', 'true')
})
})

0 comments on commit 81ac811

Please sign in to comment.