-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Conversation
54d2359
to
19499c0
Compare
disabled: boolean; | ||
} | ||
|
||
export class ListKeyManager { |
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.
Add class description
import {EventEmitter, Output, QueryList} from '@angular/core'; | ||
import {UP_ARROW, DOWN_ARROW, TAB} from '../core'; | ||
|
||
export interface MdFocusable { |
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.
Add interface description
export class ListKeyManager { | ||
private _focusedItemIndex: number; | ||
|
||
@Output() tabOut: EventEmitter<null> = new EventEmitter(); |
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.
Add field description.
Also, should it be EventEmitter<void>
?
this._focusedItemIndex = value; | ||
} | ||
|
||
// TODO(kara): update this when (keydown.downArrow) testability is fixed |
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 this this TODO
applies any more
disabled: boolean; | ||
} | ||
|
||
export class ListKeyManager { |
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.
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 { |
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.
Add interface description
this._focusedItemIndex = value; | ||
} | ||
|
||
// TODO(kara): update this when (keydown.downArrow) testability is fixed |
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 think this TODO is obsolete
@@ -67,61 +72,16 @@ export class MdMenu { | |||
*/ | |||
_focusFirstItem() { | |||
this.items.first.focus(); | |||
this._keyManager.focusedItemIndex = 0; |
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.
Add comment like
// The menu always opens with the first item focused.
export class ListKeyManager { | ||
private _focusedItemIndex: number; | ||
|
||
@Output() tabOut: EventEmitter<null> = new EventEmitter(); |
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.
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; |
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.
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;
b32a186
to
415b5a4
Compare
import {ListKeyManager, MdFocusable} from './list-key-manager'; | ||
import {DOWN_ARROW, UP_ARROW, TAB} from '../keyboard/keycodes'; | ||
|
||
class MockFocusable { |
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.
nit: technically it's a FakeFocusable
new MockFocusable() | ||
]; | ||
|
||
itemList.toArray = () => { return items; }; |
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.
itemList.toArray = () => items;
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.
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(); |
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.
Should this be void
instead of null
?
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 can change. edit: we discussed in person
415b5a4
to
c4a6015
Compare
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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