Skip to content
FrameworkStyle

media-cast-button

Accessible Cast toggle button with state reflection and keyboard support

Anatomy

<media-cast-button></media-cast-button>

Behavior

Toggles a Google Cast session. Clicking the button while disconnected opens the Cast device picker; clicking while connected ends the session.

The button derives its presentation from availability:

  • "unsupported" — the HTML custom element receives the native hidden attribute; the React component returns null.
  • "unavailable" — the button remains visible and focusable with aria-disabled="true" and data-disabled, but does not open the picker. This lets a tooltip explain that no Cast device is reachable.
  • "available" — the button is fully interactive unless the disabled prop is set.

Cast sessions come from the Google Cast component. Add it to the player next to your media element; without it the button drives the browser’s native Remote Playback API instead, which offers no receiver or load-request configuration.

Styling

Style based on cast and disabled state:

/* During an active session */
media-cast-button[data-cast-state="connected"] {
  color: blue;
}

/* Cast is supported, but no device is reachable */
media-cast-button[data-disabled] {
  cursor: not-allowed;
  opacity: 0.5;
}

Unsupported buttons are hidden automatically. No availability selector or extra hiding CSS is required.

Accessibility

Renders a <button> with an automatic aria-label:

Cast state Default label
'disconnected' “Start casting”
'connecting' “Connecting”
'connected' “Stop casting”

Override with the label prop. Keyboard activation: Enter / Space.

Examples

Basic Usage

Stop casting Start casting
<video-player class="video-player">
    <media-container>
        <hlsjs-video
            src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM.m3u8"
            autoplay
            muted
            playsinline
            loop
        ></hlsjs-video>
        <media-cast-button class="media-cast-button">
            <span class="connected">Stop casting</span>
            <span class="disconnected">Start casting</span>
        </media-cast-button>
    </media-container>
</video-player>

API Reference

Props

PropTypeDefaultDetails
disabledbooleanfalse
labelText | string | Text) | function''

State

State is reflected as data attributes for CSS styling.

PropertyTypeDetails
connection'disconnected' | 'connecting' | 'conn...
availability'available' | 'unavailable' | 'unsupp...
disabledboolean
hiddenboolean
labelText | string

Data attributes

AttributeTypeDetails
data-cast-state'disconnected' | 'connecting' | 'conn...
data-availability'available' | 'unavailable' | 'unsupp...
data-disabled
data-hidden