Skip to content

Commit

Permalink
fix(cta): cause ctas to only respond to relevant video events (#12169)
Browse files Browse the repository at this point in the history
* fix(cta): cause ctas to only respond to relevant video events

* fix(cta): only add href where needed

* fix(cta): avoid change to link-list-item-cta

---------

Co-authored-by: Andy Blum <[email protected]>
  • Loading branch information
m4olivei and andy-blum authored Dec 18, 2024
1 parent 62fcdba commit 2720e55
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/web-components/src/components/cta/button-cta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ class C4DButtonCTA extends VideoCTAMixin(CTAMixin(C4DButtonGroupItem)) {
@property({ reflect: true, attribute: 'cta-type' })
ctaType = CTA_TYPE.REGULAR;

/**
* Link `href`.
*/
@property({ attribute: 'href' })
href?: string;

/**
* The formatter for the video caption, composed with the video name and the video duration.
* Should be changed upon the locale the UI is rendered with.
Expand Down
14 changes: 11 additions & 3 deletions packages/web-components/src/components/cta/cta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
formatVideoDuration,
} from '@carbon/ibmdotcom-utilities/es/utilities/formatVideoCaption/formatVideoCaption.js';
import { carbonElement as customElement } from '@carbon/web-components/es/globals/decorators/carbon-element.js';
import { CTA_TYPE } from './defs';

const { stablePrefix: c4dPrefix } = settings;

Expand Down Expand Up @@ -55,6 +56,9 @@ class C4DCTAHead extends HostListenerMixin(StableSelectorMixin(LitElement)) {
@property({ reflect: true })
thumbnail;

@property({ attribute: 'href' })
href?: string;

updated() {
// transpose attributes from parent cta handler to desired cta style
Array.from(this.attributes).forEach((e) => {
Expand All @@ -79,13 +83,17 @@ class C4DCTAHead extends HostListenerMixin(StableSelectorMixin(LitElement)) {
// @ts-ignore: The decorator refers to this method but TS thinks this method is not referred to
private _handleVideoTitleUpdate = async (event: FocusEvent) => {
if (event) {
const { videoDuration, videoName } = event.detail as any;
const { videoDuration, videoName, videoId } = event.detail as any;
const formattedVideoDuration = formatVideoDuration({
duration: !videoDuration ? videoDuration : videoDuration * 1000,
});
this.videoDuration ? null : (this.videoDuration = formattedVideoDuration);

if (this.ctaStyle !== 'card' && this.ctaStyle !== 'feature') {
if (
this.ctaStyle !== 'card' &&
this.ctaStyle !== 'feature' &&
this.ctaType === CTA_TYPE.VIDEO &&
(this as any).href === videoId
) {
const heading = formatVideoCaption({
duration: formattedVideoDuration,
name: videoName,
Expand Down

0 comments on commit 2720e55

Please sign in to comment.