Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stop_propagation config option to stop click or touch events propagation #904

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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