Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FormField): fix aria-invalid on error false #4043

Merged
merged 1 commit into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/collections/Form/FormField.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function FormField(props) {
const ariaDescribedBy = id && error ? `${id}-error-message` : null
const ariaAttrs = {
'aria-describedby': ariaDescribedBy,
'aria-invalid': error !== undefined ? true : undefined,
'aria-invalid': error ? true : undefined,
}
const controlProps = { ...rest, content, children, disabled, required, type, id }

Expand Down
31 changes: 31 additions & 0 deletions test/specs/collections/Form/FormField-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,35 @@ describe('FormField', () => {
expect(fieldId).to.equal('testId')
})
})

describe('aria-invalid', () => {
it('is not set by default', () => {
shallow(<FormField control='input' />)
.find('input')
.should.not.have.prop('aria-invalid')
})
it('is not set when error is false', () => {
shallow(<FormField control='input' error={false} />)
.find('input')
.should.not.have.prop('aria-invalid')
})
it('is set when error is true', () => {
shallow(<FormField control='input' error />)
.find('input')
.should.have.prop('aria-invalid', true)
})
it('is is set when error object is provided', () => {
shallow(
<FormField
control='input'
error={{
content: 'Error message',
pointing: 'left',
}}
/>,
)
.find('input')
.should.have.prop('aria-invalid', true)
})
})
})