Skip to content

Commit

Permalink
fix(cta): remove deprecated public getter (#1767)
Browse files Browse the repository at this point in the history
* fix(cta): remove deprecated public getter

* chore(cta): add changeset

* refactor(cta): remove private getter

* docs: changesset

---------

Co-authored-by: Benny Powers <[email protected]>
  • Loading branch information
zeroedin and bennypowers authored Aug 20, 2024
1 parent 347d29e commit 12a8f75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-dragons-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rhds/elements": patch
---

`<rh-cta>`: removed deprecated read-only `cta` property; use `data-analytics` attributes instead
22 changes: 5 additions & 17 deletions elements/rh-cta/rh-cta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,6 @@ export class RhCta extends LitElement {
return super.getUpdateComplete();
}

/**
* The slotted `<a>` or `<button>` element
* @deprecated use `data-analytics-` attributes instead
*/
public get cta(): HTMLAnchorElement | HTMLButtonElement | null {
return this.#cta;
}

get #cta() {
return (
this.shadowRoot?.querySelector('a')
?? this.shadowRoot?.querySelector('slot')?.assignedElements().find(isSupportedContent)
?? null
);
}

/** Is the element in an RTL context? */
#dir = new DirController(this);

Expand Down Expand Up @@ -189,7 +173,11 @@ export class RhCta extends LitElement {

override firstUpdated() {
const { href, variant } = this;
const cta = this.#cta;
const cta =
this.shadowRoot?.querySelector('a')
?? this.shadowRoot?.querySelector('slot')?.assignedElements().find(isSupportedContent)
?? null;

if (href && cta !== this.shadowRoot?.querySelector('a')) {
return this.#logger.warn(`When the href attribute is used, slotted content must not be a link`);
} else if (!href && !cta) {
Expand Down

0 comments on commit 12a8f75

Please sign in to comment.