Skip to content

Commit

Permalink
feat(UncontrolledDropdown): add onToggle callback (#1705)
Browse files Browse the repository at this point in the history
Add `onToggle` to `UncontrolledDropdown`. The purpose of this new prop is to allow the user to be informed when the dropdown is toggled (opened/closed) as well as the new state of `isOpen` while still being uncontrolled.
when the dropdown is toggled, `onToggle` is called with the `event` and a `boolean` representing the new state (`true` mean the dropdown is being opened, `false` means it is being closed).
  • Loading branch information
TheSharpieOne committed Dec 3, 2019
1 parent 1fb3c17 commit d9cae30
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/UncontrolledDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ export default class UncontrolledDropdown extends Component {
this.toggle = this.toggle.bind(this);
}

toggle() {
toggle(e) {
this.setState({ isOpen: !this.state.isOpen });
if (this.props.onToggle) {
this.props.onToggle(e, !this.state.isOpen);
}
}

render() {
Expand All @@ -24,5 +27,6 @@ export default class UncontrolledDropdown extends Component {

UncontrolledDropdown.propTypes = {
defaultOpen: PropTypes.bool,
onToggle: PropTypes.func,
...Dropdown.propTypes
};

0 comments on commit d9cae30

Please sign in to comment.