Skip to content

Commit

Permalink
Be a bit more defensive about the event target.
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-r-rose committed Feb 1, 2019
1 parent 841ff8e commit a0a0686
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/application/src/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,16 @@ export abstract class JupyterFrontEnd<
contextMenuHitTest(
test: (node: HTMLElement) => boolean
): HTMLElement | undefined {
if (!this._contextMenuEvent) {
if (
!this._contextMenuEvent ||
!(this._contextMenuEvent.target instanceof HTMLElement)
) {
return undefined;
}
// This one-liner doesn't work, but should at some point in the future
// `return this._contextMenuEvent.composedPath() as HTMLElement[];`
// cf. (https://developer.mozilla.org/en-US/docs/Web/API/Event)
let node: HTMLElement = this._contextMenuEvent.target as HTMLElement;
let node = this._contextMenuEvent.target as HTMLElement;
do {
if (test(node)) {
return node;
Expand Down

0 comments on commit a0a0686

Please sign in to comment.