-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Accessibility: Adding Keyboard Shorcuts to navigate the editor regions #3084
Conversation
6601c81
to
bb5048c
Compare
Totally love this! Very very nice work. Finding a good standardized shortcut for this is going to be important, especially given the backtick discussion in last weeks meeting. I like the focus style for the region — is it kosher to do something like this? https://codepen.io/joen/pen/Nvjror — that is, a big flashing focus style that disappears? I don't know if it's intentional — I assume it is, but the shortcut doesn't work if you have focus inside a text block. Nice work! |
Codecov Report
@@ Coverage Diff @@
## master #3084 +/- ##
==========================================
- Coverage 31.54% 30.86% -0.68%
==========================================
Files 221 222 +1
Lines 6311 6450 +139
Branches 1121 1158 +37
==========================================
Hits 1991 1991
- Misses 3632 3734 +102
- Partials 688 725 +37
Continue to review full report at Codecov.
|
Love to see this in action 😄 Thanks! Shortcut: yee we should find a good one. I'd love to use @jasmussen no objections to experiment the flashing focus limited to this case. I'd like to see this merged soon and ready for testing. We can always review later if necessary.
Noticed that and I understand that's maybe a bit tricky to implement. However, if the idea of the blocks "Navigation mode" and "Edit mode" discussed during last SLack chat will be implemented, then makes sense to me having these shortcuts working just in "Navigation mode". Instead, when editing and focus is inside a block, the process would be: Aside: we should document all this in a future Gutenberg help guide. |
Good call, we should start writing these sooner rather than later. They could even be extracted to be part of the "new user experience" cc @karmatosed |
editor/layout/index.js
Outdated
<div className="editor-layout__editor"> | ||
{ mode === 'text' && <TextEditor /> } | ||
{ mode === 'visual' && <VisualEditor /> } | ||
class Layout extends Component { |
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.
Looking at the previous simple component, wonder if we should convert the region-focus into a HoC that could be used in different editor layouts.
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.
Do you think this should be a generic component in the components
module? It looks like something that could be useful even outside an editor context.
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.
done in daa9cf3
Question: can we use both the standardized backtick shortcut for keyboards that support this, and a better one for us europeans? (perhaps Ctrl+$, as $ is right above tab)? The idea being that if backtick is a standard for this, good to embrace it for the majority of the world, with enhancements for the rest of us?
Cool, Riad can we try the animated focus style from that codepen I linked? Let me know if you'd like me to implement it. It uses $blue-medium-500.
Would a good start be to implement the keyboard shortcuts cheatsheet (invoked by for example Shift + ?) as ticketed in #2980 be a good start? I don't know how far we can go with the componentization thing, but it would be really nice if, when a shortcut is used, the tooltip and cheat sheet inclusion create themselves. |
editor/layout/index.js
Outdated
<Popover.Slot /> | ||
<KeyboardShortcuts shortcuts={ { | ||
'ctrl+r': this.focusNextRegion, | ||
'ctrl+shift+r': this.focusPreviousRegion, |
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.
On Windows, Ctrl+r refreshes the page, see extended comment on the PR.
Testing on Windows, we've missed that Ctrl+r refreshes the page. The default action should be prevented but... we should find a better shortcut anyways. Finding a good one that is safe to use across different browsers, platforms, and keyboard layouts is basically impossible.
Not on my Italian keyboard, maybe that's the Danish Mac keyboard 😉. I guess $ is placed differently also in other keyboard layouts. If we decide these shortcuts should be available only in "navigation mode" (i.e. not when editing a block or when inside any other form field) then I'd consider to use single key shortcuts. To my understanding, modifiers like Many big apps already use single keys shortcuts, for example Gmail uses
Maybe replicating this interaction would make sense also in Gutenberg? As in, when editing a block, press "Escape" exits edit mode and goes back to navigation mode, then the shortcuts work again. Note: it already works this way. WordPress already uses single key shortcuts for the Comments screen: https://codex.wordpress.org/Keyboard_Shortcuts#Keyboard_Shortcuts_for_Comments We don't have to worry about screen readers because they already have their mechanism to jump through landmark regions. Windows screen readers use "browse mode" and "forms mode". When in "browse mode" the Gutenberg shortcuts won't do anything because screen readers intercepts keypresses, so keypresses are not passed to the browser. This is not a problem because, for example, NVDA and JAWS already have their shortcuts: NVDA list of single key shortcuts:
JAWS list of single key shortcuts:
I'd propose to try Note: the new meta boxes expanding panel is not included in an ARIA landmark region. Please consider, also for future developments, that all content in a web page should be inside a landmark region. Yes, it's inside the WordPress "main" landmark but the point is if this content section is important enough to be a navigable region. Should we make it a landmark adding |
I love direct shortcuts like j/k, I'd wager they'd be really popular if we were able to add a bunch of those. However I've seen the Ctrl+` shortcut used as a standard to navigate between views in an application in many places. MacOS has a ⌘+` shortcut for switching between windows in an application (i.e. if you have two Safari windows open, ⌘+` switches between those two, because for whatever dumb reason the Mac designers thought Alt + Tab should flip between only applications, not windows). And so in my googling for european alternatives to the backtick, I realized that the backtick on US keyboards sits right above the tab button. That's where I have the $ key. And I figured ... hmmm... could they have? And sure enough, Ctrl+$ moves focus from region to region in Slack. Andrea can you test whether Ctrl + the key right above your tab button, below Esc switches between regions in Slack? If yes, then that's how they did it — they chose the key by geography. And if it works for you — should we consider doing the same? |
Wondering how do we match a keyboard position regardless of the layout. Is this the same keycode even if it's a different key? In my french keyboard it's If I try in this website http://keycode.info/ it gives me a keycode of 192. Are you seeing the same keycode? |
I would guess that we have to put together an array of keycodes for this character, based on whatever info we can glean. |
I'm afraid Slack implemented an alternate shortcuts only for the languages Slack is translated in. Spanish, French, and German. On an Italian keyboard layout, the key right above your tab button, below Esc is "Back slash" and does nothing. The Slack help keeps showing me Ctrl + backtick. Switching to French does show me: Ctrl + @
Not on all US keyboards, apparently. On my mac US keyboard is right above Ctrl: Id recommend to keep it simple 😉 |
@youknowriad I do get 192 for |
Should we go with keycode 192 whatever that is on each keyboard layout :)? I think we won't be able to use the |
If we are able to go with multiple shortcuts for the same, it seems we might be able to make the most people happy by picking a shortcut that...
While 2 isn't universally true, until we find a single keyboard shortcut that's actually a standard, the closest is what we have here with ⌘+` that Slack uses. It seems worth trying this. We could then supplement it, or replace it, with a simpler shortcut that doesn't change between keyboards, if we can find a good idea for what that should be. |
Interestingly I've used ⌘+` as a shortcut using the |
And it's a flashing focus now :) |
Ctrl + $ (the key above my tab) isn't working for me, and Ctrl + @ doesn't work for me as @ requires an Alt for me. |
🤔 Can you try this |
@jasmussen Oh you're on a mac right? did you try |
Oh interesting. I didn't try that, and I have that mapped to something else. But Macs also have Ctrl, and slack on Mac also uses Ctrl for this. I think CMD + backtick on a Mac is supposed to flip between windows of the same app |
Replaced command by ctrl, does it work now? |
@jasmussen I suspect the cropping to be fixed once we land this commit a0fdfc7 from #2998 |
Then 👍 👍 for the feature from me. I'll let others chime in on the shortcuts and implementation, but I dig this implementation. |
|
||
|
||
@mixin focus_flash { | ||
animation: focus_flash .4s; |
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.
Are spaces mixed in here?
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.
Good catch 👍
@@ -60,4 +60,4 @@ export default connect( | |||
notices: getNotices( state ), | |||
} ), | |||
{ removeNotice } | |||
)( Layout ); | |||
)( navigateRegions( 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.
Looks much better, thanks.
f34a7b0
to
9ad3640
Compare
Rebased this, it should be ready to go |
The cropping on the main area doesn't to be fixed after the rebase? Testing this, I feel that the fact it disappears so quickly doesn't communicate what this does very well—almost feels like a glitch. |
Ok per @mtias suggestion, I dropped the focus animation for now |
b8ed7b3
to
89254c2
Compare
Good catch, it should be fixed now |
Looks great to me. |
e120020
to
e893cb0
Compare
I've tested a bit on a Windows laptop with the Italian keyboard. There's no physical key for the backtick. On Italian keyboards with a numeric pad, the only way to produce a backtick is pressing Alt+96 on the numeric pad. Many laptops don't even have a numeric pad... Pressing the key below Escape (in my case it's a back slash) does nothing. Will open a new issue. |
Just had confirmation from @rianrietveld the backtick doesn't work on the Dutch keyboard layout (and as said previously, probably on many other layouts). This makes #3218 really necessary. |
closes #467
This PR adds keyboard shortcuts to navigate the aria regions ala slack.
For now, I came up with random shortcuts (
ctrl+r
andctrl+shift+r
), let me know which one you think I should use.