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

Listboxes with Rearrangeable Options: Add keyboard commands for multiple selection #1344

Merged
merged 8 commits into from
Mar 31, 2020

Conversation

smhigley
Copy link
Contributor

@smhigley smhigley commented Feb 24, 2020

Resolves #919

Adds the following functionality:

  • Shift + arrow keys
  • Control + Shift + home and end
  • Control + A
  • Shift + Click

Includes tests :)

Preview link

Review checklist

Copy link
Contributor

@carmacleod carmacleod left a 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].

@smhigley
Copy link
Contributor Author

@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!

Copy link
Contributor

@carmacleod carmacleod left a comment

Choose a reason for hiding this comment

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

Looks good!
+1

@mcking65 mcking65 changed the title Implement multiselect keyboard shorcuts Listboxes with Rearrangeable Options: Add keyboard commands for multiple selection Feb 28, 2020
Copy link
Contributor

@mcking65 mcking65 left a 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!!

@zcorpan
Copy link
Member

zcorpan commented Mar 4, 2020

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?

Copy link
Member

@zcorpan zcorpan left a 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 Show resolved Hide resolved
@@ -196,6 +218,14 @@ aria.Listbox.prototype.checkKeyPress = function (evt) {
this.focusItem(nextUnselected);
}
break;
case 65:
// handle control + A
if (this.multiselectable && evt.ctrlKey) {
Copy link
Contributor

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:

Suggested change
if (this.multiselectable && evt.ctrlKey) {
var isMac = window.navigator.platform.indexOf("Mac") !== -1;
var mod = isMac ? evt.metaKey : evt.ctrlKey;
if (this.multiselectable && mod) {

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 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

Copy link
Contributor

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!

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

@carmacleod carmacleod Mar 9, 2020

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.

Copy link
Contributor

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) {

@mcking65 mcking65 force-pushed the 919-listbox-multiselect-keys branch from a22e204 to 0931755 Compare March 9, 2020 05:41
@css-meeting-bot
Copy link
Member

The ARIA Authoring Practices (APG) Task Force just discussed Listboxes with rearrangeable options.

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

@mcking65 mcking65 force-pushed the 919-listbox-multiselect-keys branch from ea05c85 to 6b322b5 Compare March 24, 2020 07:58
@mcking65 mcking65 force-pushed the 919-listbox-multiselect-keys branch from 6b322b5 to b85474a Compare March 31, 2020 06:51
@mcking65 mcking65 merged commit f84febc into master Mar 31, 2020
@mcking65 mcking65 deleted the 919-listbox-multiselect-keys branch March 31, 2020 07:35
michael-n-cooper pushed a commit that referenced this pull request Mar 31, 2020
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>
carmacleod added a commit to carmacleod/aria-practices that referenced this pull request Mar 31, 2020
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bugs in example: listbox/listbox-rearrangeable.html (multiselect keyboard interactions)
5 participants