Skip to main content
Version: Next 🚧

DurationPicker

DurationPicker picks a length of time, such as a timer, a workout, a cooking time or a reminder: hours, minutes and optionally seconds, each with its unit beside it. It looks native on each platform: wheels like the iOS countdown timer, number boxes to type into in Material, columns to click on the web, or the one you pick with display. The value is a number of seconds.

For a time of day (an alarm at 7:30 AM), use TimePicker. A duration has no AM/PM and no locale clock, its hours don't wrap at midnight, and its limits are lengths, not times.

import { DurationPicker } from '@elik56a/react-native-pickers';
Loading…
<>
  <DurationPicker value={seconds} onChange={setSeconds} />
  <Text style={{ textAlign: 'center', color: '#6E685E' }}>
    {seconds} s = {formatDuration(seconds)}
  </Text>
</>

Try the props​

Platform
display
minuteInterval
variant
<DurationPicker value={seconds} onChange={setSeconds} />

The value is in seconds​

value, defaultValue and onChange use a number of seconds: 5400 is 1 h 30 min. Store it as is, or turn it into text with formatDuration. Without value or defaultValue, the picker starts at 0.

Wheels, boxes or columns​

Each design has its own default:

displayDefault inWhat it is
'wheel'iOSHours, minutes and seconds wheels with their units at the selection band, like the iOS countdown timer
'input'MaterialA box per unit to type the number into, as in Material's time input. A number that isn't one of the steps yet (3 on the way to 30 with minuteInterval={15}) waits for the next digit
'list'webA column of cells per unit under its label, the chosen one filled, as in TimePicker on the web
<DurationPicker value={seconds} onChange={setSeconds} display="wheel" />

Hours, minutes and seconds​

Hours and minutes show by default. showSeconds adds a seconds wheel, and showHours={false} drops the hours, so the minutes count past 59 (up to 90 for a 90-minute run):

Loading…
<DurationPicker value={rest} onChange={setRest} showHours={false} showSeconds secondInterval={5} />

Min, max and intervals​

min and max are in seconds. Values outside them are dimmed, and a combination that lands outside (such as 2 h with 45 min while the max is 2 h) is pulled back to the nearest limit. Without max, the hours go up to 23, or the minutes up to 59 without hours.

minuteInterval and secondInterval show every n-th minute or second. A value between steps shows rounded down, and DurationPickerSheet confirms what the wheels show.

Loading…
<DurationPicker value={workout} onChange={setWorkout} min={10 * 60} max={3 * 3600} minuteInterval={5} />

Unit labels and other languages​

labels sets the unit beside each wheel, box or column and in the field text. Screen readers read each one as "Hours", "Minutes" or "Seconds", followed by its value.

Loading…
<DurationPicker value={seconds} onChange={setSeconds} labels={GERMAN} />

formatDuration​

Turns seconds into the field's text: the units that aren't zero, exact to the second.

formatDuration(5400); // '1 h 30 min'
formatDuration(95); // '1 min 35 s'
formatDuration(5400, { showHours: false }); // '90 min'
formatDuration(0); // '0 min'

It takes showHours and labels, like the picker.

In a sheet​

import { DurationPickerSheet } from '@elik56a/react-native-pickers';

<DurationPickerSheet visible={open} onClose={() => setOpen(false)} title="Timer" value={seconds} onConfirm={setSeconds} />

It takes the shared sheet props and the picker's, and keeps a draft until Done, like the other picker sheets.

In a form field​

DurationPickerField opens the sheet and shows the confirmed duration, like 1 h 30 min. Switch presentation in the panel: auto opens a dropdown under the field on the web and a bottom sheet on iOS and Android.

Platform
presentation
<DurationPickerField
label="Timer"
placeholder="Set a timer"
minuteInterval={5}
value={seconds}
onConfirm={setSeconds}
/>

→ Picker fields

Props​

PropTypeDefaultDescription
valuenumber—Selected duration in seconds (controlled).
defaultValuenumber0Initial duration when uncontrolled.
onChange(seconds: number) => void—Fires when any wheel settles.
onValueChanging(seconds: number) => void—Fires on every tick while scrolling (haptics).
display'wheel' | 'input' | 'list'from the designWheels (iOS), boxes to type into (Material), or columns to click (web).
showHoursbooleantrueShow the hours wheel. Without it, minutes count past 59.
showSecondsbooleanfalseAdd a seconds wheel.
minnumber0Shortest selectable duration, in seconds.
maxnumber23 h 59 min 59 s, or 59 min 59 s without hoursLongest selectable duration, in seconds.
minuteIntervalnumber1Minute step: 1, 5, 15…
secondIntervalnumber1Second step.
labels{ hours?, minutes?, seconds? }{ hours: 'h', minutes: 'min', seconds: 's' }Units beside the wheels and in the field.
loopbooleantrueLoop the minute and second wheels. Hours never loop.
itemHeightnumber40Wheel row height.
visibleItemsnumber5Visible wheel rows, or cells in a column.
variant'3d' | 'flat''3d'Wheel style.
styleStyleProp<ViewStyle>—Container style.
stylesSlotStyles<MultiWheelSlot>—MultiWheelPicker slots, for the wheels. The separator slot styles their unit labels.
themeDeepPartial<PickerTheme>—Theme override.
design'ios' | 'material' | 'web'from PickersProviderThe look to follow, over the provider's: iOS, Material or web.
testIDstring—Test ID. Each wheel, box or column gets ${testID}-hours, -minutes and -seconds.

DurationPickerSheet takes these plus the sheet props and onConfirm(seconds). DurationPickerField takes the sheet's props plus the field props.