Skip to content

feat(form-group): make aria-live attribute on feedback configurable (closes #3057) #3058

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 10 commits into from
Apr 9, 2019
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
28 changes: 13 additions & 15 deletions src/components/form-group/form-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,11 @@ const renderInvalidFeedback = (h, ctx) => {
id: ctx.invalidFeedbackId,
// If state is explicitly false, always show the feedback
state: ctx.computedState,
tooltip: ctx.tooltip
tooltip: ctx.tooltip,
ariaLive: ctx.feedbackAriaLive,
role: ctx.feedbackAriaLive ? 'alert' : null
},
attrs: {
tabindex: content ? '-1' : null,
role: 'alert',
'aria-live': 'assertive',
'aria-atomic': 'true'
}
attrs: { tabindex: content ? '-1' : null }
},
[content]
)
Expand All @@ -71,14 +68,11 @@ const renderValidFeedback = (h, ctx) => {
id: ctx.validFeedbackId,
// If state is explicitly true, always show the feedback
state: ctx.computedState,
tooltip: ctx.tooltip
tooltip: ctx.tooltip,
ariaLive: ctx.feedbackAriaLive,
role: ctx.feedbackAriaLive ? 'alert' : null
},
attrs: {
tabindex: '-1',
role: 'alert',
'aria-live': 'assertive',
'aria-atomic': 'true'
}
attrs: { tabindex: content ? '-1' : null }
},
[content]
)
Expand All @@ -96,7 +90,7 @@ const renderHelpText = (h, ctx) => {
{
attrs: {
id: ctx.descriptionId,
tabindex: '-1'
tabindex: content ? '-1' : null
}
},
[content]
Expand Down Expand Up @@ -234,6 +228,10 @@ export default (resolve, reject) => {
type: Boolean,
default: false
},
feedbackAriaLive: {
type: String,
default: 'assertive'
},
validated: {
type: Boolean,
default: false
Expand Down
55 changes: 55 additions & 0 deletions src/components/form-group/form-group.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,14 @@ describe('form-group', () => {
// With state = null (default), all helpers are rendered
expect(wrapper.find('.invalid-feedback').exists()).toBe(true)
expect(wrapper.find('.invalid-feedback').text()).toEqual('bar')
expect(wrapper.find('.invalid-feedback').attributes('role')).toEqual('alert')
expect(wrapper.find('.invalid-feedback').attributes('aria-live')).toEqual('assertive')
expect(wrapper.find('.invalid-feedback').attributes('aria-atomic')).toEqual('true')
expect(wrapper.find('.valid-feedback').exists()).toBe(true)
expect(wrapper.find('.valid-feedback').text()).toEqual('baz')
expect(wrapper.find('.valid-feedback').attributes('role')).toEqual('alert')
expect(wrapper.find('.valid-feedback').attributes('aria-live')).toEqual('assertive')
expect(wrapper.find('.valid-feedback').attributes('aria-atomic')).toEqual('true')
expect(wrapper.find('.form-text').exists()).toBe(true)
expect(wrapper.find('.form-text').text()).toEqual('foo')
expect(wrapper.attributes('aria-invalid')).not.toBeDefined()
Expand Down Expand Up @@ -294,6 +300,55 @@ describe('form-group', () => {
expect(wrapper.classes()).toContain('is-invalid')
})

it('validation elemetns respect feedback-aria-live attribute', async () => {
const wrapper = mount(BFormGroup, {
propsData: {
id: 'group-id',
label: 'test',
labelFor: 'input-id',
invalidFeedback: 'bar',
validFeedback: 'baz',
feedbackAriaLive: 'polite'
},
slots: {
default: '<input id="input-id" type="text">'
}
})

expect(wrapper.isVueInstance()).toBe(true)

// Auto ID is created after mounted
await wrapper.vm.$nextTick()

expect(wrapper.find('.invalid-feedback').exists()).toBe(true)
expect(wrapper.find('.invalid-feedback').text()).toEqual('bar')
expect(wrapper.find('.invalid-feedback').attributes('role')).toEqual('alert')
expect(wrapper.find('.invalid-feedback').attributes('aria-live')).toEqual('polite')
expect(wrapper.find('.invalid-feedback').attributes('aria-atomic')).toEqual('true')
expect(wrapper.find('.valid-feedback').exists()).toBe(true)
expect(wrapper.find('.valid-feedback').text()).toEqual('baz')
expect(wrapper.find('.valid-feedback').attributes('role')).toEqual('alert')
expect(wrapper.find('.valid-feedback').attributes('aria-live')).toEqual('polite')
expect(wrapper.find('.valid-feedback').attributes('aria-atomic')).toEqual('true')

// With feedback-aria-live set to null
wrapper.setProps({
feedbackAriaLive: null
})
await wrapper.vm.$nextTick()

expect(wrapper.find('.invalid-feedback').exists()).toBe(true)
expect(wrapper.find('.invalid-feedback').text()).toEqual('bar')
expect(wrapper.find('.invalid-feedback').attributes('role')).not.toBeDefined()
expect(wrapper.find('.invalid-feedback').attributes('aria-live')).not.toBeDefined()
expect(wrapper.find('.invalid-feedback').attributes('aria-atomic')).not.toBeDefined()
expect(wrapper.find('.valid-feedback').exists()).toBe(true)
expect(wrapper.find('.valid-feedback').text()).toEqual('baz')
expect(wrapper.find('.valid-feedback').attributes('role')).not.toBeDefined()
expect(wrapper.find('.valid-feedback').attributes('aria-live')).not.toBeDefined()
expect(wrapper.find('.valid-feedback').attributes('aria-atomic')).not.toBeDefined()
})

it('Label alignment works', async () => {
const wrapper = mount(BFormGroup, {
propsData: {
Expand Down
15 changes: 14 additions & 1 deletion src/components/form/form-invalid-feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ export const props = {
state: {
type: [Boolean, String],
default: null
},
ariaLive: {
type: String,
default: null
},
role: {
type: String,
default: null
}
}

Expand All @@ -39,7 +47,12 @@ export default Vue.extend({
'invalid-tooltip': props.tooltip,
'd-block': show
},
attrs: { id: props.id }
attrs: {
id: props.id,
role: props.role,
'aria-live': props.ariaLive,
'aria-atomic': props.ariaLive ? 'true' : null
}
}),
children
)
Expand Down
15 changes: 14 additions & 1 deletion src/components/form/form-valid-feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ export const props = {
state: {
type: [Boolean, String],
default: null
},
ariaLive: {
type: String,
default: null
},
role: {
type: String,
default: null
}
}

Expand All @@ -39,7 +47,12 @@ export default Vue.extend({
'valid-tooltip': props.tooltip,
'd-block': show
},
attrs: { id: props.id }
attrs: {
id: props.id,
role: props.role,
'aria-live': props.ariaLive,
'aria-atomic': props.ariaLive ? 'true' : null
}
}),
children
)
Expand Down