Skip to content

Commit

Permalink
fix(List): fix Home & End keys handle (#1491)
Browse files Browse the repository at this point in the history
  • Loading branch information
korvin89 authored Apr 7, 2024
1 parent 76409f4 commit 77156ff
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/components/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ export class List<T = unknown> extends React.Component<ListProps<T>, ListState<T
return;
}

const isInputTarget = event.target instanceof HTMLInputElement;

switch (event.key) {
case 'ArrowDown': {
this.handleKeyMove(event, 1, -1);
Expand All @@ -221,10 +223,22 @@ export class List<T = unknown> extends React.Component<ListProps<T>, ListState<T
break;
}
case 'Home': {
// https://www.w3.org/WAI/ARIA/apg/patterns/combobox/
// ... if the combobox is editable, returns focus to the combobox and places the cursor on the first character (c)
if (isInputTarget) {
return;
}

this.handleKeyMove(event, this.state.items.length - (activeItem || 0));
break;
}
case 'End': {
// https://www.w3.org/WAI/ARIA/apg/patterns/combobox/
// ... if the combobox is editable, returns focus to the combobox and places the cursor after the last character (c)
if (isInputTarget) {
return;
}

this.handleKeyMove(event, -(activeItem || 0) - 1);
break;
}
Expand Down

0 comments on commit 77156ff

Please sign in to comment.