Skip to content

Commit

Permalink
Fix #2306 - Dropdown with filter bug selecting with arrow keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mcandu committed Sep 21, 2021
1 parent 606e9ff commit be8b757
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/components/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,21 +578,25 @@ export class Dropdown extends Component {

getSelectedOption() {
let index = this.getSelectedOptionIndex();
return index !== -1 ? (this.props.optionGroupLabel ? this.getOptionGroupChildren(this.props.options[index.group])[index.option] : this.props.options[index]) : null;
let visibleOptions = this.getVisibleOptions()

return index !== -1 ? (this.props.optionGroupLabel ? this.getOptionGroupChildren(visibleOptions[index.group])[index.option] : visibleOptions[index]) : null;
}

getSelectedOptionIndex() {
if (this.props.value != null && this.props.options) {
let visibleOptions = this.getVisibleOptions()

if (this.props.value != null && visibleOptions) {
if (this.props.optionGroupLabel) {
for (let i = 0; i < this.props.options.length; i++) {
let selectedOptionIndex = this.findOptionIndexInList(this.props.value, this.getOptionGroupChildren(this.props.options[i]));
for (let i = 0; i < visibleOptions.length; i++) {
let selectedOptionIndex = this.findOptionIndexInList(this.props.value, this.getOptionGroupChildren(visibleOptions[i]));
if (selectedOptionIndex !== -1) {
return { group: i, option: selectedOptionIndex };
}
}
}
else {
return this.findOptionIndexInList(this.props.value, this.props.options);
return this.findOptionIndexInList(this.props.value, visibleOptions);
}
}

Expand Down

0 comments on commit be8b757

Please sign in to comment.