Skip to content

fix(datetime): improve range selection behavior and styling - #31759

Open
OS-susmitabhowmik wants to merge 16 commits into
nextfrom
ROU-13222-update-datepicker-range
Open

OS-susmitabhowmik wants to merge 16 commits into
nextfrom
ROU-13222-update-datepicker-range

Conversation

@OS-susmitabhowmik

@OS-susmitabhowmik OS-susmitabhowmik commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Issue number: resolves internal


What is the current behavior?

  • Range selection tap behavior: After selecting a full range (start + end), tapping a new date extends or modifies the existing range instead of starting a new one.
  • Range track sub-pixel seams: On screens with a fractional device pixel ratio (e.g. 2.625× on Pixel 9), faint 1px lines appear at every column boundary in the range track. Each day drew its own piece of the track with a ::before, and the per-cell boundaries left visible seams.
  • Range track z-index: The range track from the next row paints over the start/end day circles because all wrappers share the same stacking level.
  • Min/max bounds not enforced on programmatic values: Setting a range value where start or end falls outside min/max renders those out-of-bounds dates as highlighted.

What is the new behavior?

  • Third tap resets: Design feedback asked that a third tap start a new range, matching Material's range picker. Once a full range is selected, the next tap always starts a new range.
  • One bar per week: The first range day of each run within a week now draws the track for the whole run via --range-track-span, eliminating seams between days. The grid uses isolation: isolate as a single stacking context, replacing the per-wrapper z-index: 0.
  • Z-index fix: Range start/end wrappers get z-index: 1 and the existing focus-within rule is raised to z-index: 2, so the focus ring and range circles are never covered by an adjacent track. Wrappers that draw the track (calendar-day-wrapper-range-track) are excluded to avoid elevating the wide ::before over adjacent day numbers.
  • Min/max clamping: Programmatic range values are clamped to min/max bounds. If the entire range falls outside bounds, the selection is cleared.

Does this introduce a breaking change?

  • Yes
  • No

Other information

Manual test page

Range test page

New min/max scenarios added:

  • Start Before Min — start set before min, end within bounds → start clamped to min
  • End After Max — start within bounds, end set after max → end clamped to max
  • Range Entirely Outside — entire range outside min/max bounds → selection cleared

OS-susmitabhowmik and others added 5 commits November 16, 2026 12:25
Once a full date range is selected (start + end), the next tap now
always starts a new range instead of modifying the existing one.
This aligns with Material and OutSystems UI Date Picker behavior.

Resolves ROU-13222
- Add horizontal grid padding and --range-track-edge-overflow to the
  ionic theme so the range track bridges across week boundaries,
  matching the ios and md themes.
- Lift range-start and range-end wrappers to z-index: 1 so their
  circles are not covered by the next row's range track when they
  overflow their grid cell.
When a date range is set programmatically with start/end dates outside
the min/max constraints, clamp the range to the valid bounds. If the
entire range falls outside min/max, clear the selection entirely.

Resolves ROU-13214
@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ionic-framework Ready Ready Preview Nov 19, 2026 1:27am UTC

Request Review

@github-actions github-actions Bot added the package: core @ionic/core package label Nov 17, 2026
When the second tap in a range selection is earlier than the first,
swap start and end so the range renders correctly.
Consolidate duplicate "entirely before/after" e2e tests into one,
update test page with start-before-min, end-after-max, and
entirely-outside cases, and add ionChange console logger.
@OS-susmitabhowmik
OS-susmitabhowmik marked this pull request as ready for review November 17, 2026 20:41
@OS-susmitabhowmik
OS-susmitabhowmik requested a review from a team as a code owner November 17, 2026 20:41

@thetaPC thetaPC left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notes on the description:

  • The description doesn't say why the tap behavior is changing. Could you add the reason, such as design feedback asking that a third tap start a new range, matching Material's range picker? If the swap is dropped (refer to the inline comment), the "Range order not normalized" bullets can go too, since next already treats an earlier second tap as a new start.
  • The out-of-bounds console warning already existed (warnIfValueOutOfBounds), so it isn't new behavior.

Comment on lines +1642 to +1656
// Clamp range bounds to min/max so out-of-range dates are not highlighted.
// If the entire range falls outside min/max, clear the selection.
const clampedStart = clampDate(startParts, minParts, maxParts);
const clampedEnd = endParts ? clampDate(endParts, minParts, maxParts) : undefined;

