import classNames from 'classnames'; import PropTypes from 'prop-types'; import React from 'react'; import blockEvent from './utils/blockEvent'; class Option extends React.Component { constructor(props) { super(props); this.handleMouseDown = this.handleMouseDown.bind(this); this.handleMouseEnter = this.handleMouseEnter.bind(this); this.handleMouseMove = this.handleMouseMove.bind(this); this.handleTouchStart = this.handleTouchStart.bind(this); this.handleTouchEnd = this.handleTouchEnd.bind(this); this.handleTouchMove = this.handleTouchMove.bind(this); this.onFocus = this.onFocus.bind(this); } handleMouseDown (event) { event.preventDefault(); event.stopPropagation(); this.props.onSelect(this.props.option, event); } handleMouseEnter (event) { this.onFocus(event); } handleMouseMove (event) { this.onFocus(event); } handleTouchEnd(event){ // Check if the view is being dragged, In this case // we don't want to fire the click event (because the user only wants to scroll) if(this.dragging) return; this.handleMouseDown(event); } handleTouchMove () { // Set a flag that the view is being dragged this.dragging = true; } handleTouchStart () { // Set a flag that the view is not being dragged this.dragging = false; } onFocus (event) { if (!this.props.isFocused) { this.props.onFocus(this.props.option, event); } } render () { const { option, instancePrefix, optionIndex } = this.props; const className = classNames(this.props.className, option.className); return option.disabled ? (