Skip to content

Commit

Permalink
fix(datetime): RTL will no longer infinitily scroll
Browse files Browse the repository at this point in the history
Resolves #24472
  • Loading branch information
sean-perkins committed Dec 22, 2021
1 parent ee488ff commit aeaceed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
29 changes: 17 additions & 12 deletions core/src/components/datetime/datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,8 @@ export class Datetime implements ComponentInterface {
*/
const months = calendarBodyRef.querySelectorAll('.calendar-month');

const isRTL = document.dir === 'rtl';

const startMonth = months[0] as HTMLElement;
const workingMonth = months[1] as HTMLElement;
const endMonth = months[2] as HTMLElement;
Expand All @@ -681,7 +683,7 @@ export class Datetime implements ComponentInterface {
* if element is not in viewport. Use scrollLeft instead.
*/
writeTask(() => {
calendarBodyRef.scrollLeft = startMonth.clientWidth;
calendarBodyRef.scrollLeft = startMonth.clientWidth * (isRTL ? -1 : 1);

let endIO: IntersectionObserver | undefined;
let startIO: IntersectionObserver | undefined;
Expand Down Expand Up @@ -760,7 +762,7 @@ export class Datetime implements ComponentInterface {
year
});

calendarBodyRef.scrollLeft = workingMonth.clientWidth;
calendarBodyRef.scrollLeft = workingMonth.clientWidth * (isRTL ? -1 : 1);
calendarBodyRef.style.removeProperty('overflow');
calendarBodyRef.style.removeProperty('pointer-events');

Expand Down Expand Up @@ -802,14 +804,14 @@ export class Datetime implements ComponentInterface {
startIO = new IntersectionObserver(ev => ioCallback('start', ev), {
threshold: mode === 'ios' ? [0.7, 1] : 1,
root: calendarBodyRef
});
});
startIO.observe(startMonth);

this.destroyCalendarIO = () => {
endIO?.disconnect();
startIO?.disconnect();
}
});
});
}

connectedCallback() {
Expand Down Expand Up @@ -995,9 +997,12 @@ export class Datetime implements ComponentInterface {
const nextMonth = calendarBodyRef.querySelector('.calendar-month:last-of-type');
if (!nextMonth) { return; }

const isRTL = document.dir === 'rtl';
const left = (nextMonth as HTMLElement).offsetWidth * 2;

calendarBodyRef.scrollTo({
top: 0,
left: (nextMonth as HTMLElement).offsetWidth * 2,
left: left * (isRTL ? -1 : 1),
behavior: 'smooth'
});
}
Expand Down Expand Up @@ -1145,10 +1150,10 @@ export class Datetime implements ComponentInterface {
<div class="calendar-next-prev">
<ion-buttons>
<ion-button onClick={() => this.prevMonth()}>
<ion-icon slot="icon-only" icon={chevronBack} lazy={false}></ion-icon>
<ion-icon slot="icon-only" icon={chevronBack} lazy={false} flipRtl={true}></ion-icon>
</ion-button>
<ion-button onClick={() => this.nextMonth()}>
<ion-icon slot="icon-only" icon={chevronForward} lazy={false}></ion-icon>
<ion-icon slot="icon-only" icon={chevronForward} lazy={false} flipRtl={true}></ion-icon>
</ion-button>
</ion-buttons>
</div>
Expand Down Expand Up @@ -1249,7 +1254,7 @@ export class Datetime implements ComponentInterface {
minutesItems: PickerColumnItem[],
ampmItems: PickerColumnItem[],
use24Hour: boolean
) {
) {
const { color, activePartsClone, workingParts } = this;

return (
Expand Down Expand Up @@ -1290,7 +1295,7 @@ export class Datetime implements ComponentInterface {
ev.stopPropagation();
}}
></ion-picker-column-internal>
{ !use24Hour && <ion-picker-column-internal
{!use24Hour && <ion-picker-column-internal
color={color}
value={activePartsClone.ampm}
items={ampmItems}
Expand All @@ -1311,7 +1316,7 @@ export class Datetime implements ComponentInterface {

ev.stopPropagation();
}}
></ion-picker-column-internal> }
></ion-picker-column-internal>}
</ion-picker-internal>
)
}
Expand All @@ -1321,7 +1326,7 @@ export class Datetime implements ComponentInterface {
minutesItems: PickerColumnItem[],
ampmItems: PickerColumnItem[],
use24Hour: boolean
) {
) {
return [
<div class="time-header">
{this.renderTimeLabel()}
Expand Down Expand Up @@ -1411,7 +1416,7 @@ export class Datetime implements ComponentInterface {

return (
<div class="datetime-time">
{timeOnlyPresentation ? this.renderTimePicker(hoursItems, minutesItems, ampmItems, use24Hour) : this.renderTimeOverlay(hoursItems, minutesItems, ampmItems, use24Hour)}
{timeOnlyPresentation ? this.renderTimePicker(hoursItems, minutesItems, ampmItems, use24Hour) : this.renderTimeOverlay(hoursItems, minutesItems, ampmItems, use24Hour)}
</div>
)
}
Expand Down
8 changes: 8 additions & 0 deletions core/src/components/datetime/test/basic/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,11 @@ describe('Footer', () => {
});


test('datetime:rtl: basic', async () => {
const page = await newE2EPage({
url: '/src/components/datetime/test/basic?ionic:_testing=true&rtl=true'
});

const compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();
});

0 comments on commit aeaceed

Please sign in to comment.