-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dmirano/4551 ffp screen reader bug (#4640)
* updated ChoiceList component * choiceList test * unit test for new ChoiceList componenet * updated imports * added choiceList story
- Loading branch information
1 parent
fd80377
commit 734a081
Showing
13 changed files
with
476 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ChoiceList } from '@cmsgov/design-system'; | ||
import React, { useEffect, useRef } from 'react'; | ||
|
||
const ChoiceListComponent = props => { | ||
const ref = useRef(null); | ||
|
||
useEffect(() => { | ||
const ariaRegions = ref.current.querySelectorAll('[aria-live]'); | ||
|
||
ariaRegions.forEach(region => { | ||
region.removeAttribute('aria-live'); | ||
region.removeAttribute('aria-relevant'); | ||
region.removeAttribute('aria-atomic'); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<div ref={ref}> | ||
<ChoiceList {...props} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ChoiceListComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import ChoiceList from './ChoiceList'; | ||
|
||
export default { | ||
title: 'Components/ChoiceList', | ||
component: ChoiceList, | ||
includeStories: /.*Story$/, | ||
parameters: { | ||
jest: ['ChoiceList.test.js'], | ||
controls: { | ||
include: ['size'], | ||
hideNoControlsWarning: true | ||
} | ||
}, | ||
argTypes: { | ||
size: { control: 'select', options: ['small', 'medium'] } | ||
} | ||
}; | ||
|
||
const Template = args => <ChoiceList {...args} />; | ||
|
||
export const CheckboxStory = Template.bind({}); | ||
CheckboxStory.args = { | ||
type: 'checkbox', | ||
choices: [ | ||
{ | ||
label: 'firstChoice', | ||
value: 'first', | ||
checked: false | ||
}, | ||
{ | ||
label: 'secondChoice', | ||
value: 'second', | ||
checked: false | ||
} | ||
], | ||
name: 'checkboxList-name', | ||
label: 'ChoiceList', | ||
size: 'medium' | ||
}; | ||
|
||
export const RadioStory = Template.bind({}); | ||
RadioStory.args = { | ||
type: 'radio', | ||
choices: [ | ||
{ | ||
label: 'firstChoice', | ||
value: 'first', | ||
checked: true | ||
}, | ||
{ | ||
label: 'secondChoice', | ||
value: 'second', | ||
checked: false | ||
} | ||
], | ||
name: 'radioList-name', | ||
label: 'ChoiceList', | ||
size: 'medium' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import { mount, shallow } from 'enzyme'; | ||
import React from 'react'; | ||
|
||
import ChoiceList from './ChoiceList'; | ||
|
||
const checkedChildren = ( | ||
<div className="ds-c-choiceList__checkedChild"> | ||
<ChoiceList | ||
label="checkedChlildrenChoiceList" | ||
choices={[ | ||
{ | ||
label: 'firstChild', | ||
value: 'firstChild', | ||
checked: true | ||
}, | ||
{ | ||
label: 'secondChild', | ||
value: 'secondChild', | ||
checked: false | ||
} | ||
]} | ||
type="radio" | ||
size="small" | ||
/> | ||
</div> | ||
); | ||
|
||
describe('ChoiceList wrapper component', () => { | ||
it('renders correctly without checkedChildren', () => { | ||
const component = shallow( | ||
<ChoiceList | ||
label="choiceList-no-children" | ||
choices={[ | ||
{ | ||
label: 'firstChoice', | ||
value: 'first', | ||
checked: false | ||
}, | ||
{ | ||
label: 'secondChoice', | ||
value: 'second', | ||
checked: false | ||
}, | ||
{ | ||
label: 'thirdChoice', | ||
value: 'third', | ||
checked: true | ||
} | ||
]} | ||
type="radio" | ||
size="small" | ||
/> | ||
); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders correctly with checkedChildren when unchecked', () => { | ||
const component = shallow( | ||
<ChoiceList | ||
label="choiceList-with-children" | ||
choices={[ | ||
{ | ||
label: 'firstChoice', | ||
value: 'first', | ||
checked: false, | ||
checkedChildren | ||
}, | ||
{ | ||
label: 'secondChoice', | ||
value: 'second', | ||
checked: false, | ||
checkedChildren | ||
}, | ||
{ | ||
label: 'thirdChoice', | ||
value: 'third', | ||
checked: false, | ||
checkedChildren | ||
} | ||
]} | ||
type="radio" | ||
name="choiceList-with-children" | ||
size="small" | ||
/> | ||
); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders correctly with checkedChildren when checked', () => { | ||
const component = shallow( | ||
<ChoiceList | ||
label="choiceList-with-children" | ||
choices={[ | ||
{ | ||
label: 'firstChoice', | ||
value: 'first', | ||
checked: true, | ||
checkedChildren | ||
}, | ||
{ | ||
label: 'secondChoice', | ||
value: 'second', | ||
checked: false, | ||
checkedChildren | ||
}, | ||
{ | ||
label: 'thirdChoice', | ||
value: 'third', | ||
checked: false, | ||
checkedChildren | ||
} | ||
]} | ||
type="radio" | ||
name="choiceList-with-children" | ||
size="small" | ||
/> | ||
); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
it('removes ARIA components from checkedChildren', () => { | ||
const component = mount( | ||
<div className="ds-c-choiceList"> | ||
<ChoiceList | ||
label="choiceList-no-children" | ||
choices={[ | ||
{ | ||
label: 'firstChoice', | ||
value: 'first', | ||
checked: false | ||
}, | ||
{ | ||
label: 'secondChoice', | ||
value: 'second', | ||
checked: false | ||
}, | ||
{ | ||
label: 'thirdChoice', | ||
value: 'third', | ||
checked: true | ||
} | ||
]} | ||
type="radio" | ||
size="small" | ||
/> | ||
</div> | ||
); | ||
|
||
// eslint-disable-next-line testing-library/render-result-naming-convention | ||
const child = component.find('.ds-c-choiceList').render(); | ||
expect(child[0].attribs['aria-live']).toBeFalsy(); | ||
expect(child[0].attribs['aria-relevant']).toBeFalsy(); | ||
expect(child[0].attribs['aria-atomic']).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.