Skip to content
FrameworkStyle

CaptionsRadioGroup

A menu radio group for selecting caption and subtitle tracks

Creates radio items from the player text track state and selects the showing caption or subtitle track.

Import

import { CaptionsRadioGroup } from '@videojs/react/ui/captions-radio-group';

Anatomy

<CaptionsRadioGroup.Root>
  <Menu.Trigger>
    <CaptionsRadioGroup.Value />
  </Menu.Trigger>
  <Menu.Content>
    <CaptionsRadioGroup.Options
      renderItem={(props, item) => (
        <Menu.RadioItem {...props}>
          {item.label}
          <Menu.ItemIndicator checked={item.checked} />
        </Menu.RadioItem>
      )}
    />
  </Menu.Content>
</CaptionsRadioGroup.Root>

Behavior

The group is available when the configured media exposes at least one caption or subtitle track. The first generated option is Off; selecting it hides captions. Track labels use the track label, then language, then kind. Pass formatTrack to customize the visible labels.

CaptionsRadioGroup.Root uses useCaptionsOptions to own selection and renders no element. Wrap the menu’s Menu.Trigger and Menu.Content in it so the trigger inherits the group’s disabled and hidden state and exposes data-availability. CaptionsRadioGroup.Options renders the items, including Off: its required renderItem callback renders the Menu.RadioItem root and receives item state containing the translated label and current checked value. CaptionsRadioGroup.Value displays the selected label, typically inside the trigger. Options and Value render null when the text tracks feature is not configured.

The CaptionsRadioGroup export from the @videojs/react root is a compatibility component that composes Root and Options behind the former single-component props. Prefer the parts for new code.

Styling

Attribute Values Description
data-active Present / absent Present when captions are enabled.
data-disabled Present / absent Present when track selection is disabled.
data-hidden Present / absent Present when caption or subtitle tracks are unavailable.
data-availability "available" / "unavailable" Whether caption or subtitle tracks are available.

Unavailable groups receive the native hidden attribute.

Accessibility

The group uses the menu radio group pattern.

CaptionsRadioGroup.Options receives its accessible label from the label prop on CaptionsRadioGroup.Root or defaults to Captions. Override it with aria-label or aria-labelledby on CaptionsRadioGroup.Options.

Examples

Basic usage

import { Container, createPlayer, Menu } from '@videojs/react';
import { CaptionsRadioGroup } from '@videojs/react/ui/captions-radio-group';
import { Video, videoFeatures } from '@videojs/react/video';
import type { ReactNode } from 'react';

const { Player } = createPlayer({ features: videoFeatures });

function CaptionsMenu(): ReactNode {
  return (
    <Menu.Root side="top" align="end">
      <CaptionsRadioGroup.Root>
        <Menu.Trigger className="settings-trigger" render={<button type="button" />}>
          Captions
          <CaptionsRadioGroup.Value className="menu-hint" />
        </Menu.Trigger>
        <Menu.Popup className="menu">
          <Menu.Content>
            <CaptionsRadioGroup.Options
              className="menu-group"
              renderItem={(props, item) => (
                <Menu.RadioItem {...props} className="menu-item">
                  {item.label}
                  <Menu.ItemIndicator checked={item.checked} forceMount className="menu-indicator">

                  </Menu.ItemIndicator>
                </Menu.RadioItem>
              )}
            />
          </Menu.Content>
        </Menu.Popup>
      </CaptionsRadioGroup.Root>
    </Menu.Root>
  );
}

export default function BasicUsage() {
  return (
    <Player>
      <Container className="media-container">
        <Video src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4" autoPlay muted playsInline loop>
          <track kind="captions" src="/docs/demos/captions-button/captions.vtt" srcLang="en" label="English" />
          <track kind="subtitles" src="/docs/demos/captions-button/captions.vtt" srcLang="es" label="Spanish" />
        </Video>
        <div className="menu-bar">
          <CaptionsMenu />
        </div>
      </Container>
    </Player>
  );
}

API Reference

Root

Owns captions option state and shares it with an enclosing menu. Does not render a DOM element.

Props

PropTypeDefaultDetails
disabledbooleanfalse
formatTrackstring) | functionformatTrackLabel
labelobject''

State

State is accessible via the render, className, and style props.

PropertyTypeDetails
subtitlesShowingboolean
label{ key: string; text: string } | string
valuestring
optionsreadonly Option[]
disabledboolean
hiddenboolean
availability'available' | 'unavailable'

Data attributes

AttributeTypeDetails
data-active
data-disabled
data-hidden
data-availability'available' | 'unavailable'

Options

Renders menu radio items for the player's captions and subtitles tracks.

Props

PropTypeDefaultDetails
classNamestring | ((state: CaptionsRadioGroupCore.State) => string | undefined)
renderReactElement | ((props: HTMLProps, state: CaptionsRadioGroupCore.State) => ReactElement | null)
renderItem((props: CaptionsRadioGroupItemProps, state: CaptionsRadioGroupItemState) => ReactElement)
styleCSSProperties | ((state: CaptionsRadioGroupCore.State) => CSSProperties | undefined)

Value

Displays the selected captions label.

Props

PropTypeDefaultDetails
classNamestring | ((state: CaptionsOptionsResult) => string | undefined)
renderReactElement | ((props: HTMLProps, state: CaptionsOptionsResult) => ReactElement | null)
styleCSSProperties | ((state: CaptionsOptionsResult) => CSSProperties | undefined)