Skip to content

Commit

Permalink
feat(stop_propagation): Add stop_propagation to stop click or touch e…
Browse files Browse the repository at this point in the history
…vents propagation
  • Loading branch information
Zhephyr54 committed Jan 23, 2025
1 parent 2562b84 commit 342f81b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface ActionHandlerOptions {
hasHold?: boolean;
hasDoubleClick?: boolean;
disabled?: boolean;
stopPropagation?: boolean;
repeat?: number;
repeatLimit?: number;
}
Expand Down Expand Up @@ -138,6 +139,9 @@ class ActionHandler extends HTMLElement implements ActionHandler {
}

element.actionHandler.start = (ev: Event) => {
if (options.stopPropagation) {
ev.stopPropagation();
}
this.cancelled = false;
let x;
let y;
Expand Down Expand Up @@ -171,6 +175,9 @@ class ActionHandler extends HTMLElement implements ActionHandler {
};

element.actionHandler.end = (ev: Event) => {
if (options.stopPropagation) {
ev.stopPropagation();
}
// Don't respond when moved or scrolled while touch
if (['touchend', 'touchcancel'].includes(ev.type) && this.cancelled) {
if (this.isRepeating && this.repeatTimeout) {
Expand Down
1 change: 1 addition & 0 deletions src/button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ class ButtonCard extends LitElement {
.actionHandler=${actionHandler({
hasDoubleClick: this._config!.double_tap_action!.action !== 'none',
hasHold: this._config!.hold_action!.action !== 'none',
stopPropagation: this._config!.stop_propagation,
repeat: this._config!.hold_action!.repeat,
repeatLimit: this._config!.hold_action!.repeat_limit,
})}
Expand Down
2 changes: 2 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ButtonCardConfig {
tap_action?: ActionConfig;
hold_action?: ActionConfig;
double_tap_action?: ActionConfig;
stop_propagation?: boolean;
show_name?: boolean;
show_state?: boolean;
show_icon?: boolean;
Expand Down Expand Up @@ -58,6 +59,7 @@ export interface ExternalButtonCardConfig {
tap_action?: ActionConfig;
hold_action?: ActionConfig;
double_tap_action?: ActionConfig;
stop_propagation?: boolean;
show_name?: boolean;
show_state?: boolean;
show_icon?: boolean;
Expand Down

0 comments on commit 342f81b

Please sign in to comment.