Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions packages/vidstack/src/components/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,15 @@ export class MediaPlayer
#skipTitleUpdate = false;
#watchTitle() {
const el = this.$el,
{ ariaLabel } = this.$props,
{ title, live, viewType, providedTitle } = this.$state,
isLive = live(),
type = uppercaseFirstChar(viewType()),
typeText = type !== 'Unknown' ? `${isLive ? 'Live ' : ''}${type}` : isLive ? 'Live' : 'Media',
currentTitle = title();
currentTitle = title(),
label = ariaLabel() || `${typeText} Player` + (currentTitle ? ` - ${currentTitle}` : '');

setAttribute(
this.el!,
'aria-label',
`${typeText} Player` + (currentTitle ? ` - ${currentTitle}` : ''),
);
setAttribute(this.el!, 'aria-label', label);

// Title attribute is removed to prevent popover interfering with user hovering over player.
if (!__SERVER__ && el?.hasAttribute('title')) {
Expand Down
8 changes: 8 additions & 0 deletions packages/vidstack/src/core/api/player-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { MediaLoadingStrategy, MediaPosterLoadingStrategy } from './types';
export const mediaPlayerProps: MediaPlayerProps = {
artist: '',
artwork: null,
ariaLabel: '',
autoplay: false,
autoPlay: false,
clipStartTime: 0,
Expand Down Expand Up @@ -58,6 +59,8 @@ export interface MediaStateAccessors extends Pick<

export type PlayerSrc = MediaSrc | MediaSrc[];

export type MediaPlayerAriaLabel = string;

export interface MediaPlayerProps
// Prefer picking off the `MediaStore` type to ensure docs are kept in-sync.
extends Pick<
Expand All @@ -84,6 +87,11 @@ export interface MediaPlayerProps
| 'liveEdgeTolerance'
| 'minLiveDVRWindow'
> {
/**
* A custom ARIA label for the player root. By default, the player will generate a label using
* the current media type, live state, and title.
*/
ariaLabel: MediaPlayerAriaLabel;
/** @deprecated - Use `autoPlay` */
autoplay: boolean;
/** @deprecated - Use `crossOrigin` */
Expand Down
1 change: 1 addition & 0 deletions packages/vidstack/src/elements/define/player-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class MediaPlayerElement extends Host(HTMLElement, MediaPlayer) {
static tagName = 'media-player';

static override attrs: Attributes<MediaPlayerProps> = {
ariaLabel: 'aria-label',
autoPlay: 'autoplay',
crossOrigin: 'crossorigin',
playsInline: 'playsinline',
Expand Down
Loading