Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(List): fix Home & End keys handle #1491

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/components/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
};

refFilter = React.createRef<HTMLInputElement>();
refContainer = React.createRef<any>();

Check warning on line 100 in src/components/List/List.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
blurTimer: ReturnType<typeof setTimeout> | null = null;
loadingItem = {value: '__LIST_ITEM_LOADING__', disabled: false} as unknown as ListItemData<
T & {value: string}
Expand Down Expand Up @@ -203,6 +203,8 @@
return;
}

const isInputTarget = event.target instanceof HTMLInputElement;

switch (event.key) {
case 'ArrowDown': {
this.handleKeyMove(event, 1, -1);
Expand All @@ -213,18 +215,30 @@
break;
}
case 'PageDown': {
this.handleKeyMove(event, pageSize!);

Check warning on line 218 in src/components/List/List.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Forbidden non-null assertion
break;
}
case 'PageUp': {
this.handleKeyMove(event, -pageSize!);

Check warning on line 222 in src/components/List/List.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Forbidden non-null assertion
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
Loading