Skip to content

Commit

Permalink
fix: <media-live-button/> setting attr in constructor (#696)
Browse files Browse the repository at this point in the history
`setAttribute` was accidentally used in the constructor. I've moved the
logic to a function similarly to other elements.
  • Loading branch information
evoactivity authored Jul 24, 2023
1 parent d944d66 commit c99eb1c
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/js/media-live-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ slotTemplate.innerHTML = /*html*/`
<slot name="spacer">&nbsp;</slot><slot name="text">LIVE</slot>
`;

const updateAriaAttributes = (el) => {
const isPausedOrNotLive = el.mediaPaused || !el.mediaTimeIsLive
const label = isPausedOrNotLive ? verbs.SEEK_LIVE() : verbs.PLAYING_LIVE();
el.setAttribute('aria-label', label);

isPausedOrNotLive ?
el.removeAttribute('aria-disabled') :
el.setAttribute('aria-disabled', 'true');
};

/**
* @slot indicator - The default is an SVG of a circle that changes to red when the video or audio is live. Can be replaced with your own SVG or font icon.
* @slot spacer - A simple text space (&nbsp;) between the indicator and the text.
Expand All @@ -63,19 +73,16 @@ class MediaLiveButton extends MediaChromeButton {

constructor(options = {}) {
super({ slotTemplate, ...options });
this.setAttribute('aria-label', verbs.SEEK_LIVE());
}

connectedCallback() {
updateAriaAttributes(this);
super.connectedCallback();
}

attributeChangedCallback(attrName, oldValue, newValue) {
super.attributeChangedCallback(attrName, oldValue, newValue);

if (this.mediaPaused || !this.mediaTimeIsLive) {
this.setAttribute('aria-label', verbs.SEEK_LIVE());
this.removeAttribute('aria-disabled');
} else {
this.setAttribute('aria-label', verbs.PLAYING_LIVE());
this.setAttribute('aria-disabled', 'true');
}
updateAriaAttributes(this);
}

/**
Expand Down

1 comment on commit c99eb1c

@vercel
Copy link

@vercel vercel bot commented on c99eb1c Jul 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.