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 25, 2022
1 parent ee4872e commit 41b56e4
Show file tree
Hide file tree
Showing 3 changed files with 36 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
24 changes: 24 additions & 0 deletions components/date-picker/range-picker.component.spec.ts
Expand Up @@ -410,6 +410,30 @@ 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('');
fixture.debugElement.nativeElement.parentElement.setAttribute('dir', '');
}));
}); // /general api testing

describe('panel switch and move forward/afterward', () => {
Expand Down
5 changes: 5 additions & 0 deletions components/date-picker/style/patch.less
Expand Up @@ -26,3 +26,8 @@
width: inherit;
}
}

// make arrow in the right position in right direction
.@{picker-prefix-cls}-range-arrow {
margin-right: @input-padding-horizontal-base * 1.5;
}

0 comments on commit 41b56e4

Please sign in to comment.