fix(overflow-menu): keyboard navigation should skip disabled items (#1096)

This commit is contained in:
metonym 2022-02-12 15:43:45 -08:00 committed by GitHub
commit c7de897b89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View file

@ -80,20 +80,19 @@
setContext("OverflowMenu", {
focusedId,
add: ({ id, text, primaryFocus }) => {
add: ({ id, text, primaryFocus, disabled }) => {
items.update((_) => {
if (primaryFocus) {
currentIndex.set(_.length);
}
return [..._, { id, text, primaryFocus, index: _.length }];
return [..._, { id, text, primaryFocus, disabled, index: _.length }];
});
},
update: (id) => {
currentId.set(id);
},
change: (direction) => {
// TODO: skip disabled
let index = $currentIndex + direction;
if (index < 0) {
@ -102,6 +101,20 @@
index = 0;
}
let disabled = $items[index].disabled;
while (disabled) {
index = index + direction;
if (index < 0) {
index = $items.length - 1;
} else if (index >= $items.length) {
index = 0;
}
disabled = $items[index].disabled;
}
currentIndex.set(index);
},
});