Skip to content

Commit 41b56e4

Browse files
authored
fix(module:date-picker): arrow in wrong position for RTL direction (#7690)
1 parent ee4872e commit 41b56e4

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

components/date-picker/date-range-popup.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import { getTimeConfig, isAllowedDate, PREFIX_CLASS } from './util';
5656
template: `
5757
<ng-container *ngIf="isRange; else singlePanel">
5858
<div class="{{ prefixCls }}-range-wrapper {{ prefixCls }}-date-range-wrapper">
59-
<div class="{{ prefixCls }}-range-arrow" [style.left.px]="datePickerService?.arrowLeft"></div>
59+
<div class="{{ prefixCls }}-range-arrow" [style]="arrowPosition"></div>
6060
<div class="{{ prefixCls }}-panel-container {{ showWeek ? prefixCls + '-week-number' : '' }}">
6161
<div class="{{ prefixCls }}-panels">
6262
<ng-container *ngIf="hasTimePicker; else noTimePicker">
@@ -179,6 +179,12 @@ export class DateRangePopupComponent implements OnInit, OnChanges, OnDestroy {
179179
return this.showToday || this.hasTimePicker || !!this.extraFooter || !!this.ranges;
180180
}
181181

182+
get arrowPosition(): { left?: string; right?: string } {
183+
return this.dir === 'rtl'
184+
? { right: `${this.datePickerService?.arrowLeft}px` }
185+
: { left: `${this.datePickerService?.arrowLeft}px` };
186+
}
187+
182188
constructor(
183189
public datePickerService: DatePickerService,
184190
public cdr: ChangeDetectorRef,

components/date-picker/range-picker.component.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,30 @@ describe('NzRangePickerComponent', () => {
410410
const result = (nzOnChange.calls.allArgs()[0] as Date[][])[0];
411411
expect((result[0] as Date).getDate()).toBe(+leftText);
412412
}));
413+
414+
it('should support correct position for top arrow', fakeAsync(() => {
415+
fixture.detectChanges();
416+
openPickerByClickTrigger();
417+
fixture.detectChanges();
418+
flush();
419+
fixture.detectChanges();
420+
const arrow = queryFromOverlay(`.${PREFIX_CLASS}-range-arrow`) as HTMLElement;
421+
422+
expect(arrow.style.left).not.toBe('');
423+
}));
424+
425+
it('should support dir rtl for top arrow', fakeAsync(() => {
426+
fixture.debugElement.nativeElement.parentElement.setAttribute('dir', 'rtl');
427+
fixture.detectChanges();
428+
openPickerByClickTrigger();
429+
fixture.detectChanges();
430+
flush();
431+
fixture.detectChanges();
432+
const arrow = queryFromOverlay(`.${PREFIX_CLASS}-range-arrow`) as HTMLElement;
433+
434+
expect(arrow.style.right).not.toBe('');
435+
fixture.debugElement.nativeElement.parentElement.setAttribute('dir', '');
436+
}));
413437
}); // /general api testing
414438

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

components/date-picker/style/patch.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@
2626
width: inherit;
2727
}
2828
}
29+
30+
// make arrow in the right position in right direction
31+
.@{picker-prefix-cls}-range-arrow {
32+
margin-right: @input-padding-horizontal-base * 1.5;
33+
}

0 commit comments

Comments
 (0)