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

Change contentHiddenWhenClosed to set the css visibility instead of the html hidden property #195

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,28 @@ describe('<Collapsible />', () => {
expect(wrapper.props().open).toBe(false);
});
});

describe('contentHiddenWhenClosed prop', () => {
it('does not hide the content when open', () => {
const wrapper = mount(
<Collapsible trigger="Hello World" open={true} contentHiddenWhenClosed>
<input/>
</Collapsible>
);
const inputElement = wrapper.find('input').getDOMNode();
const styles = getComputedStyle(inputElement);
expect(styles.visibility).not.toEqual('hidden');
});

it('hides the content when closed', () => {
const wrapper = mount(
<Collapsible trigger="Hello World" open={false} contentHiddenWhenClosed>
<input/>
</Collapsible>
);
const inputElement = wrapper.find('input').getDOMNode();
const styles = getComputedStyle(inputElement);
expect(styles.visibility).toEqual('hidden');
});
});
});
8 changes: 3 additions & 5 deletions src/Collapsible.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ class Collapsible extends Component {
transition: this.state.transition,
overflow: this.state.overflow,
};
if (this.props.contentHiddenWhenClosed && this.state.isClosed && !this.state.inTransition) {
dropdownStyle.visibility = 'hidden';
}

var openClass = this.state.isClosed ? 'is-closed' : 'is-open';
var disabledClass = this.props.triggerDisabled ? 'is-disabled' : '';
Expand Down Expand Up @@ -253,11 +256,6 @@ class Collapsible extends Component {
style={dropdownStyle}
onTransitionEnd={this.handleTransitionEnd}
ref={this.setInnerRef}
hidden={
this.props.contentHiddenWhenClosed &&
this.state.isClosed &&
!this.state.inTransition
}
>
<div className={innerClassString.trim()}>{children}</div>
</div>
Expand Down