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

feat(a11y): manager for list keyboard events #1599

Merged
merged 1 commit into from
Oct 25, 2016

Conversation

kara
Copy link
Contributor

@kara kara commented Oct 25, 2016

This PR adds a reusable keyboard event manager for selectable lists (e.g. menu, select, and nav list). Existing e2e tests should cover this functionality.

r: @jelbourn

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 25, 2016
disabled: boolean;
}

export class ListKeyManager {
Copy link
Member

Choose a reason for hiding this comment

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

Add class description

import {EventEmitter, Output, QueryList} from '@angular/core';
import {UP_ARROW, DOWN_ARROW, TAB} from '../core';

export interface MdFocusable {
Copy link
Member

Choose a reason for hiding this comment

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

Add interface description

export class ListKeyManager {
private _focusedItemIndex: number;

@Output() tabOut: EventEmitter<null> = new EventEmitter();
Copy link
Member

Choose a reason for hiding this comment

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

Add field description.

Also, should it be EventEmitter<void>?

this._focusedItemIndex = value;
}

// TODO(kara): update this when (keydown.downArrow) testability is fixed
Copy link
Member

Choose a reason for hiding this comment

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

I don't this this TODO applies any more

disabled: boolean;
}

export class ListKeyManager {
Copy link
Member

Choose a reason for hiding this comment

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

We should have unit tests for just this class (with some fake MdFocusable items)

import {EventEmitter, Output, QueryList} from '@angular/core';
import {UP_ARROW, DOWN_ARROW, TAB} from '../core';

export interface MdFocusable {
Copy link
Member

Choose a reason for hiding this comment

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

Add interface description

this._focusedItemIndex = value;
}

// TODO(kara): update this when (keydown.downArrow) testability is fixed
Copy link
Member

Choose a reason for hiding this comment

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

I think this TODO is obsolete

@@ -67,61 +72,16 @@ export class MdMenu {
*/
_focusFirstItem() {
this.items.first.focus();
this._keyManager.focusedItemIndex = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Add comment like

// The menu always opens with the first item focused.

export class ListKeyManager {
private _focusedItemIndex: number;

@Output() tabOut: EventEmitter<null> = new EventEmitter();
Copy link
Member

Choose a reason for hiding this comment

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

Add description for tabOut

private _updateFocusedItemIndex(delta: number, items: MdFocusable[]) {
// when focus would leave menu, wrap to beginning or end
this._focusedItemIndex = (this._focusedItemIndex + delta + items.length)
% items.length;
Copy link
Member

Choose a reason for hiding this comment

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

nit: it's a little more readable to break at the highest semantic level, i.e.:

this._focusedItemIndex = 
    (this._focusedItemIndex + delta + items.length) % items.length;

@kara kara force-pushed the keyboard-toolkit branch 4 times, most recently from b32a186 to 415b5a4 Compare October 25, 2016 20:32
import {ListKeyManager, MdFocusable} from './list-key-manager';
import {DOWN_ARROW, UP_ARROW, TAB} from '../keyboard/keycodes';

class MockFocusable {
Copy link
Member

Choose a reason for hiding this comment

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

nit: technically it's a FakeFocusable

new MockFocusable()
];

itemList.toArray = () => { return items; };
Copy link
Member

Choose a reason for hiding this comment

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

itemList.toArray = () => items;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, good point.

* This event is emitted any time the TAB key is pressed, so components can react
* when focus is shifted off of the list.
*/
@Output() tabOut: EventEmitter<null> = new EventEmitter();
Copy link
Member

Choose a reason for hiding this comment

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

Should this be void instead of null?

Copy link
Contributor Author

@kara kara Oct 25, 2016

Choose a reason for hiding this comment

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

I can change. edit: we discussed in person

@kara kara added the action: merge The PR is ready for merge by the caretaker label Oct 25, 2016
@kara kara merged commit 95b2a34 into angular:master Oct 25, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants