Interactive markers are not operable with a keyboard [2.0] [Accessibility] - with PR
Checklist
- I've looked at the documentation to make sure the behavior isn't documented and expected.
- I'm sure this is an issue with Leaflet, not with my app or other dependencies (Angular, Cordova, React, etc.).
- I've searched through the current issues to make sure this hasn't been reported yet.
- I agree to follow the Code of Conduct that this project adheres to.
Steps to reproduce
- Observe an interactive marker element, within a Leaflet map.
- Navigate onto it with a keyboard using
Tab. - Attempt to activate the element with
ReturnorSpace. - Observe that the element does not respond.
- Observe that there is not an alternative way to access the same information or functionality.
Expected behavior
I expect to be able to open an alert() popup, or other popup from an interactive marker in a Leaflet map, using just the keyboard - with the Tab, Shift+Tab, Return/Enter and Space keys (Keyboard testing).
const marker = new Marker([51.5, -0.09])
.on('click', (ev) => alert('Marker click!'))
.addTo(map);Current behavior
At present, I'm forced to use a mouse.
For those who rely on a keyboard this is a blocking accessibility bug.
- Priority: High,
- Users Affected: Motor,
- WCAG 2.2 Success Criteria: 2.1.1 Keyboard [A]
Cause
The root cause of this is that the marker element is an <img> element, which is non-interactive by default. As such, Return and Space key presses do not result in click events.
(Note that ARIA and role attributes have no bearing on keyboard accessibility.)
Fix
A fix is to replace the <img> element with a native interactive element, such as <button>, <input> or <a href="..">. With these, Return and/or Space key presses do result in click events.
A neat fix would be to use an <input> element with a type="image" attribute. This would result in:
Interactive marker:
<input type="image" src="marker.png" alt="Interactive marker" ...>Non-interactive markers (keyboard: false in options):
<img src="marker.png" alt="Static marker" ...>Minimal example reproducing the issue
Environment
- Leaflet version: 2.0.0-alpha.1,
- Browser:
Chrome 140.0 - OS/Platform:
Mac OS 10.15.7
(Note, the bug will be the same on any desktop browser/OS combination.)
Source: Leaflet/Leaflet