Skip to content

Commit

Permalink
fix(player): disable click/touchstart event when toggles are disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar-22 committed Nov 30, 2023
1 parent ed8b646 commit 7c1ce4d
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export class ToggleButtonController extends ViewController<ToggleButtonControlle

protected override onConnect(el: HTMLElement) {
onPress(el, this._onMaybePress.bind(this));

// Prevent these events too when toggle is disabled.
for (const type of ['click', 'touchstart'] as const) {
this.listen(type, this._onInteraction.bind(this));
}
}

protected _isARIAPressed() {
Expand All @@ -64,11 +69,19 @@ export class ToggleButtonController extends ViewController<ToggleButtonControlle
const disabled = this.$props.disabled() || this.el!.hasAttribute('data-disabled');

if (disabled) {
event.preventDefault();
event.stopImmediatePropagation();
return;
}

event.preventDefault();
(this._delegate._onPress ?? this._onPressed).call(this, event);
}

protected _onInteraction(event: Event) {
if (this.$props.disabled()) {
event.preventDefault();
event.stopImmediatePropagation();
}
}
}

0 comments on commit 7c1ce4d

Please sign in to comment.