Skip to content

Date Range Filter

beta

The DateRangeFilter is a filter field type (FilterFieldTypes.DateRange) in the filters system. It presents a dropdown with grouped preset date ranges (Recommended, Relative dates, Calendar months) and a “Select custom range” option. Clicking “Select custom range” reveals a two-month calendar alongside the preset list for picking an arbitrary date range.

Installation

import { useState } from 'react'
import { FilterField, FilterFieldTypes } from '@harnessio/ui/components'
import type { DateRangeValue } from '@harnessio/ui/components'
const MyComponent = () => {
const [value, setValue] = useState<DateRangeValue | undefined>();
return (
<FilterField
filterOption={{
type: FilterFieldTypes.DateRange,
label: 'Timeframe',
value: 'timeframe',
}}
removeFilter={() => {}}
shouldOpenFilter={false}
onChange={(val) => setValue(val)}
value={value}
/>
);
};

With custom presets

You can provide your own set of presets via filterFieldConfig.presets. Each preset defines a label, a unique value, a group for visual grouping, and a getRange function that returns { from: Date, to: Date }.

Without custom range

Set showCustomRange: false to hide the “Select custom range” option and only show presets.