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

Conversation

gabalafou
Copy link
Contributor

There are a few tab traps in the JupyterLab UI. The worst offender is the top menu bar. The code change in this pull request is the most straightforward way to fix the menu bar tab trap in JupyterLab.

In terms of backwards compatibility, I have a hard time imagining that downstream dependents on Lumino would rely on the tab key event getting caught and swallowed (event.preventDefault + event.stopPropagation) by the Lumino menu bar, but it is something to consider.

@gabalafou
Copy link
Contributor Author

Note that this PR does not fix all of the tab traps in JupyterLab. There are others, these two in particular:

  • when a notebook is open, code cells become tab traps (technically, you can ESC-key out of the code cell and tab backwards through the UI, but I couldn't figure out a way to go forward past the code cell)
  • opening the command-line terminal also creates a tab trap unless you know to press CTRL + D

@gabalafou
Copy link
Contributor Author

Testing

Testing this change against the JupyterLab UI is a little bit tricky right now.

When I tried to link @lumino/widgets, I got errors when trying to do a dev build of the JupyterLab frontend code. I think that's because the JupyterLab frontend code has not yet been updated to be compatible with the latest Lumino code.

So I had to cherry pick the commit from this PR onto a branch based on the Lumino 1.x branch, and then do the linking.

In terms of the command line, it looks like the following.

First, with the Lumino repo as your current working directory:

git checkout -b no-tab-traps 1.x
git cherry-pick 911f4b067f27d88be3d9707e33ad4eac746009b7
yarn 
yarn build
cd packages/widgets
yarn link

Then, with the JupyterLab repo as current working directory (and assuming you have already pulled latest changes and installed everything):

jlpm link @lumino/widgets
jlpm build
jupyter lab --dev-mode

@gabalafou gabalafou added the accessibility Addresses accessibility needs label Aug 23, 2022
Copy link
Member

@fcollonval fcollonval left a comment

Choose a reason for hiding this comment

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

Just adding more information in the code comments. Otherwise it looks good to me.

packages/widgets/src/menubar.ts Show resolved Hide resolved
packages/widgets/src/menubar.ts Outdated Show resolved Hide resolved
@fcollonval
Copy link
Member

Note that this PR does not fix all of the tab traps in JupyterLab. There are others, these two in particular:

* when a notebook is open, code cells become tab traps (technically, you can `ESC`-key out of the code cell and tab backwards through the UI, but I couldn't figure out a way to go forward past the code cell)

* opening the command-line terminal also creates a tab trap unless you know to press `CTRL` + `D`

Those are gonna be tricky as tab is meaningful for code editors and terminals. It may be interesting to see how vscode in its web version (aka vscode.dev or github.dev) deal with that.

just tested - terminals are not available on the online version (no server to back it up) and editor are also a tab trap.

Maybe there is an issue on JupyterLab to track this.

Co-authored-by: Frédéric Collonval <[email protected]>
@fcollonval fcollonval added the enhancement New feature or request label Aug 23, 2022
@fcollonval fcollonval added this to the Lumino 2 milestone Aug 23, 2022
Copy link
Member

@fcollonval fcollonval left a comment

Choose a reason for hiding this comment

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

Thanks @gabalafou

return;
}

// A menu bar handles all other keydown events.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder if the logic here is sound.

Originally this handler only called preventDefault and stopPropagation if it actually handled the key. But then the handler was rewritten to handle mnemonics. I lightly suspect that the decision to call prevent and stop on all keys was done to make the handler more readable, without too much thought given to possible negative consequences.

I wrote this PR conservatively, meaning I kept everything else about this function the same EXCEPT when the tab key is pressed. But I guess it's worth asking whether the handler should be refactored to only intercept key events that it actually does something with.

I could imagine a handler that looks more like the following:

keyDown() {
  let kc = event.keyCode;
  let endEvent = () => { 
    event.preventDefault();
    event.stopPropagation();
  };
  // Enter, Up Arrow, Down Arrow
  if (kc === 13 || kc === 38 || kc === 40) {
    endEvent();
    this.openActiveMenu();
    return;
  }
  // ...
}

In other words, it would go back to looking like the original implementation.

Copy link
Member

Choose a reason for hiding this comment

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

Let's pursue this train of thought in another PR if necessary so we can merge this one and iterate.

Copy link
Member

@afshin afshin left a comment

Choose a reason for hiding this comment

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

Thank you!

@fcollonval
Copy link
Member

@meeseeksdev please backport to 1.x

meeseeksmachine pushed a commit to meeseeksmachine/lumino that referenced this pull request Oct 11, 2022
fcollonval added a commit that referenced this pull request Oct 12, 2022
* Backport PR #373: Fix tab trap in menubar

* Use key instead of keyCode

* Point to stable doc on 1.x branch

Co-authored-by: Afshin Taylor Darian <[email protected]>
Co-authored-by: Frédéric Collonval <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accessibility Addresses accessibility needs enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants