Skip to content

Commit

Permalink
fix(FormField): fix aria-invalid on error false (#4043)
Browse files Browse the repository at this point in the history
  • Loading branch information
aoelen authored Aug 19, 2020
1 parent 1c24915 commit d0dc3c4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
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)
})
})
})

0 comments on commit d0dc3c4

Please sign in to comment.