Skip to content

Commit

Permalink
fix(focus trigger strategy): detect click out via activeElement (#2865)
Browse files Browse the repository at this point in the history
sashaqred authored Sep 14, 2021
1 parent bb0fe20 commit 1f8e0cb
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ export abstract class NbTriggerStrategyBase implements NbTriggerStrategy {

protected destroyed$ = new Subject();

// @breaking-change 9.0.0 Change parameter to Element instead of Event
protected isNotOnHostOrContainer(event: Event): boolean {
return !this.isOnHost(event) && !this.isOnContainer(event);
}
@@ -174,7 +175,11 @@ export class NbFocusTriggerStrategy extends NbTriggerStrategyBase {
protected clickOut$: Observable<Event> = observableFromEvent<Event>(this.document, 'click')
.pipe(
filter(() => !!this.container()),
filter(event => this.isNotOnHostOrContainer(event)),
/**
* Event target of `click` could be different from `activeElement`.
* If during click you return focus to the host, it won't be opened.
*/
filter(() => this.isNotOnHostOrContainer({ target: this.document.activeElement } as unknown as Event)),
takeUntil(this.destroyed$),
);

0 comments on commit 1f8e0cb

Please sign in to comment.