Skip to main content

Countdown

Real-time countdown driven by wall-clock deltas (no drift after background switches), with controlled direct display and uncontrolled self-driving modes, and format tokens DD / HH / mm / ss / S.

Basic usage​

Basic usage
02:00:0001:3001天02:00:01.500
00:01:05受控直显:65000ms(组件不自驱动)
import { LhCountdown } from '@lh-ui/react'

export default function Demo() {
return <LhCountdown time={2 * 3600 * 1000} />
}

Countdown Props​

PropDescriptionTypeOptionsDefault
valueRemaining ms (controlled direct display: the component does not self-drive)number——
timeUncontrolled total duration ms (auto-starts on mount when autoStart)number——
formatFormat string (tokens DD/HH/mm/ss/S; without DD, HH carries total hours)string—'HH:mm:ss'
autoStartAuto-start on mount in uncontrolled modeboolean—true
millisecondPer-frame updates (recommended when showing milliseconds)boolean—false
disabledDisabled (greyed and pauses ticking)boolean—false
ariaLabelAccessible name (falls back to formatted text)string——
onChangeRemaining ms changed (each tick in uncontrolled mode)(value: number) => void——
onFinishCountdown reached zero() => void——
sxShorthand layout propsSxProps——

Ref (LhCountdownInstance)​

MethodDescription
start()Start / resume (continues from the paused point)
pause()Pause (keeps the remaining time)
reset()Reset to the time total (restarts immediately when autoStart)
Clock semantics

Remaining time is computed from wall-clock deltas (target wall clock − now), never by accumulated subtraction — background switching and timer throttling cause no drift; enable millisecond when showing milliseconds (16ms steps).

Accessibility

The root element is role="timer" with the accessible name taken from ariaLabel or the formatted text; digits use tabular figures (tabular-nums) so ticking does not jitter.

Styles​

import '@lh-ui/react/style/countdown'