Skip to content

Commit

Permalink
fix: #416 press up or down will throw error when list only has disabl…
Browse files Browse the repository at this point in the history
…ed choice
  • Loading branch information
xulingling0 committed Jan 4, 2023
1 parent 36785f3 commit eef66b6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/types/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class ArrayPrompt extends Prompt {
return this.scrollUp();
}
this.index = ((idx - 1 % len) + len) % len;
if (this.isDisabled()) {
if (this.isDisabled() && !this.isAllChoicesDisabled()) {
return this.up();
}
return this.render();
Expand All @@ -395,7 +395,7 @@ class ArrayPrompt extends Prompt {
return this.scrollDown();
}
this.index = (idx + 1) % len;
if (this.isDisabled()) {
if (this.isDisabled() && !this.isAllChoicesDisabled()) {
return this.down();
}
return this.render();
Expand Down Expand Up @@ -467,6 +467,10 @@ class ArrayPrompt extends Prompt {
swap(this.choices, this.index, pos);
}

isAllChoicesDisabled(choice = this.choices){
return !choice.some(ch => !this.isDisabled(ch))
}

isDisabled(choice = this.focused) {
let keys = ['disabled', 'collapsed', 'hidden', 'completing', 'readonly'];
if (choice && keys.some(key => choice[key] === true)) {
Expand Down

0 comments on commit eef66b6

Please sign in to comment.