Skip to content

feat(datetime): add parts for calendar day, active, and today #27641

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

Merged
merged 33 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0293b9d
feat(datetime): add parts for calendar day and button wrapper
brandyscarney Aug 17, 2023
6ca4cda
test(datetime): add test for customizing the css parts
brandyscarney Aug 17, 2023
8c28d11
refactor: remove unused css
brandyscarney Aug 17, 2023
c697ef9
chore(): add updated snapshots
Ionitron Aug 17, 2023
64fa7cb
fix(datetime): focus calendar day element when tabbing
brandyscarney Aug 17, 2023
16fdd91
test(datetime): remove test from color directory
brandyscarney Aug 24, 2023
cd6e0a4
test(datetime): add test to custom for customizing calendar days
brandyscarney Aug 24, 2023
1a588b0
test(datetime): target the specific grid datetime for the test
brandyscarney Aug 24, 2023
a0f6cd5
test(datetime): remove unused elements from test
brandyscarney Aug 24, 2023
71273b6
test(datetime): fix broken tests
brandyscarney Aug 24, 2023
c0772db
chore(): add updated snapshots
Ionitron Aug 24, 2023
ac71cfa
test(datetime): update colors to look better with dark mode
brandyscarney Aug 25, 2023
9b93291
fix(datetime): extract width/height to Sass vars
brandyscarney Aug 28, 2023
e314040
docs(datetime): comment on why the mins exist
brandyscarney Aug 28, 2023
f5c8c82
style: lint
brandyscarney Aug 28, 2023
141fc3b
git: revert image updates
brandyscarney Aug 28, 2023
d522a76
fix(datetime): don't add css shadow parts to spacer days
brandyscarney Aug 30, 2023
c062227
fix(datetime): add a focus ring around ios and make highlightedDates …
brandyscarney Aug 31, 2023
e34124a
actual property name
brandyscarney Aug 31, 2023
beec11c
Merge branch 'feature-7.4' into FW-1593
brandyscarney Aug 31, 2023
7d91ffa
chore(): add updated snapshots
Ionitron Aug 31, 2023
c2a5c32
test(datetime): fix incorrect selector & screenshot images
brandyscarney Aug 31, 2023
8bc0407
Merge branch 'feature-7.4' into FW-1593
liamdebeasi Sep 1, 2023
74547d6
test(datetime): oops those ids were used
brandyscarney Sep 1, 2023
de13e15
chore(): add updated snapshots
Ionitron Sep 1, 2023
85e250d
fix(datetime): check if the day is not calendar padding to add parts
brandyscarney Sep 1, 2023
9cfe971
fix(datetime): remove highlighted dates from other months
brandyscarney Sep 5, 2023
2a63bf5
refactor(datetime): combine the shared css
brandyscarney Sep 5, 2023
198bd3d
test(datetime): add tests for focus states
brandyscarney Sep 5, 2023
6f4d463
style: lint
brandyscarney Sep 5, 2023
aa3881e
chore(): add updated snapshots
Ionitron Sep 5, 2023
cbba937
test(datetime): don't screenshot rtl tests for focus
brandyscarney Sep 5, 2023
80af52c
Merge branch 'feature-7.4' into FW-1593
brandyscarney Sep 6, 2023
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
3 changes: 3 additions & 0 deletions core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ ion-datetime,css-prop,--background-rgb
ion-datetime,css-prop,--title-color
ion-datetime,css-prop,--wheel-fade-background-rgb
ion-datetime,css-prop,--wheel-highlight-background
ion-datetime,part,calendar-day
ion-datetime,part,calendar-day active
ion-datetime,part,calendar-day today
ion-datetime,part,month-year-button
ion-datetime,part,time-button
ion-datetime,part,time-button active
Expand Down
Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 12 and the 26.

datetime-diff-one.mov

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Member Author

Choose a reason for hiding this comment

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

The height difference here is caused by the calendar day becoming 24px high across browsers. On main, the height is 23.5px for Chrome, 24px for Firefox, and 23px for Safari. This branch removes that fractional pixel making all browsers render the calendar day at the same height. See the below image for more details.

datetime-height-changes-ios

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 12 and the 26.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Member Author

Choose a reason for hiding this comment

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

The height difference here is caused by the calendar day going from 42.5px high to 42px high. On main, the height is 42.5px for Firefox and Chrome, but 42px for Safari. This branch removes that fractional pixel making all browsers render the calendar day at the same height. See the below image for more details.

