Skip to content

Date Range Preset Collision in bsDaterangepicker Causes Incorrect Preset Detection for Identical Ranges #6806

@Virus35

Description

@Virus35

When using ngx-bootstrap bsDaterangepicker quick select ranges, the bsValueChange event emits only the selected Date[] value and does not expose which preset button was clicked.

If the application tries to detect the selected preset by comparing returned dates against configured ranges, multiple presets that generate the same range cannot be distinguished.

In such cases, the first matching preset is always selected.


Example Scenario

Configured presets:

ranges = [
  {
    id: 4,
    label: 'Last 3 Months (Till Today)',
    value: [new Date('2026-01-21'), new Date('2026-04-21')]
  },
  {
    id: 26,
    label: 'Last 90 Days',
    value: [new Date('2026-01-21'), new Date('2026-04-21')]
  }
];

Selection handler:

onValueChange(selectedRange: Date[]) {
  const matched = ranges.find(
    r =>
      r.value[0].getTime() === selectedRange[0].getTime() &&
      r.value[1].getTime() === selectedRange[1].getTime()
  );

  console.log(matched);
}

Steps to Reproduce

  1. Configure two presets that resolve to the same date range on a given day.
  2. Open bsDaterangepicker.
  3. Click Last 90 Days.
  4. Observe emitted Date[].
  5. Reverse lookup returns first match.

Actual Result

{
  id: 4,
  label: 'Last 3 Months (Till Today)'
}

Expected Result

{
  id: 26,
  label: 'Last 90 Days'
}

Impact

  • Incorrect preset label shown
  • Wrong preset ID stored
  • Saved filters can be inaccurate
  • Confusing UX for overlapping ranges

Suggested Enhancement

Expose selected quick-range preset metadata in event output, for example:

{
  presetId: 26,
  label: 'Last 90 Days',
  value: [startDate, endDate]
}

This would avoid unreliable reverse-matching based only on dates.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions