Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/cdk/overlay/keyboard/overlay-keyboard-dispatcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ describe('OverlayKeyboardDispatcher', () => {
expect(overlayTwoSpy).toHaveBeenCalled();
});

it('should dispatch keyboard events when propagation is stopped', () => {
const overlayRef = overlay.create();
const spy = jasmine.createSpy('keyboard event spy');
const button = document.createElement('button');

document.body.appendChild(button);
button.addEventListener('keydown', event => event.stopPropagation());

overlayRef.keydownEvents().subscribe(spy);
keyboardDispatcher.add(overlayRef);
dispatchKeyboardEvent(button, 'keydown', ESCAPE);

expect(spy).toHaveBeenCalled();

button.parentNode!.removeChild(button);
});

it('should dispatch targeted keyboard events to the overlay containing that target', () => {
const overlayOne = overlay.create();
const overlayTwo = overlay.create();
Expand Down
6 changes: 3 additions & 3 deletions src/cdk/overlay/keyboard/overlay-keyboard-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ export class OverlayKeyboardDispatcher implements OnDestroy {
* events to the appropriate overlay.
*/
private _subscribeToKeydownEvents(): void {
const bodyKeydownEvents = fromEvent<KeyboardEvent>(this._document.body, 'keydown');
const bodyKeydownEvents = fromEvent<KeyboardEvent>(this._document.body, 'keydown', true);

this._keydownEventSubscription = bodyKeydownEvents.pipe(
filter(() => !!this._attachedOverlays.length)
).subscribe(event => {
// Dispatch keydown event to correct overlay reference
// Dispatch keydown event to the correct overlay.
this._selectOverlayFromEvent(event)._keydownEvents.next(event);
});
}
Expand All @@ -87,7 +87,7 @@ export class OverlayKeyboardDispatcher implements OnDestroy {
overlay.overlayElement.contains(event.target as HTMLElement);
});

// Use that overlay if it exists, otherwise choose the most recently attached one
// Use the overlay if it exists, otherwise choose the most recently attached one
return targetedOverlay || this._attachedOverlays[this._attachedOverlays.length - 1];
}

Expand Down