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

Components: Remove redundant onClickOutside handler from Dropdown #11253

Merged
merged 1 commit into from
Oct 31, 2018
Merged
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
18 changes: 4 additions & 14 deletions packages/components/src/dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import Popover from '../popover';
class Dropdown extends Component {
constructor() {
super( ...arguments );

this.toggle = this.toggle.bind( this );
this.close = this.close.bind( this );
this.clickOutside = this.clickOutside.bind( this );
this.bindContainer = this.bindContainer.bind( this );
this.refresh = this.refresh.bind( this );

this.popoverRef = createRef();

this.state = {
isOpen: false,
};
Expand All @@ -38,10 +39,6 @@ class Dropdown extends Component {
}
}

bindContainer( ref ) {
this.container = ref;
}

/**
* When contents change height due to user interaction,
* `refresh` can be called to re-render Popover with correct
Expand All @@ -59,12 +56,6 @@ class Dropdown extends Component {
} ) );
}

clickOutside( event ) {
if ( ! this.container.contains( event.target ) ) {
this.close();
}
}

close() {
this.setState( { isOpen: false } );
}
Expand All @@ -84,15 +75,14 @@ class Dropdown extends Component {
const args = { isOpen, onToggle: this.toggle, onClose: this.close };

return (
<div className={ className } ref={ this.bindContainer }>
<div className={ className }>
{ renderToggle( args ) }
{ isOpen && (
<Popover
className={ contentClassName }
ref={ this.popoverRef }
position={ position }
onClose={ this.close }
onClickOutside={ this.clickOutside }
expandOnMobile={ expandOnMobile }
headerTitle={ headerTitle }
>
Expand Down