diff --git a/addon/components/select-box/index.gjs b/addon/components/select-box/index.gjs index afe82492..8b59f3fe 100644 --- a/addon/components/select-box/index.gjs +++ b/addon/components/select-box/index.gjs @@ -144,15 +144,27 @@ export default class SelectBox extends Component { } get activeOptionIndex() { - return this.activeOption ? this.activeOption.index : -1; + return this.activeOption ? this.activeOption.index : null; } get previousOption() { - return this.options[this.activeOptionIndex - 1]; + let index = this.activeOptionIndex; + + if (index === null) { + index = this.options.length; + } + + return this.options[index - 1]; } get nextOption() { - return this.options[this.activeOptionIndex + 1]; + let index = this.activeOptionIndex; + + if (index === null) { + index = -1; + } + + return this.options[index + 1]; } get optionElements() { diff --git a/tests/integration/components/select-box/index/key-arrow-up-test.gjs b/tests/integration/components/select-box/index/key-arrow-up-test.gjs index abb89b08..28738894 100644 --- a/tests/integration/components/select-box/index/key-arrow-up-test.gjs +++ b/tests/integration/components/select-box/index/key-arrow-up-test.gjs @@ -33,18 +33,16 @@ module('select-box (up arrow key)', function (hooks) { assert.dom('.select-box__option[aria-current="true"]').doesNotExist(); - await triggerEvent('.select-box__option:nth-child(3)', 'mouseenter'); - await triggerKeyEvent('.select-box__options', 'keydown', 'ArrowUp'); assert - .dom('.select-box__option:nth-child(2)') + .dom('.select-box__option:nth-child(3)') .hasAttribute('aria-current', 'true'); await triggerKeyEvent('.select-box__options', 'keydown', 'ArrowUp'); assert - .dom('.select-box__option:nth-child(1)') + .dom('.select-box__option:nth-child(2)') .hasAttribute('aria-current', 'true'); await triggerKeyEvent('.select-box__options', 'keydown', 'ArrowUp');