const rangeFullyOutOfBounds =
clampedEnd && endParts && isSameDay(clampedStart, clampedEnd) && !isSameDay(startParts, endParts);

if (rangeFullyOutOfBounds) {
this.activeParts = [];
} else {
startParts = clampedStart;
endParts = clampedEnd;
this.activeParts = endParts ? { start: startParts, end: endParts } : { start: startParts };
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same-day check misses ranges that touch min or max:

  • ['2022-06-01', '2022-06-05'] with min="2022-06-05" clamps both ends to Jun 5, so the selection is cleared even though Jun 5 is in bounds
  • ['2022-01-01', '2022-01-01'] or ['2022-01-01'] with min="2022-06-05" skips the check because start equals end or there is no end, so Jun 5 is highlighted as a range the developer never set

Comparing the original dates against the bounds covers all three:

Suggested change
// Clamp range bounds to min/max so out-of-range dates are not highlighted.
// If the entire range falls outside min/max, clear the selection.
const clampedStart = clampDate(startParts, minParts, maxParts);
const clampedEnd = endParts ? clampDate(endParts, minParts, maxParts) : undefined;
const rangeFullyOutOfBounds =
clampedEnd && endParts && isSameDay(clampedStart, clampedEnd) && !isSameDay(startParts, endParts);
if (rangeFullyOutOfBounds) {
this.activeParts = [];
} else {
startParts = clampedStart;
endParts = clampedEnd;
this.activeParts = endParts ? { start: startParts, end: endParts } : { start: startParts };
}
/**
* Clamp the range to min/max so out-of-bounds dates are not highlighted.
* Clear the selection when no day of the range falls within min/max.
*/
const lastParts = endParts ?? startParts;
const rangeOutOfBounds =
(maxParts && isAfter(startParts, maxParts)) || (minParts && isBefore(lastParts, minParts));
if (rangeOutOfBounds) {
this.activeParts = [];
} else {
startParts = clampDate(startParts, minParts, maxParts);
endParts = endParts ? clampDate(endParts, minParts, maxParts) : undefined;
this.activeParts = endParts ? { start: startParts, end: endParts } : { start: startParts };
}

A test for the first case, to go after range entirely outside min/max should clear the selection:

    test('range ending on min should keep that day selected', async ({ page }) => {
      await page.setContent(
        `
        <ion-datetime
          locale="en-US"
          presentation="date"
          selection-mode="range"
          min="2022-06-05"
          max="2022-06-25"
        ></ion-datetime>
        <script>
          const datetime = document.querySelector('ion-datetime');
          datetime.value = ['2022-06-01', '2022-06-05'];
        </script>
      `,
        config
      );

      await page.locator('.datetime-ready').waitFor();
      const day5 = page.locator('ion-datetime [data-month="6"][data-day="5"]');

      await expect(day5).toHaveClass(/calendar-day-range-start/);
      await expect(day5).toHaveClass(/calendar-day-range-end/);
    });

@OS-susmitabhowmik OS-susmitabhowmik Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this! Fixed and added a test in 70f66d3

Comment on lines +214 to +227
// Calendar / Body
// -----------------------------------

:host .calendar-body .calendar-month .calendar-month-grid {
@include globals.padding(0, globals.$ion-space-200);
}

// Range Selection
// -----------------------------------

:host {
--range-background: #{globals.$ion-bg-primary-subtle-default};
--range-track-height: #{globals.$ion-scale-1200};
--range-track-edge-overflow: #{globals.$ion-space-200};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ionic theme design has no side padding on the grid. Each row is seven 49px cells across the full 343px width, and in the range example the track stops flush with the grid edge on Saturday and Sunday instead of running past it.

  • Adding padding: 0 8px shrinks the cells in every ionic datetime, not only ranges, which is why the basic, display and show-adjacent-days screenshots changed
  • It also doesn't remove the line. At Pixel 9 density (2.625x), the ionic track has a faint 1px line at every column boundary on both next and this branch; the padding only moves where the boundaries fall. There are no lines at 2x or 3x, and none in md, so the cause is likely specific to the ionic theme

Reverting both rules keeps the grid matching the design, and the line can be fixed on its own:

Suggested change
// Calendar / Body
// -----------------------------------
:host .calendar-body .calendar-month .calendar-month-grid {
@include globals.padding(0, globals.$ion-space-200);
}
// Range Selection
// -----------------------------------
:host {
--range-background: #{globals.$ion-bg-primary-subtle-default};
--range-track-height: #{globals.$ion-scale-1200};
--range-track-edge-overflow: #{globals.$ion-space-200};
// Range Selection
// -----------------------------------
:host {
--range-background: #{globals.$ion-bg-primary-subtle-default};
--range-track-height: #{globals.$ion-scale-1200};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted the padding changes and tested this issue further. It was actually occurring on all three themes and seems to have been caused by the way we were drawing the range tracker previously one day at a time. I updated the way we are drawing the tracker to be drawn per week instead in 01dd633. Could you please retest to verify if the line issue is fixed?

Comment on lines 882 to 901
* Creating a new range: first click sets start, second sets end.
* Modifying an existing range:
* - Before range → new start
* - Within range → new end
* - After range → new end
* Once a full range is selected (both start and end), the next
* tap always starts a new range with the clicked date as the start.
* If the resulting span contains a disabled date, start a new range instead.
*/
private setActivePartsRange = (parts: DatetimeParts) => {
const current = this.rangeParts;

if (!current || isBefore(parts, current.start) || this.rangeContainsDisabledDate(current.start, parts)) {
if (!current || current.end || this.rangeContainsDisabledDate(current.start, parts)) {
this.activeParts = { start: parts };
} else {
this.activeParts = { start: current.start, end: parts };
const start = current.start;
// Normalize so start is always before end
if (isBefore(parts, start)) {
this.activeParts = { start: parts, end: start };
} else {
this.activeParts = { start, end: parts };
}
}
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swapping an earlier second tap into the end goes against Material's range picker, which the md theme follows and ios mirrors: there, an earlier second tap becomes the new start. Without confirm buttons the swap also emits ionChange right away, so a tap meant to fix the start date commits a range the user didn't pick. The third-tap reset already matches Material, so keeping the existing new-start branch gets the requested behavior without the swap:

Suggested change
* Creating a new range: first click sets start, second sets end.
* Modifying an existing range:
* - Before range → new start
* - Within range → new end
* - After range → new end
* Once a full range is selected (both start and end), the next
* tap always starts a new range with the clicked date as the start.
* If the resulting span contains a disabled date, start a new range instead.
*/
private setActivePartsRange = (parts: DatetimeParts) => {
const current = this.rangeParts;
if (!current || isBefore(parts, current.start) || this.rangeContainsDisabledDate(current.start, parts)) {
if (!current || current.end || this.rangeContainsDisabledDate(current.start, parts)) {
this.activeParts = { start: parts };
} else {
this.activeParts = { start: current.start, end: parts };
const start = current.start;
// Normalize so start is always before end
if (isBefore(parts, start)) {
this.activeParts = { start: parts, end: start };
} else {
this.activeParts = { start, end: parts };
}
}
};
* Creating a new range: first click sets start, second sets end.
* If the second click is before the start, it becomes the new start.
* Once a full range is selected (both start and end), the next
* tap always starts a new range with the clicked date as the start.
* If the resulting span contains a disabled date, start a new range instead.
*/
private setActivePartsRange = (parts: DatetimeParts) => {
const current = this.rangeParts;
if (
!current ||
current.end ||
isBefore(parts, current.start) ||
this.rangeContainsDisabledDate(current.start, parts)
) {
this.activeParts = { start: parts };
} else {
this.activeParts = { start: current.start, end: parts };
}
};

Please also replace the tapping an earlier date second should normalize start and end test in test/range/datetime.e2e.ts with one for the new-start behavior. The fixture has no confirm buttons by default, so it also checks that the earlier tap doesn't emit ionChange:

    test('tapping an earlier date second should start a new range', async ({ page }) => {
      await fixture.goto(config);
      const ionChangeSpy = await page.spyOnEvent('ionChange');

      const day20 = fixture.getVisibleDay(20);
      const day10 = fixture.getVisibleDay(10);

      // First tap: set start to day 20
      await day20.click();
      await page.waitForChanges();

      // Second tap: day 10 is before the start, so it becomes the new start
      await day10.click();
      await page.waitForChanges();

      await expect(day10).toHaveClass(/calendar-day-range-start/);
      await expect(day20).not.toHaveClass(/calendar-day-range-start/);
      await expect(day20).not.toHaveClass(/calendar-day-range-end/);
      await expect(ionChangeSpy).not.toHaveReceivedEvent();
    });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense to me! Updated as a part of 3683a1d

Comment on lines +304 to +315
z-index: 1;
}

/**
* Range start and end circles can overflow their grid row.
* Lift them above adjacent in-range wrappers so the next
* row's range track does not paint over the circle.
*/
:host .calendar-day-wrapper-range-start,
:host .calendar-day-wrapper-range-end {
z-index: 1;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Giving range start and end the same z-index: 1 as :focus-within lets DOM order decide, so a range-end or range-start wrapper later in the DOM paints over the focus ring of the day before it. In the md theme, keyboard-focusing Jun 19 on the range test page's "Programmatic Default Value" (Jun 10 to 20) shows the right edge of its ring cut flat by Jun 20's track. ios uses the same ring but its wider cells keep it clear at that width, and ionic draws its ring inside the button. Raising the focused day to z-index: 2 keeps it on top:

Suggested change
z-index: 1;
}
/**
* Range start and end circles can overflow their grid row.
* Lift them above adjacent in-range wrappers so the next
* row's range track does not paint over the circle.
*/
:host .calendar-day-wrapper-range-start,
:host .calendar-day-wrapper-range-end {
z-index: 1;
}
/**
* Range start and end wrappers use z-index: 1 below. Matching them
* would let DOM order decide, so a later range edge would paint over
* this day's focus ring. Stay one level above them.
*/
z-index: 2;
}
/**
* Range start and end circles can overflow their grid row.
* Lift them above adjacent in-range wrappers so the next
* row's range track does not paint over the circle.
*/
:host .calendar-day-wrapper-range-start,
:host .calendar-day-wrapper-range-end {
z-index: 1;
}

The in-range-focus screenshot focuses Jun 15, which has no range edge next to it, so it doesn't catch this. Moving focus to Jun 17, the day before the end, would cover it:

      await page.keyboard.press('ArrowDown');
      await page.waitForChanges();
      await page.keyboard.press('ArrowRight');
      await page.waitForChanges();
      await page.keyboard.press('ArrowRight');
      await page.waitForChanges();

      const day17 = datetime.locator('[data-month="6"][data-day="17"]');
      await expect(day17).toBeFocused();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 3683a1d

… range

The previous same-day check after clamping missed ranges that touch min
or max boundaries. Compare the original start/end against bounds first
so a range ending exactly on min is kept and a single-date range outside
bounds is correctly cleared.
…el seams

Each day in a range previously drew its own piece of the track with a
::before using two background layers. At fractional device pixel ratios
(e.g. 2.625× on Pixel 9), the browser anti-aliased each layer's edge
independently, letting the white background layer show through at every
column boundary.

The first range day of each run within a week now draws the track for
the whole run via --range-track-span, so there are no edges between
days. The track uses a single background color instead of two layers,
which means both opaque and translucent --range-background values work
without overlap artifacts.

The grid uses isolation: isolate as a single stacking context, replacing
the per-wrapper z-index rules. The ionic grid padding and edge overflow
are removed so the grid matches the design.
Add back focus-within (z-index: 2) and range-start/range-end (z-index: 1)
rules, excluding range-track wrappers whose wide ::before would cover
adjacent day numbers if elevated.

Also change range selection so tapping an earlier date as the second
click starts a new range instead of swapping, matching Material's range
picker. The focus screenshot now targets day 17 (adjacent to range-end)
to catch focus ring clipping.
# Conflicts:
#	core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-display-ionic-md-ltr-light-Mobile-Firefox-linux.png
#	core/src/components/datetime/test/show-adjacent-days/datetime.e2e.ts-snapshots/datetime-show-adjacent-days-weekends-disabled-ionic-md-ltr-light-Mobile-Firefox-linux.png

This branch was successfully deployed

1 active deployment
Preview — 6bca5a4d Deployed Nov 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants