Skip to content

Commit

Permalink
fix up arrow
Browse files Browse the repository at this point in the history
  • Loading branch information
amk221 committed Dec 12, 2024
1 parent dea8767 commit fac91ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
18 changes: 15 additions & 3 deletions addon/components/select-box/index.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit fac91ee

Please sign in to comment.