Skip to content

Commit

Permalink
Refactored Option.js
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri-sakharov committed Dec 22, 2017
1 parent 69868a0 commit d923fb6
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/Option.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';

const blockEvent = event => {
event.preventDefault();
event.stopPropagation();
if ((event.target.tagName !== 'A') || !('href' in event.target)) {
return;
}
if (event.target.target) {
window.open(event.target.href, event.target.target);
} else {
window.location.href = event.target.href;
}
};

class Option extends React.Component {

Expand All @@ -16,20 +29,6 @@ class Option extends React.Component {
this.onFocus = this.onFocus.bind(this);
}


blockEvent (event) {
event.preventDefault();
event.stopPropagation();
if ((event.target.tagName !== 'A') || !('href' in event.target)) {
return;
}
if (event.target.target) {
window.open(event.target.href, event.target.target);
} else {
window.location.href = event.target.href;
}
}

handleMouseDown (event) {
event.preventDefault();
event.stopPropagation();
Expand All @@ -52,12 +51,12 @@ class Option extends React.Component {
this.handleMouseDown(event);
}

handleTouchMove (event) {
handleTouchMove () {
// Set a flag that the view is being dragged
this.dragging = true;
}

handleTouchStart (event) {
handleTouchStart () {
// Set a flag that the view is not being dragged
this.dragging = false;
}
Expand All @@ -69,13 +68,13 @@ class Option extends React.Component {
}

render () {
var { option, instancePrefix, optionIndex } = this.props;
var className = classNames(this.props.className, option.className);
const { option, instancePrefix, optionIndex } = this.props;
const className = classNames(this.props.className, option.className);

return option.disabled ? (
<div className={className}
onMouseDown={this.blockEvent}
onClick={this.blockEvent}>
onMouseDown={blockEvent}
onClick={blockEvent}>
{this.props.children}
</div>
) : (
Expand All @@ -95,7 +94,7 @@ class Option extends React.Component {
</div>
);
}
};
}

Option.propTypes = {
children: PropTypes.node,
Expand Down

0 comments on commit d923fb6

Please sign in to comment.