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

Reader context menu keyboard navigation #139

Merged
merged 3 commits into from
Oct 15, 2024

Conversation

abaevbog
Copy link
Contributor

  • add tabstop to contextMenu, so navigation between buttons within it is handled by focusManager
  • when context menu is opened, focus the first button from contextMenu so that the next keypress interacts with menu items
  • when Escape keypress is being handled and contextmenu is open, just call reader.closeContextMenu to close it and let focus go back to previously focused element.
  • add keydown listener to context-menu to navigate it by typing characters on the keyboard. After something is typed, find buttons with text that begins with the input. If there is only one match, it is clicked. If there are multiple, the first one is focused. The input counter is reset after 3 seconds of not typing.

Fixes: zotero/zotero#4681

Also, fixed an encountered glitch where clicking inside of the rendered reader content when the context menu is open would make the annotation un-selectable via tab.

Currently, getting into the menu or navigating it with keyboard is not possible. For comparison, this is the updated behavior. In the end, i type "gre" to get the "Green" option selected.

reader.context.menu.keyboard.mov

@mrtcode
Copy link
Member

mrtcode commented Oct 7, 2024

Sorry, I forgot that context menu navigation was working in the initial Reader 2.0 version. Let's see if we can add those extra features from this PR.

@abaevbog
Copy link
Contributor Author

abaevbog commented Oct 7, 2024

Yeah, I'll revise this to just keep the last bullet point from the initial description

  • add keydown listener to context-menu to navigate it by typing characters on the keyboard. After something is typed, find buttons with text that begins with the input. If there is only one match, it is clicked. If there are multiple, the first one is focused. The input counter is reset after 3 seconds of not typing.

As well as that glitch fix I ran into

- added keydown listener to contextmenu to select a menuitem by typing,
similar to native menus. After something is typed, find buttons with
text that begins with the input. If there is only one match, it is
clicked. If there are multiple, the first one is focused. The input
counter is reset after 2 seconds of not typing.
- listen to even candidates in focus-manager and dispatch copy of
keydown events from there to context-menu, in case one types when
the menu itself is not focused.

Also, fixed an encountered glitch where clicking inside of the rendered
reader content when the context menu is open would make the
annotation un-selectable via tab.
@abaevbog abaevbog force-pushed the context_menu_keyboard_nav branch from 4bdec1d to 3eb0441 Compare October 9, 2024 17:38
@abaevbog
Copy link
Contributor Author

abaevbog commented Oct 9, 2024

I just revised this to only keep the menuitem selection by typing.

Comment on lines 160 to 163
// If there is only one candidate, click it right away
if (candidates.length == 1) {
candidates[0].click();
}
Copy link
Member

Choose a reason for hiding this comment

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

But where is this concept from? It feels pretty unexpected that pressing a letter immediately activates an action.

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 thought it would be nice to skip an extra click or keypress if this is the only matching option. But you're right, the native menu does not do that, so it's probably best to stick to just focusing the menu item.

Comment on lines 178 to 182
function handlePointerDown(event) {
// Clicking on the rendered content when a contextmenu is open will
// lead to pointerup event not firing and the annotation becoming not-selectable
// via keyboard until it is clicked.
if (event.target.classList.contains("context-menu-overlay")) return;
Copy link
Member

Choose a reason for hiding this comment

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

I'm trying to reproduce the mentioned issue. Could you help me with the steps to reproduce it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it actually is a bit harder to reproduce now than before. The recent fix to context menu focus regression must have helped.

I did get to reproduce it with an unloaded reader tab. After it loads, click on the annotation ... to open the context menu, then click on the rendered PDF content, and try to navigate to the sidebar with tab. It gets skipped for me. Clicking around resolves the issue, and on subsequent attempts, it doesn't seem to happen again.

Screen.Recording.2024-10-10.at.12.27.36.PM.mov

Copy link
Member

Choose a reason for hiding this comment

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

It should be fixed in 97dd5ab. Thanks for helping to reproduce it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's fixed now. That was definitely a less-roundabout way to do it!

I removed this changed from here.

@abaevbog
Copy link
Contributor Author

Oh, on a separate note, I just noticed that when a context-menu is opened, subsequent Escape keypress not only closes the contextmenu but also re-focuses the rendered content iframe. We probably want to treat Escape as a special case here so it only closes the contextmenu and refocuses the context-menu button?

@mrtcode
Copy link
Member

mrtcode commented Oct 11, 2024

Oh, on a separate note, I just noticed that when a context-menu is opened, subsequent Escape keypress not only closes the contextmenu but also re-focuses the rendered content iframe. We probably want to treat Escape as a special case here so it only closes the contextmenu and refocuses the context-menu button?

We can create a separate issue for that.

@mrtcode
Copy link
Member

mrtcode commented Oct 14, 2024

Ok, looks good. We can merge.

@dstillman dstillman merged commit 34c1294 into zotero:master Oct 15, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Reader: Annotations colors aren't accessible via keyboard
3 participants