-
Notifications
You must be signed in to change notification settings - Fork 313
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
Listboxes with Rearrangeable Options: Add keyboard commands for multiple selection #1344
Conversation
3919615
to
8c00dd1
Compare
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.
Nice!
Confirmed that the new "multi-select" keys for Example 2 now work as advertised!
Thanks for adding shift+click
as well.
However, Example 1 now selects all options when Ctrl+A
is typed. :)
(see inline code suggestion).
Might want to add a new ariaTest
for 'key control+A does not select all options in example 1'. ;)
Should the test title explicitly list "example 1"? Not sure what we usually do for test titles for multiple examples, but it might be a bit confusing if we had one test that said:
'key control+A selects all options'
and another that said:
'key control+A does not select all options'
[Edit: Wow - you are way ahead of me! You've already committed a fix! I'll have a look later this evening].
@carmacleod I added a couple more tests for the control + a behavior, including the one you suggested :) Let me know if that addresses everything, and thanks for the review! |
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 good!
+1
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.
Editorial changes and functional changes are good, thank you @smhigley!!
So on macOS, the usual shortcut for select all is Command+A, not Control+A. How should we handle this? Support both Control+A and Command+A? Detect macOS and change the shortcut from Control+A to Command+A? |
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.
Code review and test review done. Looks good and tests pass. There's a typo in a comment elemnt
.
We could merge this and follow up with the question about macOS in a new issue.
examples/listbox/js/listbox.js
Outdated
@@ -196,6 +218,14 @@ aria.Listbox.prototype.checkKeyPress = function (evt) { | |||
this.focusItem(nextUnselected); | |||
} | |||
break; | |||
case 65: | |||
// handle control + A | |||
if (this.multiselectable && evt.ctrlKey) { |
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.
To answer @zcorpan 's question:
So on macOS, the usual shortcut for select all is Command+A, not Control+A. How should we handle this?
Detect macOS and change the shortcut from Control+A to Command+A
Something like this should do it:
if (this.multiselectable && evt.ctrlKey) { | |
var isMac = window.navigator.platform.indexOf("Mac") !== -1; | |
var mod = isMac ? evt.metaKey : evt.ctrlKey; | |
if (this.multiselectable && mod) { |
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.
I don't think we need to detect Mac. I just added (evt.ctrlKey || evt.metaKey)
. That should work for Mac, and doesn't cause issues with the Windows key, since Windows + A is eaten by the OS anyway.
@zcorpan let me know if it's working for you with that change
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.
Windows + A is eaten by the OS anyway.
Ha! I did not know that. :)
Seems to open up the notification sidebar.
Whaddaya know.
Thanks for the lesson!
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.
What will this logic end up doing on Linux where I believe we want it to be ctrl-a? There could be other platforms, even some mobile with BT keyboards that will allow these commands to be used. I just pushed a change to the keyboard documentation, but I don't believe what I wrote is entirely accurate using this logic.
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.
Hmmm... now that I'm looking at the logic, I believe it makes both Ctrl+A
and Cmd+A
work on macOS. Do we want that?
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.
@mcking65
I don't think there's a KeyboardEvent.metaKey on Linux. Hopefully someone can confirm.
The doc says the only other metaKey
is the Windows key on Windows keyboards, and @smhigley mentioned that Windows+A is eaten by the OS (i.e. our code would never see it).
The code within the case for the 'A' (65) key being pressed is:
if (this.multiselectable && (evt.ctrlKey || evt.metaKey))
so the logic would work as follows on Linux:
"if the list is multiselectable and the control key was pressed (with the 'A')"
So || evt.metaKey
would never be evaluated.
So I think the logic is ok for Linux, but I don't think it's ok for macOS, unless we want both ctrl+A and command-A to select all.
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.
@mcking65
You are correct about the keyboards! I googled a bit and discovered that some older Linux keyboards and even some recent bluetooth android keyboards have a meta key (apparently for the mobile ones, the "search" key maps to metaKey). So even though those keyboards are likely rare, we don't want meta+A to select all. We only want that on Mac.
@smhigley I think we need to go with the code that detects Mac:
var isMac = window.navigator.platform.indexOf("Mac") !== -1;
var mod = isMac ? evt.metaKey : evt.ctrlKey;
if (this.multiselectable && mod) {
a22e204
to
0931755
Compare
The ARIA Authoring Practices (APG) Task Force just discussed The full IRC log of that discussion<carmacleod> TOPIC: Listboxes with rearrangeable options<carmacleod> github: https://github.com//pull/1344 <ZoeBijl> regrets+ <carmacleod> sarah: prefer not to detect platform, in case it's not future-proof <Jemma> mck: adding this var mod = isMac ? evt.metaKey : evt.ctrlKey; <carmacleod> sarah: so we can support Ctrl+A select all on Mac as well as Cmd+A for select all <carmacleod> mck: I'm ok with that - I'll update the documentation table <carmacleod> mck: will merge after updating table |
ea05c85
to
6b322b5
Compare
6b322b5
to
b85474a
Compare
Listboxes with Rearrangeable Options: Add keyboard commands for multiple selection (pull #1344) Resolves issue #919 by adding the following commands for selecting options: - Shift + arrow keys - Control + Shift + home and end - Control + A, command-a on macOS - Shift + Click Adds regression tests for the commands. Co-authored-by: Matt King <a11yThinker@gmail.com> Co-authored-by: Carolyn MacLeod <Carolyn_MacLeod@ca.ibm.com>
…ple selection (pull w3c#1344) Resolves issue w3c#919 by adding the following commands for selecting options: - Shift + arrow keys - Control + Shift + home and end - Control + A, command-a on macOS - Shift + Click Adds regression tests for the commands. Co-authored-by: Matt King <a11yThinker@gmail.com> Co-authored-by: Carolyn MacLeod <Carolyn_MacLeod@ca.ibm.com>
Resolves #919
Adds the following functionality:
Includes tests :)
Preview link
Review checklist