Skip to content

Commit

Permalink
fix(ui): Fix hiding controls on mobile after touch
Browse files Browse the repository at this point in the history
On pointerless touch-screen devices, :hover queries on an element do
not make sense.  In spite of this, they can pass on such devices after
a touch event, and elements even get stuck in this false :hover state.

Now we check if the device supports hovering before making the :hover
query on individual elements, which fixes the hiding on controls on
mobile after a touch event.

Closes #2886

Backported to v2.5.x

Change-Id: I5ae0b0c84c69961c33df5e50f480b53495ab2694
  • Loading branch information
joeyparrish committed Oct 5, 2020
1 parent 4f991a5 commit 4c58835
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ui/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,14 @@ shaka.ui.Controls.prototype.onMouseStill_ = function() {
* @private
*/
shaka.ui.Controls.prototype.isHovered_ = function() {
if (!window.matchMedia('hover: hover').matches) {
// This is primarily a touch-screen device, so the :hover query below
// doesn't make sense. In spite of this, the :hover query on an element
// can still return true on such a device after a touch ends.
// See https://bit.ly/34dBORX for details.
return false;
}

return this.showOnHoverControls_.some((element) => {
return element.matches(':hover');
});
Expand Down

0 comments on commit 4c58835

Please sign in to comment.