Skip to content

Commit

Permalink
fix(Collapse): add aria-expanded attribute (#1657)
Browse files Browse the repository at this point in the history
  • Loading branch information
nylon22 authored and TheSharpieOne committed Oct 11, 2019
1 parent 32f0c0d commit 2fdf15a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Collapse.js
Expand Up @@ -127,6 +127,7 @@ class Collapse extends Component {
style={{ ...childProps.style, ...style }}
className={classes}
ref={this.props.innerRef}
aria-expanded={isOpen ? 'true' : 'false'}
>
{children}
</Tag>
Expand Down
8 changes: 8 additions & 0 deletions src/__tests__/Collapse.spec.js
Expand Up @@ -122,4 +122,12 @@ describe('Collapse', () => {
expect(wrapper.state('height')).toBe(null);
wrapper.unmount();
});

it('should set aria-expanded', () => {
isOpen = false;
wrapper = mount(<Collapse isOpen={isOpen} />);
expect(wrapper.find('div').prop('aria-expanded')).toBe('false');
toggle();
expect(wrapper.find('div').prop('aria-expanded')).toBe('true');
});
});
10 changes: 10 additions & 0 deletions src/__tests__/UncontrolledCollapse.spec.js
Expand Up @@ -95,4 +95,14 @@ describe('UncontrolledCollapse', () => {

expect(UncontrolledCollapse.prototype.toggle.mock.calls.length).toBe(1);
});

it('should set aria-expanded', () => {
const collapse = mount(<UncontrolledCollapse toggler="#toggler">Yo!</UncontrolledCollapse>);

expect(collapse.find('div').prop('aria-expanded')).toBe('false');
toggler.click();
collapse.update();

expect(collapse.find('div').prop('aria-expanded')).toBe('true');
});
});

0 comments on commit 2fdf15a

Please sign in to comment.