Skip to content

fix(form-state): explicitly handle when state is set to empty string. fixes #2166 #2167

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

Merged
merged 5 commits into from
Nov 13, 2018
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
33 changes: 33 additions & 0 deletions src/components/form-input/form-input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ describe('form-input', async () => {
expect(input.classes()).not.toContain('is-invalid')
})

it('does not have is-valid or is-invalid classes when state=""', async () => {
const wrapper = mount(Input, {
propsData: {
state: ''
}
})
const input = wrapper.find('input')
expect(input.classes()).not.toContain('is-valid')
expect(input.classes()).not.toContain('is-invalid')
})

it('has class is-valid when state=true', async () => {
const wrapper = mount(Input, {
propsData: {
Expand All @@ -135,6 +146,17 @@ describe('form-input', async () => {
expect(input.classes()).not.toContain('is-invalid')
})

it('has class is-valid when state="valid"', async () => {
const wrapper = mount(Input, {
propsData: {
state: 'valid'
}
})
const input = wrapper.find('input')
expect(input.classes()).toContain('is-valid')
expect(input.classes()).not.toContain('is-invalid')
})

it('has class is-invalid when state=false', async () => {
const wrapper = mount(Input, {
propsData: {
Expand All @@ -146,6 +168,17 @@ describe('form-input', async () => {
expect(input.classes()).not.toContain('is-valid')
})

it('has class is-invalid when state="invalid"', async () => {
const wrapper = mount(Input, {
propsData: {
state: 'invalid'
}
})
const input = wrapper.find('input')
expect(input.classes()).toContain('is-invalid')
expect(input.classes()).not.toContain('is-valid')
})

it('does not have aria-invalid attribute by default', async () => {
const wrapper = mount(Input)
expect(wrapper.contains('[aria-invalid]')).toBe(false)
Expand Down
7 changes: 5 additions & 2 deletions src/mixins/form-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ export default {
props: {
state: {
// true/'valid', false/'invalid', '',null
type: [Boolean, String],
// The order must be String first, then Boolean!
type: [String, Boolean],
default: null
}
},
computed: {
computedState () {
const state = this.state
if (state === true || state === 'valid') {
if (state === '') {
return null
} else if (state === true || state === 'valid') {
return true
} else if (state === false || state === 'invalid') {
return false
Expand Down