Skip to content

Commit

Permalink
Don't attach events directly to document
Browse files Browse the repository at this point in the history
Fixes #20
  • Loading branch information
fregante committed Oct 10, 2020
1 parent 66e5cc2 commit 8795011
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ function delegate<TElement extends Element = Element, TEvent extends Event = Eve
};
}

const baseElement = base; // Required for TypeScript
// `document` should never be the base, it's just an easy way to define "global event listeners"
const baseElement = base instanceof Document ? base.documentElement : base;

// Handle the regular Element usage
const capture = Boolean(typeof options === 'object' ? options.capture : options);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"browser"
],
"rules": {
"max-params": 0,
"prefer-rest-params": 0,
"import/extensions": 0,
"unicorn/import-index": 0,
Expand Down
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {window} = new JSDOM(`

global.Event = window.Event;
global.Element = window.Element;
global.Document = window.Document;
global.document = window.document;
const container = window.document.querySelector('ul');
const anchor = window.document.querySelector('a');
Expand Down

0 comments on commit 8795011

Please sign in to comment.