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

[Accessbility] ui-router doesn't work with keyboard with url-less states #721

Closed
Eradev opened this issue Jan 27, 2020 · 3 comments
Closed

Comments

@Eradev
Copy link

Eradev commented Jan 27, 2020

Hello,

navigation using a keyboard breaks with url-less states due to the uiSref directive removing an empty href. That makes the anchor not tabbable without tabindex, and also remove the ability to navigate to the state with the Enter button as it's no longer considered a link.

Was it intended to be like that? Is there a workaround?

@Eradev
Copy link
Author

Eradev commented Jan 29, 2020

Ended up overwriting AnchorUISref.update.

import { Directive, ElementRef, Renderer2, Host } from '@angular/core';
import { AnchorUISref } from '@uirouter/angular';

// tslint:disable-next-line: directive-selector
@Directive({ selector: 'a[uiSref]' })
export class CustomUiSrefDirective {
  constructor(
    @Host() public hostAnchor: AnchorUISref,
    private renderer: Renderer2,
    private elementRef: ElementRef) {

    hostAnchor.update = (href: string) => {
      this.renderer.setProperty(this.elementRef.nativeElement, 'tabIndex', '0');

      if (href && href !== '') {
        this.renderer.setProperty(this.elementRef.nativeElement, 'href', href);
      } else {
        this.renderer.setProperty(this.elementRef.nativeElement, 'href', '');
      }
    };
  }
}

@christopherthielen
Copy link
Member

This behavior is related to this bug report angular-ui/ui-router#3248

I've fixed this in #721, hopefully this behavior is correct now.

@mergify mergify bot closed this as completed in 5020c79 Jul 6, 2020
@Eradev
Copy link
Author

Eradev commented Nov 3, 2020

@christopherthielen I just re-tested this. The fix enables the Enter button, but it is still ignored when navigating with Tab.

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

No branches or pull requests

2 participants