Skip to content

Date Range Picker

Start/end range with a presets rail, fiscal-year helpers, and a BS/AD switch. It accepts the familiar daterangepicker.js option shape (ranges, opens, drops, autoApply, linkedCalendars), so an existing integration usually ports across with no rewrite.

Framework
— pick a value to see the result —
Options
All options
OptionTypeDefaultDescription
mode'BS' | 'AD''BS'Calendar system the range opens in.
allowModeTogglebooleantrueShow the BS/AD swap button on the input.
value / defaultValue{ start, end } | null— (empty)Controlled / initial range. Empty until set (or use defaultPresetId).
presetsPresetDefinition[] | 'default' | false'default'Quick-range rail (includes 'Pick a Month'); false hides it.
defaultPresetIdstring | nullPreset highlighted when the popup opens.
fiscalStartMonthnumber (1–12)4BS month the fiscal year starts (Shrawan = 4).
autoApplybooleanfalseCommit on the second click instead of an Apply button.
minDate / maxDateDate | 'today' | '-1y'Earliest / latest selectable day.
disabledWeekdaysnumber[][]Grey-out weekdays (0 = Sunday … 6 = Saturday).
maxRangeSpanDaysnumber | nullReject ranges longer than N days.
autoUpdateInputbooleantrueWrite the applied range back into the input text.
allowInputbooleantrueType the range in a segmented `YYYY-MM-DD – YYYY-MM-DD` field (focus selects a section, ↑/↓ step, digits auto-advance, Backspace clears). Set false for read-only.
displayFormatstringYYYY-MM-DDdayjs-style tokens for each bound.
valueFormat'iso' | 'iso-bs' | 'timestamp' | 'date-object' | { calendar, format }'iso'Shape of the machine value sent to the server — AD ISO by default, stable no matter the display calendar/format. Exposed on onChange/events and written to altField/submitName.
submitNamestring | { start, end }Inject hidden field(s) carrying the machine value(s). A string writes a single `start,end` field; `{ start, end }` writes two named fields.
altFieldstring | HTMLElement | { start, end }Write the machine value(s) into existing field(s) — one combined, or a start/end pair.
altFormatValueFormatvalueFormatOverride the format used for altField / submitName only.
clearablebooleantrueShow a × button to clear the current value.
appendTostring | HTMLElementdocument.bodyWhere the popup portal is mounted.
opens'left' | 'right' | 'center' | 'auto''auto'Horizontal alignment of the popup relative to the input.
drops'down' | 'up' | 'auto''auto'Whether the popup opens below or above the input.
adapterCalendarAdapterbuilt-inSwap the BS↔AD conversion engine (advanced).
Events & callbacks
NamePayloadFires when
onApplyDateRangeResultA full start→end range was applied.
onChange{ start?, end? }Partial change while picking (first click / preset).
onOpen()Fires when the popup is shown.
onClose()Fires when the popup is hidden.
apply.nepaliDateRangePickerCustomEvent<DateRangeResult>Bubbling DOM event dispatched on the input.
import { mountDateRangePicker } from 'nepali-datepicker-pro';
import 'nepali-datepicker-pro/style.css';

mountDateRangePicker(document.querySelector('#picker'), {});
Real-world example — Report filter

Nepali fiscal year presets (Shrawan start), submits the applied range as two AD ISO fields your backend can drop straight into a BETWEEN query.

import { mountDateRangePicker } from 'nepali-datepicker-pro';
import 'nepali-datepicker-pro/style.css';

mountDateRangePicker(document.querySelector('#picker'), {
  fiscalStartMonth: 4,
  valueFormat: 'iso',
  submitName: { start: 'from_date', end: 'to_date' }
});

Notes

  • Fiscal years are first class. fiscalStartMonth defaults to 4 (Shrawan), which drives the "This fiscal year" / "Last fiscal year" presets.
  • onChange fires mid-selection, onApply fires on commit. Use onApply for anything that hits your server; onChange carries a partial { start?, end? } while the user is still picking.
  • Two-field submission. submitName: { start: 'from_date', end: 'to_date' } writes two hidden inputs, which drops straight into a WHERE date BETWEEN ? AND ? query.

See also

Released under the MIT License.