Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

fix(button): prevent event propagation to children of disabled buttons #712

Merged
merged 1 commit into from
Oct 11, 2021
Merged
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
13 changes: 12 additions & 1 deletion src/components/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import ifNonNull from '../../globals/directives/if-non-null';
import FocusMixin from '../../globals/mixins/focus';
import { BUTTON_KIND, BUTTON_SIZE, BUTTON_ICON_LAYOUT } from './defs';
import styles from './button.scss';
import HostListener from '../../globals/decorators/host-listener';
import HostListenerMixin from '../../globals/mixins/host-listener';

export { BUTTON_KIND, BUTTON_SIZE, BUTTON_ICON_LAYOUT };

Expand All @@ -25,7 +27,7 @@ const { prefix } = settings;
* @csspart button The button.
*/
@customElement(`${prefix}-btn`)
class BXButton extends FocusMixin(LitElement) {
class BXButton extends HostListenerMixin(FocusMixin(LitElement)) {
/**
* `true` if there is an icon.
*/
Expand All @@ -48,6 +50,15 @@ class BXButton extends FocusMixin(LitElement) {
this.requestUpdate();
}

@HostListener('click', { capture: true })
// @ts-ignore
private _handleDisabledClick(event: Event) {
const { disabled } = this;
if (disabled) {
event.stopPropagation();
}
}

/**
* `true` if the button should have input focus when the page loads.
*/
Expand Down