Skip to content

Commit

Permalink
fix(Dropdown): Fix getSelectedIndexAfterMove recursion error
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchellNeedham committed Feb 10, 2024
1 parent ef8684c commit a55eed9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,11 +739,16 @@ class DropdownInner extends Component {
nextIndex = lastIndex
}

if (options[nextIndex].disabled) {
return this.getSelectedIndexAfterMove(offset, nextIndex)
if (!options[nextIndex].disabled) {
return nextIndex
}

return nextIndex
// if 'wrapSelection' is set to false, keep reference to last enabled index to avoid infinite loop
// where options has disabled items at start or end
if (!wrapSelection) {
return this.getSelectedIndexAfterMove(offset + Math.sign(offset), startIndex)

Check warning on line 749 in src/modules/Dropdown/Dropdown.js

View check run for this annotation

Codecov / codecov/patch

src/modules/Dropdown/Dropdown.js#L749

Added line #L749 was not covered by tests
}
return this.getSelectedIndexAfterMove(offset, nextIndex)
}

// ----------------------------------------
Expand Down

0 comments on commit a55eed9

Please sign in to comment.