Skip to content

Period picker with tabs: day, week, month, quarter, year ​

One block for every filter of a dashboard. The reader chooses the kind of period on a tab, then the period. The value is always a first and a last day, so your query stays the same.

The code ​

import { createDatePicker } from '@nervure/datetime';

createDatePicker('#field', {
  mode: 'period',
  compare: true,
  onChange: (selection) => console.log(selection.value, selection.start, selection.end),
});

The value is { start: '2026-10-01', end: '2026-12-31' }. Read the guide for every option, and see every example.

What it does ​

  • Tabs: day, week, month, quarter, year, free range. Show only some with granularities.
  • A ready-made period goes to its tab: "Last year" opens the year tab.
  • The pick stays when the tab changes: 4 December becomes December, then 2026.
  • compare gives the period to compare with: the same period last year, or the period just before.
  • The selection gives start and end as instants in the time zone, and granularity.

Why this one ​

  • No dependency, about 18 kB gzipped for every mode, zone and language.
  • Values are ISO 8601 text. Each selection also gives two instants, start and end, in the time zone.
  • 28 languages and right to left. Keyboard and screen readers.
  • Your CSS and your colours, through CSS variables. Light and dark.
  • The same picker in plain JavaScript, as a web component, in React and in Vue.