-
Notifications
You must be signed in to change notification settings - Fork 472
Add "/" and "f" keyboard shortcuts to focus the panel filter box #6025
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
Open
fqueze
wants to merge
1
commit into
firefox-devtools:main
Choose a base branch
from
fqueze:filter-keyboard-shortcut
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| import { fireEvent, screen } from '@testing-library/react'; | ||
|
|
||
| import { render } from 'firefox-profiler/test/fixtures/testing-library'; | ||
| import { PanelSearch } from 'firefox-profiler/components/shared/PanelSearch'; | ||
| import { fireFullKeyPress } from 'firefox-profiler/test/fixtures/utils'; | ||
| import { coerce } from 'firefox-profiler/utils/types'; | ||
|
|
||
| describe('shared/PanelSearch', function () { | ||
| function setup({ alsoFocusOnF = false }: { alsoFocusOnF?: boolean } = {}) { | ||
| const onSearch = jest.fn(); | ||
| const renderResult = render( | ||
| <PanelSearch | ||
| className="testPanelSearch" | ||
| label="Filter:" | ||
| title="Filter description" | ||
| currentSearchString="" | ||
| onSearch={onSearch} | ||
| alsoFocusOnF={alsoFocusOnF} | ||
| /> | ||
| ); | ||
| return { ...renderResult, onSearch }; | ||
| } | ||
|
|
||
| function getSearchInput(): HTMLInputElement { | ||
| return screen.getByRole('searchbox') as HTMLInputElement; | ||
| } | ||
|
|
||
| it('focuses the search input when the / key is pressed outside any input', () => { | ||
| setup(); | ||
| const input = getSearchInput(); | ||
| expect(input).not.toHaveFocus(); | ||
|
|
||
| fireFullKeyPress(coerce<Window, HTMLElement>(window), { key: '/' }); | ||
|
|
||
| expect(input).toHaveFocus(); | ||
| }); | ||
|
|
||
| it('does not steal the / key when focus is already inside an input', () => { | ||
| setup(); | ||
| const input = getSearchInput(); | ||
|
|
||
| // Add a separate input that will hold focus. | ||
| const otherInput = document.createElement('input'); | ||
| otherInput.type = 'text'; | ||
| document.body.appendChild(otherInput); | ||
| otherInput.focus(); | ||
| expect(otherInput).toHaveFocus(); | ||
|
|
||
| // Fire the keydown event from the focused input. The listener should | ||
| // bail out and leave focus where it was. | ||
| fireEvent.keyDown(otherInput, { key: '/' }); | ||
|
|
||
| expect(otherInput).toHaveFocus(); | ||
| expect(input).not.toHaveFocus(); | ||
|
|
||
| document.body.removeChild(otherInput); | ||
| }); | ||
|
|
||
| it('does not react to / combined with a modifier key', () => { | ||
| setup(); | ||
| const input = getSearchInput(); | ||
| expect(input).not.toHaveFocus(); | ||
|
|
||
| fireEvent.keyDown(window, { key: '/', ctrlKey: true }); | ||
| expect(input).not.toHaveFocus(); | ||
|
|
||
| fireEvent.keyDown(window, { key: '/', metaKey: true }); | ||
| expect(input).not.toHaveFocus(); | ||
|
|
||
| fireEvent.keyDown(window, { key: '/', altKey: true }); | ||
| expect(input).not.toHaveFocus(); | ||
| }); | ||
|
|
||
| it('focuses the search input when the f key is pressed and alsoFocusOnF is true', () => { | ||
| setup({ alsoFocusOnF: true }); | ||
| const input = getSearchInput(); | ||
| expect(input).not.toHaveFocus(); | ||
|
|
||
| fireFullKeyPress(coerce<Window, HTMLElement>(window), { key: 'f' }); | ||
|
|
||
| expect(input).toHaveFocus(); | ||
| }); | ||
|
|
||
| it('does not focus the search input on the f key when alsoFocusOnF is not set', () => { | ||
| setup(); | ||
| const input = getSearchInput(); | ||
| expect(input).not.toHaveFocus(); | ||
|
|
||
| fireFullKeyPress(coerce<Window, HTMLElement>(window), { key: 'f' }); | ||
|
|
||
| expect(input).not.toHaveFocus(); | ||
| }); | ||
|
|
||
| it('still uses / for focus even when alsoFocusOnF is true', () => { | ||
| setup({ alsoFocusOnF: true }); | ||
| const input = getSearchInput(); | ||
| expect(input).not.toHaveFocus(); | ||
|
|
||
| fireFullKeyPress(coerce<Window, HTMLElement>(window), { key: '/' }); | ||
|
|
||
| expect(input).toHaveFocus(); | ||
| }); | ||
|
|
||
| it('removes its global key listener on unmount', () => { | ||
| const { unmount } = setup(); | ||
| const input = getSearchInput(); | ||
| unmount(); | ||
|
|
||
| // After unmount, pressing / should be a no-op (no focus jump back). | ||
| fireFullKeyPress(coerce<Window, HTMLElement>(window), { key: '/' }); | ||
| expect(input).not.toHaveFocus(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires a new string ID.
https://mozilla-l10n.github.io/documentation/localization/making_string_changes.html
In general, shortcuts are exposed as a separate string, so they can be localized where necessary. Does
/work across locales? For example, that's only available with SHIFT on an Italian layout.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's meant to be the same key as the '/' that starts the type ahead feature of Firefox, so we filter markers instead of having an unusable find feature. The '/' is hardcoded at https://searchfox.org/firefox-main/rev/e374045fac6f19383a04d087d2930ced5c1551fe/toolkit/content/widgets/findbar.js#876 in Firefox, so no need to localize it on the profiler side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it actually enabling the feature in the browser, or just a similar feature? What about other browsers?
We should still add a comment, e.g.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not enabling the feature in the browser, but actually the opposite: the web page consuming the event prevents the browser feature from being triggered. I haven't tested other browsers, but gmail has a similar behavior: typing '/' focuses the filter box.