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(typeahead) : accessibility support #1321

Closed
wants to merge 2 commits into from

Conversation

thbt
Copy link
Contributor

@thbt thbt commented Feb 17, 2017

Fixes focus management and speech when using a screen reader

  • read and followed the CONTRIBUTING.md guide.
  • built and tested the changes locally.
  • added/updated any applicable tests.
  • added/updated any applicable API documentation.
  • added/updated any applicable demos.

Fixes focus management and speech when using a screen reader
* An optional id for the typeahead. The id should be unique.
* If not provided, it will be auto-generated.
*/
@HostBinding('attr.id') @Input() id: string = undefined;

Choose a reason for hiding this comment

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

Could you please use 'host' instead of @HostBinding so all the host bindings are in one place only?

Choose a reason for hiding this comment

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

There is no need for = undefined - it is initialized like this by default.

Choose a reason for hiding this comment

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

Also the comment seems to be invalid as we are not auto-generating id when one is not provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The id is actually generated in the typeahead.ts file and set when the popup is opened (see _openPopup method).
It's actually kinda hackish but I don't know how else I can set the id of the popup. If I generate it in the typeahead-window.ts file, a new id will be generated each time the popup is opened (since a new instance is created each time)

I applied your other comments.

<button type="button" class="dropdown-item" [class.active]="idx === activeIdx"
(mouseenter)="markActive(idx)"
<button type="button" class="dropdown-item" role="option"
[attr.id]="id + '-' + idx"

Choose a reason for hiding this comment

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

I think that you can use [id]="..." instead of [attr.id] as buttons should have the id property.


next() {
if (this.activeIdx === this.results.length - 1) {
this.activeIdx = this.focusFirst ? (this.activeIdx + 1) % this.results.length : -1;
} else {
this.activeIdx++;
}
this.activeChangedEvent.emit(this.id + '-' + this.activeIdx);

Choose a reason for hiding this comment

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

You've got this this.activeChangedEvent.emit(this.id + '-' + this.activeIdx) logic repeated in several places, would be good to extract it. Also, shouldn't -1 by handled as a special case?

@@ -124,6 +129,10 @@ export class NgbTypeahead implements ControlValueAccessor,
*/
@Output() selectItem = new EventEmitter<NgbTypeaheadSelectItemEvent>();

@HostBinding('attr.aria-activedescendant') activeDescendant: string = undefined;

Choose a reason for hiding this comment

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

activeDescendant: string is enough, no need for = undefined

@@ -124,6 +129,10 @@ export class NgbTypeahead implements ControlValueAccessor,
*/
@Output() selectItem = new EventEmitter<NgbTypeaheadSelectItemEvent>();

@HostBinding('attr.aria-activedescendant') activeDescendant: string = undefined;
@HostBinding('attr.aria-owns') popupId: string = `ngb-typeahead-${nextId++}`;

Choose a reason for hiding this comment

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

Please use host instead of @HostBinding

Choose a reason for hiding this comment

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

No need for type (: string) as TS will infer it

@@ -124,6 +129,10 @@ export class NgbTypeahead implements ControlValueAccessor,
*/
@Output() selectItem = new EventEmitter<NgbTypeaheadSelectItemEvent>();

@HostBinding('attr.aria-activedescendant') activeDescendant: string = undefined;
@HostBinding('attr.aria-owns') popupId: string = `ngb-typeahead-${nextId++}`;
@HostBinding('attr.aria-expanded') isOpen: boolean = false;

Choose a reason for hiding this comment

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

No need for type (: boolean) as TS will infer it

@pkozlowski-opensource
Copy link
Member

@thbt thnx for the PR - I did the first pass on it and left some comments. Please address those and then I will have another look. Thnx!

@pkozlowski-opensource pkozlowski-opensource added this to the 1.0.0-alpha.23 milestone Apr 6, 2017
@thbt thbt deleted the typeahead-a11y branch April 7, 2017 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants