Skip to content

Commit

Permalink
fix: warn about nested action elements (#3058)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeripeierSBB authored Sep 5, 2024
1 parent 92cf0ca commit 5b1a823
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/elements/core/base-elements/action-base-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ export abstract class SbbActionBaseElement extends LitElement {
return maybeDisabled.disabled || maybeDisabled.formDisabled;
}

public override connectedCallback(): void {
super.connectedCallback();

if (
import.meta.env.DEV &&
(this.hasAttribute('data-link') || this.hasAttribute('data-button')) &&
this.parentElement?.closest('[data-link], [data-button], a, button')
) {
console.warn(
`Nested action element detected (${this.localName} inside ${this.parentElement!.closest('[data-link], [data-button], a, button')!.localName}). Maybe use a static variant for the inner action element?`,
this,
);
}
}

protected setupBaseEventHandlers(): void {
this.addEventListener(
'click',
Expand Down

0 comments on commit 5b1a823

Please sign in to comment.