Skip to content

Commit

Permalink
fix: warn about nested action elements
Browse files Browse the repository at this point in the history
  • Loading branch information
jeripeierSBB committed Sep 5, 2024
1 parent 92cf0ca commit 77aaee0
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')

Check warning on line 32 in src/elements/core/base-elements/action-base-element.ts

View check run for this annotation

Codecov / codecov/patch

src/elements/core/base-elements/action-base-element.ts#L32

Added line #L32 was not covered by tests
) {
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,
);
}

Check warning on line 38 in src/elements/core/base-elements/action-base-element.ts

View check run for this annotation

Codecov / codecov/patch

src/elements/core/base-elements/action-base-element.ts#L34-L38

Added lines #L34 - L38 were not covered by tests
}

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

0 comments on commit 77aaee0

Please sign in to comment.