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 tab trap in menubar #373

Merged
merged 4 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 8 additions & 3 deletions packages/widgets/src/menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,18 @@ export class MenuBar extends Widget {
* Handle the `'keydown'` event for the menu bar.
gabalafou marked this conversation as resolved.
Show resolved Hide resolved
*/
private _evtKeyDown(event: KeyboardEvent): void {
// Fetch the key code for the event.
let kc = event.keyCode;

// Do not trap the tab key.
if (kc === 9) {
return;
}

// A menu bar handles all keydown events.
gabalafou marked this conversation as resolved.
Show resolved Hide resolved
event.preventDefault();
event.stopPropagation();

// Fetch the key code for the event.
let kc = event.keyCode;

// Enter, Up Arrow, Down Arrow
if (kc === 13 || kc === 38 || kc === 40) {
this.openActiveMenu();
Expand Down
6 changes: 6 additions & 0 deletions packages/widgets/tests/src/menubar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,12 @@ describe('@lumino/widgets', () => {
});

context('keydown', () => {
it('should bail on Tab', () => {
let event = new KeyboardEvent('keydown', { keyCode: 9 });
bar.node.dispatchEvent(event);
expect(event.defaultPrevented).to.equal(false);
});

it('should open the active menu on Enter', () => {
let menu = bar.activeMenu!;
bar.node.dispatchEvent(
Expand Down