Skip to content

Media time slider

Pro

A media player's position bar: where playback is, what has loaded, and the time under the pointer, to seek by pointer, touch and keyboard. Not an M3 component (@windmorph/react-pro).

import { MediaTimeSlider } from '@windmorph/react-pro';

Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.

Props

By name or description, across the 19 props below

MediaTimeSlider 19 props

  • durationtype numberRequired

    The media's length in seconds. Until it is known (0 or NaN, as a media element's duration before its metadata loads), and for a live stream with no end (Infinity), the slider can't be moved and leaves the Tab order (aria-disabled): focus already on it stays, as the next media loads.

    A new media's length goes unknown while it loads (a media element's duration is NaN until its metadata comes): that lets go of anything held for the last one, so pass the element's duration as it is, rather than keeping the old length meanwhile (keep the slider mounted, too: a new key would drop focus on it to the page). A known length that changes, as a stream's grows, lets go of a position held after a seek, never of a drag.

  • valuetype number

    The position in seconds (controlled).

  • defaultValuetype numberdefault 0

    The first position in seconds when uncontrolled.

  • bufferedtype MediaTimeSliderBuffered

    What has loaded: drawn over the bar, behind the played part.

  • steptype numberdefault 5

    Seconds an arrow key moves. Page Up and Page Down move a tenth of the length, Home and End go to the start and the end, and a drag moves freely.

  • disabledtype booleandefault false

    Turns the slider off: it can't be moved or focused.

  • formatTimetype ((seconds: number) => string)default m:ss, or h:mm:ss for an hour or longer, in the locale's digits

    The bubble's time, laid out left to right as the bar is: return a time, not a sentence in a right-to-left script.

  • valueTexttype ((seconds: number, duration: number, chapter?: string) => string)default the labels.position words, as "1 minute, 23 seconds of 10 minutes"

    The position in words for screen readers (aria-valuetext); labels.unknownLength while the length isn't known. While the slider has focus, its value and words stay where the person last put them, so playback doesn't have screen readers say the time every second; they follow playback again once focus leaves.

  • chapterstype readonly MediaTimeSliderChapter[]

    The media's chapters: the bar breaks at each start (chapter-gap), the played gradient running across the breaks as one; the chapter under the pointer grows a step; the bubble shows its title, and the position's words name it. Starts at or past the length are left out, and starts closer than chapter-min-width merge.

  • idtype string

    The id of the root, the slider's group.

  • reftype Ref<HTMLDivElement>

    The root element.

Events

  • onChangetype ((seconds: number) => void)

    Called as the position moves: on every move of a drag, and for each key. While dragged, and after a seek until value comes within a second of where it was put (two seconds at most, for a seek the player refused), the slider shows the position it was moved to, so the player's time updates never pull the handle back.

  • onChangeEndtype ((seconds: number) => void)

    Called when a drag ends, a key changes the position or a screen reader steps it: the moment to seek.

Text

  • labelstype Partial<MediaTimeSliderLabels>

    Its words, for translation. A LabelsProvider sets them for the whole app.

  • aria-labeltype string

    Accessible name when there's no visible label ("Position", "Seek").

    One of aria-label or aria-labelledby is required.

  • aria-labelledbytype string

    The id of the visible label that names the slider.

    One of aria-label or aria-labelledby is required.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Types

MediaTimeRanges 3 fields

A media element's buffered (TimeRanges), or anything shaped like it.

  • lengthtype numberRequired
  • starttype (index: number) => numberRequired
  • endtype (index: number) => numberRequired

MediaTimeSliderChapter 2 fields

A chapter of the media: where it starts, and its title.

  • starttype numberRequired

    Its start, in seconds; the first starts at 0.

  • titletype string

    Its title, shown over the time in the bubble and said with the position.

Spec status

Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.

  • The position, the loaded ranges and the time under the pointer

    Built

    Configuration · States

  • An hour-long media (h:mm:ss) and a length not known yet

    Built

    Configuration · States

  • A player that seeks on onChangeEnd

    Built

    Use case · Player

  • Over a video, in a dark ThemeScope

    Built

    Use case · Video

  • Built to the M3 slider, for media

    Extension

    M3 has no media components and its slider tracks start at 16px; this one is a 4px bar that grows to 8px with a handle while active, in the slider’s colour roles and springs, with a 48px target and the core slider’s touch handling.

Theming & tokens

Set the tokens below on the slider or any ancestor; over a video, a dark ThemeScope round the controls is usually all it needs. The bubble is the core's plain tooltip, themed by its own --md-comp-plain-tooltip-* tokens. className goes on the root, the 48px target; style each part with classNames: root, parts, track, buffered, played, hover, thumb, bubbleAnchor, bubble.

MediaTimeSlider tokens
VariableDefaultPaints
--wm-media-time-slider-track-height4pxThe bar’s thickness at rest.
--wm-media-time-slider-track-height-active8pxThe bar’s thickness under the pointer, while dragged or keyboard-focused.
--wm-media-time-slider-track-cornervar(--md-sys-shape-corner-full)The bar’s corners.
--wm-media-time-slider-track-colorcolor-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent)The part not yet played or loaded.
--wm-media-time-slider-buffered-colorcolor-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent)The loaded parts (`buffered`), drawn over the bar.
--wm-media-time-slider-played-colorvar(--md-sys-color-primary)The played part, from the start to the position.
--wm-media-time-slider-played-color-endvar(--_wm-media-time-slider-played-color)The played part’s colour at the position: another colour makes the played part a gradient across its length, so this colour is always at the playhead (the same as `played-color` by default: solid).
--wm-media-time-slider-played-blend-start55%How far along the played part the gradient begins: `played-color` until there, then blending to `played-color-end` at the position.
--wm-media-time-slider-underlay-colortransparentA ground under the bar alone, the bar’s size, so a see-through track over a picture keeps its contrast with the played part (a player sets it).
--wm-media-time-slider-chapter-gap4pxThe break in the bar at each chapter’s start.
--wm-media-time-slider-chapter-min-width4pxThe narrowest a chapter is drawn; starts closer than this merge.
--wm-media-time-slider-chapter-height-hover10pxThe thickness of the chapter under the pointer, or under the handle while dragged or keyboard-focused, a step past the active bar.
--wm-media-time-slider-hover-colorcolor-mix(in srgb, var(--md-sys-color-primary) 38%, transparent)The stretch from the played part to a mouse, trackpad or pen over the bar, where a press would land (`transparent` turns it off).
--wm-media-time-slider-thumb-size16pxThe handle’s diameter while active.
--wm-media-time-slider-thumb-size-rest0pxThe handle’s dot at rest, so a paused player can show where it is (0, no dot, by default); it grows to `thumb-size` while active.
--wm-media-time-slider-thumb-colorvar(--_wm-media-time-slider-played-color)The handle’s dot (its `::before`).
--wm-media-time-slider-bubble-gap8pxThe space between the time bubble and the active bar.
--wm-media-time-slider-spring-durationvar(--md-sys-motion-spring-spatial-fast-duration)How long the bar takes to grow and the handle to appear (the fast spatial spring; at once under reduced motion).
--wm-media-time-slider-spring-easingvar(--md-sys-motion-spring-spatial-fast-easing)Their easing.