Skip to content

Commit

Permalink
fix(module:date-picker): arrow in wrong position for RTL direction
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyship committed Oct 18, 2022
1 parent ee4872e commit 6a78bec
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
8 changes: 7 additions & 1 deletion components/date-picker/date-range-popup.component.ts
Expand Up @@ -56,7 +56,7 @@ import { getTimeConfig, isAllowedDate, PREFIX_CLASS } from './util';
template: `
<ng-container *ngIf="isRange; else singlePanel">
<div class="{{ prefixCls }}-range-wrapper {{ prefixCls }}-date-range-wrapper">
<div class="{{ prefixCls }}-range-arrow" [style.left.px]="datePickerService?.arrowLeft"></div>
<div class="{{ prefixCls }}-range-arrow" [style]="arrowPosition"></div>
<div class="{{ prefixCls }}-panel-container {{ showWeek ? prefixCls + '-week-number' : '' }}">
<div class="{{ prefixCls }}-panels">
<ng-container *ngIf="hasTimePicker; else noTimePicker">
Expand Down Expand Up @@ -179,6 +179,12 @@ export class DateRangePopupComponent implements OnInit, OnChanges, OnDestroy {
return this.showToday || this.hasTimePicker || !!this.extraFooter || !!this.ranges;
}

get arrowPosition(): { left?: string; right?: string } {
return this.dir === 'rtl'
? { right: `${this.datePickerService?.arrowLeft}px` }
: { left: `${this.datePickerService?.arrowLeft}px` };
}

constructor(
public datePickerService: DatePickerService,
public cdr: ChangeDetectorRef,
Expand Down
25 changes: 25 additions & 0 deletions components/date-picker/range-picker.component.spec.ts
Expand Up @@ -410,6 +410,31 @@ describe('NzRangePickerComponent', () => {
const result = (nzOnChange.calls.allArgs()[0] as Date[][])[0];
expect((result[0] as Date).getDate()).toBe(+leftText);
}));

it('should support correct position for top arrow', fakeAsync(() => {
fixture.detectChanges();
openPickerByClickTrigger();
fixture.detectChanges();
flush();
fixture.detectChanges();
const arrow = queryFromOverlay(`.${PREFIX_CLASS}-range-arrow`) as HTMLElement;

expect(arrow.style.left).not.toBe('');
}));

it('should support dir rtl for top arrow', fakeAsync(() => {
fixture.debugElement.nativeElement.parentElement.setAttribute('dir', 'rtl');
fixture.detectChanges();
openPickerByClickTrigger();
fixture.detectChanges();
flush();
fixture.detectChanges();
const arrow = queryFromOverlay(`.${PREFIX_CLASS}-range-arrow`) as HTMLElement;

expect(arrow.style.right).not.toBe('');
expect(arrow.style.left).toBe('');
fixture.debugElement.nativeElement.parentElement.setAttribute('dir', '');
}));
}); // /general api testing

describe('panel switch and move forward/afterward', () => {
Expand Down

0 comments on commit 6a78bec

Please sign in to comment.