Skip to content

Commit

Permalink
Merge branch 'staging/charmander' into feat/cta/href
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers committed Jun 18, 2024
2 parents db2dcad + 655aec0 commit 540da8a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .changeset/few-buckets-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@rhds/elements": patch
---
`<rh-cta>`: lazy-load the icon component dependency
10 changes: 2 additions & 8 deletions elements/rh-cta/rh-cta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ import { colorContextConsumer, type ColorTheme } from '../../lib/context/color/c

import style from './rh-cta.css';

import '@patternfly/elements/pf-icon/pf-icon.js';

function isSupportedContent(el: Element | null): el is HTMLAnchorElement | HTMLButtonElement {
return el instanceof HTMLAnchorElement || el instanceof HTMLButtonElement;
}

function isButton(element: Element | null): element is HTMLButtonElement {
return element?.tagName.toLowerCase() === 'button';
}

/**
* A call to action is a styled link that entices users to make a selection.
* @summary Directs users to other pages or displays extra content
Expand Down Expand Up @@ -211,9 +205,9 @@ export class RhCta extends LitElement {
const cta = this.#cta;
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 && !isSupportedContent(cta) && !href) {
} else if (!href && !cta) {
return this.#logger.warn(`The first child in the light DOM must be a supported call-to-action tag (<a>, <button>)`);
} else if (!href && isButton(cta) && !variant) {
} else if (!href && cta instanceof HTMLButtonElement && !variant) {
return this.#logger.warn(`Button tag is not supported semantically by the default link styles`);
}
}
Expand Down

0 comments on commit 540da8a

Please sign in to comment.