Hello,
This post is a follow up of an other post I’ve made in the chromium discussion group: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-discuss/nHH_y7yWRAY.
Context
We have video controls which are usually displayed for 3s when user interacts with the player. After this delay controls are hidden because what matters is the video being played.
Feature
In this context, only when user navigates using keyboard, we want to keep controls visible until they loose focus, instead of 3s ellapsed without interaction.
Solution right now
let fromMouse = false
element.addEventListener('mousedown', () => {
fromMouse = true
setTimeout(() => {
fromMouse = false
})
})
element.addEventListener('focus', () => {
const mustKeepControlsVisible = fromMouse === false
})
This solution is almost what we are planning to use in production. I would like to suggest something more reliable.
Proposal
Add relatedEvent
to focus
and blur
events.
This new property may be one of null, mousedownEvent, touchstartEvent and keydownEvent.
element.addEventListener('focus', (e) => {
const mustKeepControlsVisible = e.relatedEvent && e.relatedEvent.type === 'keydown'
})
Existing proposals on same subject
Introduce a new CSS selector, :serial-focus
that could be used to differentiate focus.
element.addEventListener('focus', () => {
const mustKeepControlsVisible = element.matches(':serial-focus')
})
Also introduce a new CSS selector, :visual-focus-ring-is-not-required
that could be used as shown below.
element.addEventListener('focus', () => {
const mustKeepControlsVisible = element.matches(':visual-focus-ring-is-not-required') === false
})
Please let me know what you think