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

[terra-form-select] Fix exception when no options exist. #4079

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading