Tucano

Time picker

For when only the time matters: store hours, delivery slot, shift. It's the date picker's columns without the calendar, with the same mask, the same keyboard and the same Apply button. The form gets 14:30, exactly what an <input type="time"> would post.

Examples

Under each field is the value the server receives.

Limits

data-min="08:00" and data-max="18:00": anything outside shows disabled in the columns.

Every 15 minutes

data-minute-step="15" leaves only 00, 15, 30 and 45 in the column.

With seconds

data-seconds="true" adds the third column, and the value comes out as 14:30:15.

Now button

data-now="true" adds "Agora" (now) to the footer: it applies the current time, on the minute step, and closes.

Without Apply

data-auto-apply="true": every click in a column counts right away.

24-hour clock

data-locale="pt-BR" shows 14:30; on an English page the field shows 02:30 PM. The POST is 14:30 either way.

With an error

aria-invalid="true" on the field — Django 5 already writes it.

Closing must be after opening.

How to use

Mark the <input> and it sets itself up on load and on every htmx:afterSwap.

<input type="text" name="opening" data-tuc-timepicker>
<input type="text" name="shift" data-tuc-timepicker data-mode="range">
<input type="text" name="slot" data-tuc-timepicker data-min="08:00" data-max="18:00" data-minute-step="15">
AttributeDefaultWhat for
data-modesinglerange for start and end side by side
data-min data-max—Limits, as hh:mm
data-minute-step5Step of the minutes column; 1 lists them all
data-secondsfalseSeconds column
data-auto-applyfalsetrue drops Apply: every click counts
data-nowfalsetrue adds the Now button, which applies the current time and closes — disabled when now is outside min and max
data-locale<html lang>12- or 24-hour clock
data-iso-namethe namename of the hidden field with the value
data-placementbottom-centerSide and alignment of the panel
data-nativefalsetrue or auto: the system's time picker

In a Django form

class StoreForm(forms.ModelForm):
    class Meta:
        model = Store
        fields = ["opens_at", "closes_at"]
        widgets = {
            "opens_at": forms.TextInput(attrs={"data-tuc-timepicker": ""}),
            "closes_at": forms.TextInput(attrs={"data-tuc-timepicker": "", "data-max": "23:00"}),
        }

Don't use type="time" on the widget: the browser's picker would open on top of ours. TimeField reads 14:30 and 14:30:15 with no setup.

In JavaScript

const tp = new Tucano.TimePicker('#opening', {
  mode: 'range',
  min: '08:00',
  max: '18:00',
  minuteStep: 15,
  onChange: (value, { iso }) => console.log(value, iso),
});

tp.setValue({ start: '09:00', end: '12:30' });
tp.getValue();   // { start: '09:00', end: '12:30' } — in single mode, '14:30' or null
tp.clear();
tp.destroy();

Value and form

As in the date picker, an <input type="hidden"> next to it carries the name and the value in 24-hour time. The visible field may show 02:30 PM; the server always gets 14:30.

POST  opening  = 14:30
POST  exact    = 14:30:15          # with data-seconds
POST  shift    = 09:00,17:30       # start and end, comma-separated

The value is text, not a Date: a time without a day isn't an instant, and a Date would force us to make up a day and a time zone. getValue() and e.detail.value return the same '14:30' as the POST.

Typing

The mask is hh:mm, and the colon goes in on its own. It also reads 1430, 14h30, 14h and 2:30 pm.

The value is confirmed on leaving the field, or with Enter while the panel is open. A time outside min and max isn't accepted, nor pulled to the limit: the field goes back to the previous value. In the columns, though, picking 6 PM with 30 minutes and a max of 18:00 lands on 18:00. In a range, the end you didn't touch follows the other one instead of leaving the start after the end.

Keyboard and accessibility

The same as the date picker's time columns. Arriving by Tab doesn't open the panel.

KeyWhereAction
↓FieldOpens the panel with focus on the hours column
SpaceEmpty fieldOpens the panel
EnterField, panel openConfirms what was typed and closes
↑ ↓ColumnPrevious and next value, skipping disabled ones
Home EndColumnFirst and last value that counts
Enter SpaceColumnPicks the value
TabInside the panelFrom one column to the next and to the buttons; each column is a single stop
EscField or panelCloses, discards what wasn't applied and returns focus to the field

API

Generated from the code on every build — if something is not here, it does not exist.

Markup
[data-tuc-timepicker]
In JS
new Tucano.TimePicker(alvo, opcoes)
Attributes
data-auto-apply data-iso-name data-locale data-max data-min data-minute-step data-mode data-native data-now data-placement data-seconds
Methods
getValue setValue clear open close toggle destroy
Events
tucano:change

Options

The notes in this table come from comments in the source code, which are written in Portuguese.

OptionDefaultWhat for
mode'single''single' | 'range' (inicio e fim lado a lado)
secondsfalse
minuteStep5
localeundefineddefault: locale do documento/navegador; decide 24 h ou AM/PM
minnull'08:00': as horas antes ficam desativadas nas colunas
maxnull'18:00'
autoApplyfalsetrue: cada clique numa coluna ja vale, sem o Aplicar
clearabletrue
nowfalsebotao "Agora" no rodape: aplica a hora atual e fecha. Opt-in
placement'bottom-center'
appendToundefined
isoNameundefinedname do input hidden com o valor HH:MM
nativefalsetrue ou 'auto': o seletor de hora do sistema no celular
onChangenull
onOpennull
onClosenull