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

Add type-ahead to assign tester dropdown #1095

Merged
merged 3 commits into from
May 20, 2024
Merged
Changes from 1 commit
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
26 changes: 25 additions & 1 deletion client/components/TestQueue/AssignTesterDropdown/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,33 @@ const AssignTesterDropdown = ({
const clearAriaLiveRegion = () => {
setAlertMessage('');
};

const handleKeyDown = event => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting!

const { key } = event;
if (key.match(/[a-z]/)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (key.match(/[a-z]/)) {
if (key.match(/[0-9a-zA-Z]/)) {

While there are none currently tracked by the app, I've come to find out GitHub usernames can begin with a number, so just to be safe. Uppercase is there as well in case one is holding Shift or CapsLock is enabled. It seems to also align with browsers' native behavior for <select>

const container = event.target.closest('[role=menu]');
const matchingMenuItem = Array.from(container.children).find(
menuItem => {
return menuItem.innerText
.trim()
.toLowerCase()
.startsWith(key);
}
);

if (matchingMenuItem) {
matchingMenuItem.focus();
}
}
};

return (
<LoadingStatus message={loadingMessage}>
<Dropdown focusFirstItemOnShow aria-label="Assign testers menu">
<Dropdown
focusFirstItemOnShow
aria-label="Assign testers menu"
onKeyDown={handleKeyDown}
>
<Dropdown.Toggle
ref={dropdownAssignTesterButtonRef}
aria-label="Assign testers"
Expand Down
Loading