Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datepicker): handle clicks correctly inside the <label> #3562

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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