Skip to content
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

add aria-expanded attribute to Collapse and UncontrolledCollapse #1627 #1656

Closed
wants to merge 7 commits into from
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
2 changes: 1 addition & 1 deletion src/UncontrolledCollapse.js
Expand Up @@ -49,7 +49,7 @@ class UncontrolledCollapse extends Component {
}

render() {
return <Collapse isOpen={this.state.isOpen} {...omit(this.props, omitKeys)} />;
return <Collapse isOpen={this.state.isOpen} {...omit(this.props, omitKeys)} aria-expanded={this.state.isOpen ? 'true' : 'false'} />;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this cascade down to the Collapse which would use the value of it's isOpen prop similarly to add this?

}
}

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 = shallow(<UncontrolledCollapse toggler="#toggler">Yo!</UncontrolledCollapse>);

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

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