Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datetime): navigate to month within min range #24759

Merged
merged 2 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions core/src/components/datetime/datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,8 @@ export class Datetime implements ComponentInterface {
const { month, year, day } = refMonthFn(this.workingParts);

if (isMonthDisabled({ month, year, day: null }, {
minParts: this.minParts,
maxParts: this.maxParts
minParts: { ...this.minParts, day: null },
maxParts: { ...this.maxParts, day: null }
})) {
return;
}
Expand Down Expand Up @@ -1238,8 +1238,11 @@ export class Datetime implements ComponentInterface {
year,
day: null
}, {
minParts: this.minParts,
maxParts: this.maxParts
// The day is not used when checking if a month is disabled.
// Users should be able to access the min or max month, even if the
// min/max date is out of bounds (e.g. min is set to Feb 15, Feb should not be disabled).
minParts: { ...this.minParts, day: null },
maxParts: { ...this.maxParts, day: null }
});
// The working month should never have swipe disabled.
// Otherwise the CSS scroll snap will not work and the user
Expand Down
14 changes: 14 additions & 0 deletions core/src/components/datetime/test/minmax/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,17 @@ test('datetime: minmax navigation disabled', async () => {
expect(navButtons[1]).toHaveAttribute('disabled');

});

test('datetime: min including day should not disable month', async () => {
const page = await newE2EPage({
url: '/src/components/datetime/test/minmax?ionic:_testing=true'
});

const calendarMonths = await page.findAll('ion-datetime#min-with-day >>> .calendar-month');

await page.waitForChanges();

expect(calendarMonths[0]).toHaveClass('calendar-month-disabled');
expect(calendarMonths[1]).not.toHaveClass('calendar-month-disabled');
expect(calendarMonths[2]).not.toHaveClass('calendar-month-disabled');
})
4 changes: 4 additions & 0 deletions core/src/components/datetime/test/minmax/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ <h2>h23 Min</h2>
<h2>locale: en-GB</h2>
<ion-datetime locale="en-GB" presentation="time" min="19:30" value="20:30" max="20:40"></ion-datetime>
</div>
<div class="grid-item">
<h2>Min with year/month/day</h2>
<ion-datetime id="min-with-day" min="2022-02-09" value="2022-02-09"></ion-datetime>
</div>
</div>
</ion-content>

Expand Down