Skip to content
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
19 changes: 9 additions & 10 deletions src/components/Dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import DropdownContent from './dropdown-content.js';
class Dropdown extends Component {
displayName: 'Dropdown'

componentDidMount () {
componentDidMount() {
window.addEventListener('click', this._onWindowClick);
window.addEventListener('touchstart', this._onWindowClick);
}

componentWillUnmount () {
componentWillUnmount() {
window.removeEventListener('click', this._onWindowClick);
window.removeEventListener('touchstart', this._onWindowClick);
}

constructor (props) {
constructor(props) {
super(props);

this.state = {
Expand All @@ -30,13 +30,13 @@ class Dropdown extends Component {
this._onToggleClick = this._onToggleClick.bind(this);
}

isActive () {
isActive() {
return (typeof this.props.active === 'boolean') ?
this.props.active :
this.state.active;
}

hide () {
hide() {
this.setState({
active: false
}, () => {
Expand All @@ -46,7 +46,7 @@ class Dropdown extends Component {
});
}

show () {
show() {
this.setState({
active: true
}, () => {
Expand All @@ -56,14 +56,14 @@ class Dropdown extends Component {
});
}

_onWindowClick (event) {
_onWindowClick(event) {
const dropdownElement = findDOMNode(this);
if (event.target !== dropdownElement && !dropdownElement.contains(event.target) && this.isActive()) {
this.hide();
}
}

_onToggleClick (event) {
_onToggleClick(event) {
event.preventDefault();
if (this.isActive()) {
this.hide();
Expand All @@ -72,7 +72,7 @@ class Dropdown extends Component {
}
}

render () {
render() {
const { children, className, disabled, removeElement } = this.props;
// create component classes
const active = this.isActive();
Expand All @@ -86,7 +86,6 @@ class Dropdown extends Component {
if (child.type === DropdownTrigger) {
const originalOnClick = child.props.onClick;
child = cloneElement(child, {
ref: 'trigger',
onClick: (event) => {
if (!disabled) {
this._onToggleClick(event);
Expand Down
10 changes: 5 additions & 5 deletions src/docs/components/account-dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import PropTypes from 'prop-types';
import Dropdown, { DropdownTrigger, DropdownContent } from '../../../lib/components/dropdown.js';

class AccountDropdown extends Component {
constructor (props) {
constructor(props) {
super(props);

this.handleLinkClick = this.handleLinkClick.bind(this);
}

handleLinkClick () {
this.refs.dropdown.hide();
handleLinkClick() {
this.dropdownRef.hide();
}

render () {
render() {
const { user } = this.props;

return (
<Dropdown className="account-dropdown" ref="dropdown">
<Dropdown className="account-dropdown" ref={ref => (this.dropdownRef = ref)}>
<DropdownTrigger>
<img className="account-dropdown__avatar" src={user.avatar_url} /><span className="account-dropdown__name">My Account</span>
</DropdownTrigger>
Expand Down