Skip to content

Commit

Permalink
Fixed flow errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
visusnet committed Jul 20, 2018
1 parent 44d43ed commit e2d9fa3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Typeahead.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {Node} from 'react';
// @flow
import React, {PureComponent} from 'react';
import type {Node} from 'react';
import * as PropTypes from 'prop-types';
import scrollIntoView from 'dom-scroll-into-view';

Expand Down Expand Up @@ -299,7 +299,10 @@ export default class Typeahead extends PureComponent<Props, State> {
_sortOptionsByGroup = (options: Option[]): Option[] => {
const groups = this.props.groups;
const indexOfGroup = (groupValue: any) => groups.findIndex(group => group.value === groupValue);
if (typeof groups === 'undefined') {
return options;
}
const indexOfGroup = (groupValue: any): number => groups.findIndex(group => group.value === groupValue);
// This is necessary because Array.prototype.sort is not necessarily stable. See:
// http://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.sort
const wrappedOptions = options.map((option, index) => ({option, index}));
Expand Down Expand Up @@ -378,8 +381,8 @@ export default class Typeahead extends PureComponent<Props, State> {
_initializeFromProps = (props: Props): void => {
this._validateProps(props);
const {value, options, groups} = props;
const sortedOptions = groups === undefined ? options : this._sortOptionsByGroup(options);
const {value, options} = props;
const sortedOptions = this._sortOptionsByGroup(options);
this.setState({
options: sortedOptions,
highlightedIndex: this._getInitialIndex(props),
Expand Down

0 comments on commit e2d9fa3

Please sign in to comment.