Fix drawer open bug in iOS Safari.

This commit is contained in:
Dermot Duffy
2022-08-13 13:48:01 -07:00
parent 86a1ae785c
commit 70d445d921
3 changed files with 24 additions and 11 deletions
+12 -5
View File
@@ -13,6 +13,7 @@ import { SideDrawer } from 'side-drawer';
import drawerInjectStyle from '../scss/drawer-inject.scss';
import drawerStyle from '../scss/drawer.scss';
import { stopEventFromActivatingCardWideActions } from '../utils/action';
import { isHoverableDevice } from '../utils/basic';
@customElement('frigate-card-drawer')
export class FrigateCardDrawer extends LitElement {
@@ -37,6 +38,8 @@ export class FrigateCardDrawer extends LitElement {
protected _resizeObserver = new ResizeObserver(() => this._hideDrawerIfNecessary());
protected readonly _isHoverableDevice = isHoverableDevice();
/**
* Called on the first update.
* @param changedProps The changed properties.
@@ -110,7 +113,11 @@ export class FrigateCardDrawer extends LitElement {
class="control"
icon="${this.open ? 'mdi:menu-open' : 'mdi:menu'}"
@mouseenter=${() => {
if (!this.open) {
// Only open the drawer on mousenter when the device
// supports hover (otherwise iOS may end up passing on
// subsequent click events to a different element, see:
// https://github.com/dermotduffy/frigate-hass-card/issues/801
if (this._isHoverableDevice && !this.open) {
this.open = true;
}
}}
@@ -130,8 +137,8 @@ export class FrigateCardDrawer extends LitElement {
}
declare global {
interface HTMLElementTagNameMap {
"frigate-card-drawer": FrigateCardDrawer
"side-drawer": SideDrawer,
}
interface HTMLElementTagNameMap {
'frigate-card-drawer': FrigateCardDrawer;
'side-drawer': SideDrawer;
}
}
+3 -5
View File
@@ -47,7 +47,7 @@ import {
TimelineConfig,
} from '../types';
import { stopEventFromActivatingCardWideActions } from '../utils/action';
import { dispatchFrigateCardEvent, errorToConsole, prettifyTitle } from '../utils/basic';
import { dispatchFrigateCardEvent, errorToConsole, isHoverableDevice, prettifyTitle } from '../utils/basic';
import { getCameraTitle } from '../utils/camera.js';
import {
getRecordingSegments,
@@ -548,9 +548,7 @@ export class FrigateCardTimelineCore extends LitElement {
protected _pointerHeld = false;
protected _ignoreClick = false;
protected static _isHoverableDevice = window.matchMedia(
'(hover: hover) and (pointer: fine)',
).matches;
protected readonly _isHoverableDevice = isHoverableDevice();
/**
* Get a tooltip for a given timeline event.
@@ -559,7 +557,7 @@ export class FrigateCardTimelineCore extends LitElement {
*/
protected _getTooltip(item: TimelineItem): string {
const source = (<FrigateCardTimelineItem>item).source;
if (!FrigateCardTimelineCore._isHoverableDevice || !source) {
if (!this._isHoverableDevice || !source) {
// Don't display tooltips on touch devices, they just get in the way of
// the drawer.
return '';
+9 -1
View File
@@ -76,4 +76,12 @@ export function errorToConsole(e: Error, func?: CallableFunction): void {
} else {
func(e);
}
}
}
/**
* Determine if the device supports hovering.
* @returns `true` if the device supports hovering, `false` otherwise.
*/
export const isHoverableDevice = (): boolean => window.matchMedia(
'(hover: hover) and (pointer: fine)',
).matches;