Skip to content

Commit

Permalink
fix(datepicker): handle clicks correctly inside the <label> (#3562)
Browse files Browse the repository at this point in the history
Fixes #3557
  • Loading branch information
maxokorokov committed Feb 7, 2020
1 parent 4ac0352 commit 0f626e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/datepicker/datepicker-input.spec.ts
Expand Up @@ -59,6 +59,25 @@ describe('NgbInputDatepicker', () => {
expectSameValues(inputDatepicker, config);
});

it('should work when wrapped in the <label> and toggled with (click)', () => {
const fixture = createTestCmpt(`
<label>
<input ngbDatepicker #d="ngbDatepicker" [startDate]="{year: 2018, month: 3}" (click)="d.toggle()">
</label>`);

const dpInput = fixture.debugElement.query(By.directive(NgbInputDatepicker)).injector.get(NgbInputDatepicker);

// open
dpInput.open();
fixture.detectChanges();

// click on a date
fixture.nativeElement.querySelectorAll('.ngb-dp-day')[3].click(); // 1 MAR 2018
fixture.detectChanges();

expect(dpInput.isOpen()).toBe(false);
});

describe('Custom config as provider', () => {
const config = new NgbInputDatepickerConfig();
customizeConfig(config);
Expand Down
2 changes: 1 addition & 1 deletion src/datepicker/datepicker-month-view.ts
Expand Up @@ -19,7 +19,7 @@ import {DayTemplateContext} from './datepicker-day-template-context';
<ng-template ngFor let-week [ngForOf]="month.weeks">
<div *ngIf="!week.collapsed" class="ngb-dp-week" role="row">
<div *ngIf="showWeekNumbers" class="ngb-dp-week-number small text-muted">{{ i18n.getWeekNumerals(week.number) }}</div>
<div *ngFor="let day of week.days" (click)="doSelect(day)" class="ngb-dp-day" role="gridcell"
<div *ngFor="let day of week.days" (click)="doSelect(day); $event.preventDefault()" class="ngb-dp-day" role="gridcell"
[class.disabled]="day.context.disabled"
[tabindex]="day.tabindex"
[class.hidden]="day.hidden"
Expand Down

0 comments on commit 0f626e1

Please sign in to comment.