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

Differentiating between the user and code setting focus #577

Open
ben-lu-uw opened this issue Nov 15, 2021 · 7 comments
Open

Differentiating between the user and code setting focus #577

ben-lu-uw opened this issue Nov 15, 2021 · 7 comments

Comments

@ben-lu-uw
Copy link
Contributor

In #533 I made it so that the screen reader announces the location when the map is focused. However, we seem to use .focus() on the map container a lot, for example, when clicking a feature link the screen reader will announce the focus message even though the user did not focus the map themselves. There's now a mix where either the user focuses on the map or we forced the focus through JS but they both fire the same event. Should we introduce a new event for when the user focuses or try and have a different approach instead of forcing focus changes or something else?

@ahmadayubi
Copy link
Member

For checking if the map is focused there is a this._map.isFocused variable that is used to show or hide the crosshair. You may also be able to used it in this case.

https://github.com/Maps4HTML/Web-Map-Custom-Element/blob/31ad0bd0b392bd10f40527efd0185af70bd54562/src/mapml/layers/Crosshair.js#L88-L103

@ben-lu-uw
Copy link
Contributor Author

ben-lu-uw commented Nov 16, 2021

Shouldn't isFocused also be changed when mousedown focuses on a different element or does that affect the functionality of the crosshair?
image
Edit: click map tab to focus map

@ahmadayubi
Copy link
Member

2021-11-16.09-50-20.mp4

That's the behavior I see, but the variable afterward doesn't seem to update although the internal behavior that uses that variable does (not sure why there would be a difference at the moment).

Also the moment you go to the console the map loses focus so a better way to check the variable state is adding console.log to the code.

@ben-lu-uw
Copy link
Contributor Author

Console logging gives the same result and I do get the same behavior as you with the crosshair.
Another example is that if you click on the map the focus box or crosshair does not appear even though the active element is the map.

@ahmadayubi
Copy link
Member

ahmadayubi commented Nov 16, 2021

Console logging gives the same result and I do get the same behavior as you with the crosshair. Another example is that if you click on the map the focus box or crosshair does not appear even though the active element is the map.

The last part is by design, you only want the crosshair, outline and announcements (unless, it was decided otherwise) when using keyboard, not mouse. The crosshair for example provides no value if you already have a mouse that can click anywhere including the center on the map.

@ben-lu-uw
Copy link
Contributor Author

Ah makes sense. For announcement Peter did want it to announce location when the mouse dragged the map as well, so I guess it makes the most sense to also announce when focused/unfocused through clicking.

@ahmadayubi
Copy link
Member

When checking for the active element, one thing I had to account for in the past is that the active element of the DOM is different than the active element of the shadowDom.

i.e. if you have the zoom button focused, the DOM's active element will be the mapml-viewer, whereas the shadowDom's active element will be the button itself. IIRC

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