-
Notifications
You must be signed in to change notification settings - Fork 124
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
Remember hadKeyboardEvent across navigations? #198
Comments
I don't have good answers just sharing some of the history here :) We've wrestled with this issue a fair bit:
I think there are two parts to the question:
I think @Justineo's comment addresses the first question: #88 (comment) It feels like our heuristic could be "good enough" in that it always tries to match on programmatic focus, but it also feels like the Regarding the second question, I'm leaning toward not sharing this information across origins because that feels like it gets into a weird user privacy space. That also makes me wonder about #42 where we discuss the option of letting users opt-in to always displaying a focus indicator regardless of modality. I'm wondering if that indicator should be drawn in a way that does not use the underlying style system so folks can't fingerprint it. |
@jakearchibald Have we ever discussed Focus Navigation Start Point? One of the ideas Alice and I have been discussing is exposing this to developers. Currently in SPAs folks do focus management by setting tabindex=-1 on an element and calling focus on it when it loads. Often they suppress the focus ring because the element they're moving focus to is non-interactive (maybe it's a heading or a div that wraps new page content). This has always felt kind of hacky and so we'd like to expose an API so developers can say "move the focus start point to this element." The element itself isn't really "focused" but likely a screen reader cursor would move to it, and the next time the user presses Tab they would be navigating inside of this element. If such an API existed, do you think that's what you'd be using in the scenario you describe? |
The polyfill does a good job here I think. As in, switching on the last device the user used.
Agreed. But what about same-origin? The polyfill doesn't currently store it, hence the issue I ran into, but it could via session storage.
I hadn't read that before, and it's great, but I don't think it applies in this situation. In this case, I want to show focus styles if the user used keyboard, but I don't want to show focus styles if the user used mouse. focus-visible generally does a good job with this, unless there's a navigation in the middle. If there's a navigation in the middle, focus-visible forgets that the mouse was used. Maybe the workaround I used can explain it better than I can GoogleChromeLabs/proxx@bfea7b5. |
In fact, here's a reduced demo https://static-misc.glitch.me/focus-visible/. |
@alice do you happen to know if Chromium's focus type flag gets reset when someone navigates? @jakearchibald I think I'm ok with adding this to session storage—Alice do you have any thoughts? Jake I don't know if you have the bandwidth to do a PR on the polyfill to add this? If not that's totally OK, I can try to get to it sometime soon. |
I'll put it on my backlog |
I'm running into the same problem with native focus-visible implementation. I'd like to dig out this old thread since Jake was here :D. In the following example: https://codesandbox.io/s/focus-on-page-load-jy595z?file=/src/index.js, I programmatically focus the span on page load. To my surprise, the span receives focus-visible and shows the focus ring. If I understand correctly, focus-visible is only applied to an element if it is focused from a keyboard interaction. I guess chromium follows similar logic as the polyfill, which sets the keyboard interact status to true by default. My question is why focus-visible behave in such a way? I'm building a player widget that uses focus-trap library. It automatically focuses an element on page load. This behavior is causing UI issues... |
Right now this will show focus styles, because
hadKeyboardEvent
has reset as part of the navigation.Should it be stored in session storage?
From a web standards point of view, should this state travel across origins? In the above steps, imagine if the page with the start button was on another origin to the page with the game board.
This would be observable in the new page by looking at computed styles, so it does leak some data about interaction with the other origin.
The text was updated successfully, but these errors were encountered: