Skip to content

Commit

Permalink
combobox: add home/end navigation (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaance committed Feb 17, 2020
1 parent 0134a4a commit 6a78bbb
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/combobox/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,38 @@ function useKeyDown() {
}
break;
}
case "Home": {
// Don't scroll the page
event.preventDefault();

if (!options || options.length === 0) {
return;
}

if (state === IDLE) {
transition(NAVIGATE);
} else {
const firstOption = options[0].value;
transition(NAVIGATE, { value: firstOption });
}
break;
}
case "End": {
// Don't scroll the page
event.preventDefault();

if (!options || options.length === 0) {
return;
}

if (state === IDLE) {
transition(NAVIGATE);
} else {
const lastOption = options[options.length - 1].value;
transition(NAVIGATE, { value: lastOption });
}
break;
}
case "Escape": {
if (state !== IDLE) {
transition(ESCAPE);
Expand Down

0 comments on commit 6a78bbb

Please sign in to comment.