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

♿ Router: Focus element after URL hash scroll into view navigation #30067

Closed
MrGrigri opened this issue Apr 23, 2019 · 9 comments
Closed

♿ Router: Focus element after URL hash scroll into view navigation #30067

MrGrigri opened this issue Apr 23, 2019 · 9 comments
Labels
area: router freq4: critical P2 The issue is important to a large percentage of users, with a workaround state: confirmed type: bug/fix
Milestone

Comments

@MrGrigri
Copy link

MrGrigri commented Apr 23, 2019

♿ feature request

Add a flag for the Router Module to accept a flag to enable focusing of the element to which it is scrolled. In a previous issue (#6595) it was discussed that a feature request is needed to handle this issue.

This feature is required for Accessibility to work properly.

Relevant Package

@angular/router/ExtraOptions

Description

This feature is required for Accessibility to work properly. The anchorScrolling router option works...however, according to the HTML Standard Spec, Navigate to a Fragment, the last step is:

Move the sequential focus navigation starting point to [the] target.

Describe the solution you'd like

Add a parameter for ExtraOptions as anchorFocus with the boolean type attached and false as the default

export interface ExtraOptions {
  ...
  anchorScrolling?: 'disabled' | 'enabled',
  anchorFocus?: boolean,
  ...
})

This could be achieved by dynamically setting a tabindex of '0' on the targeted element, focusing on that element, then setting the tabindex to '-1'. If a tabindex is already set to '0', then just focus on the element.

@ngbot ngbot bot added this to the needsTriage milestone Apr 23, 2019
@AlekNiebla
Copy link

Hey can I work this issue?

@MrGrigri MrGrigri changed the title Router: Focus element after URL hash scroll into view navigation ♿ Router: Focus element after URL hash scroll into view navigation Apr 23, 2019
@AlekNiebla
Copy link

Hey can I work this issue?

hey im not gonna take on this issue

@danielnixon
Copy link

This is one of the issues I'm tackling in https://github.com/oaf-project/oaf-angular-router

@jasonaden
Copy link
Contributor

Thanks for the issue. This would be a good one to get fixed. Thanks for taking a look @danielnixon .

@zelliott
Copy link
Contributor

zelliott commented Aug 13, 2019

Quickly chiming in, I don't think the proposed solution (reproduced below) is what we want:

This could be achieved by dynamically setting a tabindex of '0' on the targeted element, focusing on that element, then setting the tabindex to '-1'. If a tabindex is already set to '0', then just focus on the element.

We don't want to set focus on the target element, we want to move the sequential focus navigation starting point to the target. There's likely some logic in Angular's router (I'm super unfamiliar with Angular's router) that's preventing the browser from correctly doing this.

@MrGrigri
Copy link
Author

@zelliott, according to the spec, the element needs to be focused on for accessibility reasons.

@zelliott
Copy link
Contributor

Sorry, I misread the spec, thanks.

However, after reading the spec, I still don't think the proposed solution is quite what we want. The target element should not be focused. Instead, it should have the focusing steps run on it. The difference is that if the target element is not focusable, it is not focused. Maybe a bit pedantic, but thought it'd be worth clarifying here.

@tomasdev

This comment has been minimized.

@jelbourn jelbourn added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed severity3: broken labels Oct 1, 2020
@jelbourn jelbourn added P2 The issue is important to a large percentage of users, with a workaround and removed P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Dec 21, 2020
atscott added a commit to atscott/angular that referenced this issue Dec 22, 2020
According to the [spec](https://html.spec.whatwg.org/#scroll-to-fragid),
we should attempt to set the browser focus after scrolling to a
fragment. Note that this change does not exactly follow the robust steps
outlined in the spec by finding a fallback target if the original is not
focusable. Instead, we simply attempt to focus the element by calling
`focus` on it, which will do nothing if the element is not focusable.

fixes angular#30067
atscott added a commit to atscott/angular that referenced this issue Dec 22, 2020
According to the [spec](https://html.spec.whatwg.org/#scroll-to-fragid),
we should attempt to set the browser focus after scrolling to a
fragment. Note that this change does not exactly follow the robust steps
outlined in the spec by finding a fallback target if the original is not
focusable. Instead, we simply attempt to focus the element by calling
`focus` on it, which will do nothing if the element is not focusable.

fixes angular#30067
atscott added a commit to atscott/angular that referenced this issue Dec 22, 2020
According to the [spec](https://html.spec.whatwg.org/#scroll-to-fragid),
we should attempt to set the browser focus after scrolling to a
fragment. Note that this change does not exactly follow the robust steps
outlined in the spec by finding a fallback target if the original is not
focusable. Instead, we simply attempt to focus the element by calling
`focus` on it, which will do nothing if the element is not focusable.

fixes angular#30067
atscott added a commit to atscott/angular that referenced this issue Dec 22, 2020
According to the [spec](https://html.spec.whatwg.org/#scroll-to-fragid),
we should attempt to set the browser focus after scrolling to a
fragment. Note that this change does not exactly follow the robust steps
outlined in the spec by finding a fallback target if the original is not
focusable. Instead, we simply attempt to focus the element by calling
`focus` on it, which will do nothing if the element is not focusable.

fixes angular#30067
atscott added a commit to atscott/angular that referenced this issue Dec 22, 2020
According to the [spec](https://html.spec.whatwg.org/#scroll-to-fragid),
we should attempt to set the browser focus after scrolling to a
fragment. Note that this change does not exactly follow the robust steps
outlined in the spec by finding a fallback target if the original is not
focusable. Instead, we simply attempt to focus the element by calling
`focus` on it, which will do nothing if the element is not focusable.

fixes angular#30067
atscott added a commit to atscott/angular that referenced this issue Dec 28, 2020
According to the [spec](https://html.spec.whatwg.org/#scroll-to-fragid),
we should attempt to set the browser focus after scrolling to a
fragment. Note that this change does not exactly follow the robust steps
outlined in the spec by finding a fallback target if the original is not
focusable. Instead, we simply attempt to focus the element by calling
`focus` on it, which will do nothing if the element is not focusable.

fixes angular#30067
josephperrott pushed a commit that referenced this issue Jan 5, 2021
According to the [spec](https://html.spec.whatwg.org/#scroll-to-fragid),
we should attempt to set the browser focus after scrolling to a
fragment. Note that this change does not exactly follow the robust steps
outlined in the spec by finding a fallback target if the original is not
focusable. Instead, we simply attempt to focus the element by calling
`focus` on it, which will do nothing if the element is not focusable.

fixes #30067

PR Close #40241
@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 Feb 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: router freq4: critical P2 The issue is important to a large percentage of users, with a workaround state: confirmed type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants