Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cold-hairs-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@theoplayer/web-ui': patch
---

Fixed an issue where buttons inside the default UI could accidentally be clicked even when they were hidden because of user inactivity.
3 changes: 2 additions & 1 deletion src/DefaultUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { TimeRange } from './components/TimeRange';
import { STREAM_TYPE_CHANGE_EVENT } from './events/StreamTypeChangeEvent';
import { USER_IDLE_CHANGE_EVENT } from './events/UserIdleChangeEvent';
import { READY_EVENT } from './events/ReadyEvent';
import { ACCIDENTAL_CLICK_DELAY } from './util/Constants';
import { toggleAttribute } from './util/CommonUtils';
import { createCustomEvent } from './util/EventUtils';
import { createTemplate } from './util/TemplateUtils';
Expand Down Expand Up @@ -343,7 +344,7 @@ export class DefaultUI extends HTMLElement {
// but wait a little bit to prevent accidentally clicking the seekbar.
this._timeRangeInertTimeout = setTimeout(() => {
this._timeRange!.inert = false;
}, 50);
}, ACCIDENTAL_CLICK_DELAY);
}
}
this.dispatchEvent(createCustomEvent(USER_IDLE_CHANGE_EVENT));
Expand Down
3 changes: 2 additions & 1 deletion src/UIContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { isArrowKey, isBackKey, KeyCode } from './util/KeyCode';
import { READY_EVENT } from './events/ReadyEvent';
import { createTemplate } from './util/TemplateUtils';
import { addGlobalStyles } from './Global';
import { ACCIDENTAL_CLICK_DELAY } from './util/Constants';

// Load components used in template
import './components/GestureReceiver';
Expand Down Expand Up @@ -1092,7 +1093,7 @@ export class UIContainer extends HTMLElement {

private readonly _onClickAfterPointerUp = (event: MouseEvent): void => {
this.removeEventListener('click', this._onClickAfterPointerUp, true);
if (performance.now() - this._lastPointerUpTime < 10) {
if (performance.now() - this._lastPointerUpTime < ACCIDENTAL_CLICK_DELAY) {
event.preventDefault();
event.stopPropagation();
}
Expand Down
10 changes: 10 additions & 0 deletions src/util/Constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* The delay before we should start handling clicks
* after the user becomes active again (in milliseconds).
*
* When the user is idle and then touches the player, that first touch
* should not trigger any accidental clicks on UI controls. Therefore,
* we will keep all UI controls inactive for a little bit longer
* after that first touch, until this delay has passed.
*/
export const ACCIDENTAL_CLICK_DELAY = 50;