Skip to content

Commit

Permalink
Fixed #1358 - Dropdown throws an exception on console after filtering…
Browse files Browse the repository at this point in the history
… and keyboard navigation
  • Loading branch information
mertsincan committed May 4, 2020
1 parent 6b579df commit 9799c09
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/components/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ export class Dropdown extends Component {
return null;
}

filter(options) {
let filterValue = this.state.filter.trim().toLocaleLowerCase(this.props.filterLocale);
let searchFields = this.props.filterBy ? this.props.filterBy.split(',') : [this.props.optionLabel || 'label'];
let items = FilterUtils.filter(options, searchFields, filterValue, this.props.filterMatchMode, this.props.filterLocale);

return (items && items.length) ? items : null;
}

findNextVisibleItem(index) {
let i = index + 1;
if (i === this.props.options.length) {
Expand All @@ -296,7 +304,7 @@ export class Dropdown extends Component {
}

if (this.hasFilter()) {
if (this.filter(option))
if (this.filter([option]))
return option;
else
return this.findNextVisibleItem(i);
Expand All @@ -319,7 +327,7 @@ export class Dropdown extends Component {
}

if (this.hasFilter()) {
if (this.filter(option))
if (this.filter([option]))
return option;
else
return this.findPrevVisibleItem(i);
Expand Down Expand Up @@ -595,12 +603,10 @@ export class Dropdown extends Component {
let items = this.props.options;

if (items && this.hasFilter()) {
let filterValue = this.state.filter.trim().toLocaleLowerCase(this.props.filterLocale);
let searchFields = this.props.filterBy ? this.props.filterBy.split(',') : [this.props.optionLabel || 'label'];
items = FilterUtils.filter(items, searchFields, filterValue, this.props.filterMatchMode, this.props.filterLocale);
items = this.filter(items);
}

if(items) {
if (items) {
return items.map((option) => {
let optionLabel = this.getOptionLabel(option);
return (
Expand Down

0 comments on commit 9799c09

Please sign in to comment.