datetime-height-changes-md

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 12 and the 26.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 12 and the 26.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 20 additions & 20 deletions core/src/components/datetime/datetime.ios.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@include padding($datetime-ios-padding, $datetime-ios-padding, $datetime-ios-padding, $datetime-ios-padding);

border-bottom: $datetime-ios-border-color;

font-size: 14px;
}

Expand Down Expand Up @@ -85,27 +85,33 @@
*/
@include padding($datetime-ios-padding * 0.5, $datetime-ios-padding * 0.5, $datetime-ios-padding * 0.5, $datetime-ios-padding * 0.5);

align-items: center;

height: calc(100% - #{$datetime-ios-padding});
}

:host .calendar-day {
font-size: 20px;
}
:host .calendar-day-wrapper {
@include padding(4px);

// This is required so that the calendar day wrapper
// will collapse instead of expanding to fill the button
height: 0;

.calendar-day:focus .calendar-day-highlight,
.calendar-day.calendar-day-active .calendar-day-highlight {
opacity: 0.2;
min-height: 16px;
}

.calendar-day.calendar-day-active .calendar-day-highlight {
background: current-color(base);
:host .calendar-day {
width: 40px;
min-width: 40px;

height: 40px;

font-size: 20px;
}

// !important is needed here to overwrite custom highlight background, which is inline.
// Does not apply to the active state because highlights aren't applied at all there.
.calendar-day:focus .calendar-day-highlight {
/* stylelint-disable-next-line declaration-no-important */
background: current-color(base) !important;
.calendar-day:focus,
.calendar-day.calendar-day-active {
background: current-color(base, 0.2);
}

/**
Expand Down Expand Up @@ -135,12 +141,6 @@
color: current-color(contrast);
}

.calendar-day.calendar-day-today.calendar-day-active .calendar-day-highlight {
background: current-color(base);

opacity: 1;
}

// Time / Header
// -----------------------------------
:host .datetime-time {
Expand Down
15 changes: 8 additions & 7 deletions core/src/components/datetime/datetime.md.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@

// Individual day button in month
:host .calendar-day {
@include padding(13px, 0, 13px, 0px);
width: 42px;
min-width: 42px;

height: 42px;

font-size: $datetime-md-calendar-item-font-size;
}

.calendar-day:focus .calendar-day-highlight {
.calendar-day:focus {
background: current-color(base, 0.2);

box-shadow: 0px 0px 0px 4px current-color(base, 0.2);
Expand All @@ -85,11 +88,9 @@
* should have ion-color for text color.
*/
:host .calendar-day.calendar-day-today {
color: current-color(base);
}

.calendar-day.calendar-day-today .calendar-day-highlight {
border: 1px solid current-color(base);

color: current-color(base);
}

/**
Expand All @@ -101,7 +102,7 @@
color: current-color(contrast);
}

.calendar-day.calendar-day-active .calendar-day-highlight {
.calendar-day.calendar-day-active {
border: 1px solid current-color(base);

background: current-color(base);
Expand Down
33 changes: 20 additions & 13 deletions core/src/components/datetime/datetime.scss
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ ion-picker-column-internal {
}

:host .calendar-body .calendar-month {
display: flex;

flex-flow: column;

/**
* Swiping should snap to at
* most one month at a time.
Expand Down Expand Up @@ -325,13 +329,27 @@ ion-picker-column-internal {
grid-template-columns: repeat(7, 1fr);
}

:host .calendar-day-wrapper {
display: flex;

align-items: center;
justify-content: center;

min-width: 0;

min-height: 0;

overflow: visible;
}

/**
* Center the day text vertically
* and horizontally within its grid cell.
*/
:host .calendar-day {
@include padding(0px, 0px, 0px, 0px);
@include margin(0px, 0px, 0px, 0px);
@include border-radius(50%);
@include padding(0px);
@include margin(0px);

display: flex;

Expand Down Expand Up @@ -362,17 +380,6 @@ ion-picker-column-internal {
opacity: 0.4;
}

.calendar-day-highlight {
@include border-radius(32px, 32px, 32px, 32px);
@include padding(4px, 4px, 4px, 4px);

position: absolute;

width: 32px;
height: 32px;

z-index: -1;
}

// Time / Header
// -----------------------------------
Expand Down
119 changes: 61 additions & 58 deletions core/src/components/datetime/datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ import {
*
* @part month-year-button - The button that opens the month/year picker when
* using a grid style layout.
*
* @part calendar-day - The individual buttons that display a day inside of the datetime
* calendar.
* @part calendar-day active - The currently selected calendar day.
* @part calendar-day today - The calendar day that contains the current day.
*/
@Component({
tag: 'ion-datetime',
Expand Down Expand Up @@ -800,7 +805,7 @@ export class Datetime implements ComponentInterface {
/**
* Get the number of padding days so
* we know how much to offset our next selector by
* to grab the correct calenday-day element.
* to grab the correct calendar-day element.
*/
const padding = currentMonth.querySelectorAll('.calendar-day-padding');
const { day } = this.workingParts;
Expand All @@ -814,7 +819,7 @@ export class Datetime implements ComponentInterface {
* and focus it.
*/
const dayEl = currentMonth.querySelector(
`.calendar-day:nth-of-type(${padding.length + day})`
`.calendar-day-wrapper:nth-of-type(${padding.length + day}) .calendar-day`
) as HTMLElement | null;
if (dayEl) {
dayEl.focus();
Expand Down Expand Up @@ -2080,68 +2085,66 @@ export class Datetime implements ComponentInterface {
}

return (
<button
tabindex="-1"
data-day={day}
data-month={month}
data-year={year}
data-index={index}
data-day-of-week={dayOfWeek}
disabled={isCalDayDisabled}
class={{
'calendar-day-padding': isCalendarPadding,
'calendar-day': true,
'calendar-day-active': isActive,
'calendar-day-today': isToday,
}}
style={
dateStyle && {
color: dateStyle.textColor,
}
}
aria-hidden={isCalendarPadding ? 'true' : null}
aria-selected={ariaSelected}
aria-label={ariaLabel}
onClick={() => {
if (isCalendarPadding) {
return;
<div class="calendar-day-wrapper">
<button
tabindex="-1"
data-day={day}
data-month={month}
data-year={year}
data-index={index}
data-day-of-week={dayOfWeek}
disabled={isCalDayDisabled}
class={{
'calendar-day-padding': isCalendarPadding,
'calendar-day': true,
'calendar-day-active': isActive,
'calendar-day-today': isToday,
}}
part={`calendar-day${isActive ? ' active' : ''}${isToday ? ' today' : ''}`}
style={
dateStyle && {
color: dateStyle.textColor,
backgroundColor: dateStyle.backgroundColor,
}
}

this.setWorkingParts({
...this.workingParts,
month,
day,
year,
});

// multiple only needs date info, so we can wipe out other fields like time
if (multiple) {
this.setActiveParts(
{
month,
day,
year,
},
isActive
);
} else {
this.setActiveParts({
...activePart,
aria-hidden={isCalendarPadding ? 'true' : null}
aria-selected={ariaSelected}
aria-label={ariaLabel}
onClick={() => {
if (isCalendarPadding) {
return;
}

this.setWorkingParts({
...this.workingParts,
month,
day,
year,
});
}
}}
>
<div
class="calendar-day-highlight"
style={{
backgroundColor: dateStyle?.backgroundColor,

// multiple only needs date info, so we can wipe out other fields like time
if (multiple) {
this.setActiveParts(
{
month,
day,
year,
},
isActive
);
} else {
this.setActiveParts({
...activePart,
month,
day,
year,
});
}
}}
></div>
{text}
</button>
>
{text}
</button>
</div>
);
})}
</div>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 4.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 4.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 1 in 13.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 4.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 4.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 4.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 4.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 4.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 4.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion core/src/components/datetime/test/color/datetime.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
test('should not have visual regressions', async ({ page }) => {
await page.goto('/src/components/datetime/test/color', config);

const datetime = page.locator('ion-datetime');
const datetime = page.locator('#colorDatetime');

await expect(datetime).toHaveScreenshot(screenshot(`datetime-color`));

Expand All @@ -18,5 +18,12 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {

await expect(datetime).toHaveScreenshot(screenshot(`datetime-color-dark`));
});
test('should be able to customize datetime using css parts', async ({ page }) => {
await page.goto('/src/components/datetime/test/color', config);

const datetime = page.locator('#customDatetime');

await expect(datetime).toHaveScreenshot(screenshot(`datetime-custom-css-parts`));
});
});
});
Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 4.

Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 4.

Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 4.

Copy link
Member Author

Choose a reason for hiding this comment

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

The difference between these two screenshots is a shift horizontally of the 4.

Loading