Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
[terra-form-select] Fix exception when no options exist. (#4079)
Browse files Browse the repository at this point in the history
  • Loading branch information
cm9361 authored Apr 2, 2024
1 parent b702696 commit ab57d92
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/terra-form-select/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Fixed
* Fixed exception thrown when down arrow is pressed on a form select with no options.

## 6.60.0 - (March 27, 2024)

* Fixed
Expand Down
4 changes: 4 additions & 0 deletions packages/terra-form-select/src/shared/_MenuUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ class MenuUtil {
*/
static findNext(object, value) {
const options = MenuUtil.flatten(object, true);
if (options.length === 0) {
return null;
}

const index = options.findIndex(({ props }) => MenuUtil.isEqual(props.value, value));
if (options.length - 1 === index) {
return options[0].props.value;
Expand Down
6 changes: 6 additions & 0 deletions packages/terra-form-select/tests/jest/MenuUtil.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ describe('MenuUtil', () => {
});
});

it('should return null if there are no options', () => {
const options = [];

expect(MenuUtil.findNext(options, null)).toBeNull();
});

describe('findPrevious', () => {
it('should return the option after the value', () => {
const options = [
Expand Down

0 comments on commit ab57d92

Please sign in to comment.