Skip to content

Commit

Permalink
fix(datepicker): refine focus state checks
Browse files Browse the repository at this point in the history
This adds additional condition to restrict focus in/out to instance of
the datepicker by verifyng if focus event target and related targets are
descendants of the datepicker element. This removes false results based
only on the class name checks, which fail when focus is switched between
datepicker instances.

Closes ng-bootstrap#3494
  • Loading branch information
peterblazejewicz committed Jan 6, 2020
1 parent 736953a commit 2a90c88
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/datepicker/datepicker.ts
Expand Up @@ -388,7 +388,9 @@ export class NgbDatepicker implements OnDestroy,
.pipe(
filter(
({target, relatedTarget}) =>
!(hasClassName(target, 'ngb-dp-day') && hasClassName(relatedTarget, 'ngb-dp-day'))),
!(hasClassName(target, 'ngb-dp-day') && hasClassName(relatedTarget, 'ngb-dp-day') &&
this._elementRef.nativeElement.contains(target as Node) &&
this._elementRef.nativeElement.contains(relatedTarget as Node))),
takeUntil(this._destroyed$))
.subscribe(({type}) => this._ngZone.run(() => this._service.focusVisible = type === 'focusin'));
});
Expand Down

0 comments on commit 2a90c88

Please sign in to comment.