Skip to content

Commit

Permalink
Adding aria-invalid="true" to TextInput when error (#4349)
Browse files Browse the repository at this point in the history
* Adding aria-invalid="true" to TextInput when error

* Create gold-baboons-live.md
  • Loading branch information
jonrohan authored Mar 4, 2024
1 parent 9c535e8 commit 15c078d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-baboons-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Adding aria-invalid="true" to TextInput when error.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/react/src/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const TextInput = React.forwardRef<HTMLInputElement, TextInputProps>(
aria-required={required}
{...inputProps}
data-component="input"
aria-invalid={validationStatus === 'error' ? 'true' : undefined}
/>
<TextInputInnerVisualSlot
visualPosition="trailing"
Expand Down
7 changes: 6 additions & 1 deletion packages/react/src/__tests__/TextInput.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {SearchIcon} from '@primer/octicons-react'
import userEvent from '@testing-library/user-event'
import {render as HTMLRender, fireEvent} from '@testing-library/react'
import {render as HTMLRender, fireEvent, screen} from '@testing-library/react'
import {axe} from 'jest-axe'
import React from 'react'
import {TextInput} from '..'
Expand Down Expand Up @@ -39,6 +39,11 @@ describe('TextInput', () => {
expect(render(<TextInput name="zipcode" validationStatus="error" />)).toMatchSnapshot()
})

it('renders sets aria-invalid="true" on error', () => {
HTMLRender(<TextInput name="zipcode" validationStatus="error" data-testid="zipcodeInput" />)
expect(screen.getByTestId('zipcodeInput')).toHaveAttribute('aria-invalid', 'true')
})

it('renders contrast', () => {
expect(render(<TextInput name="zipcode" contrast />)).toMatchSnapshot()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ exports[`TextInput renders error 1`] = `
onClick={[Function]}
>
<input
aria-invalid="true"
className="c2"
data-component="input"
name="zipcode"
Expand Down

0 comments on commit 15c078d

Please sign in to comment.