Skip to content

Commit 1ee3e7a

Browse files
authored
fix: fireEvent in IE11 (#445)
* fix: fireEvent in IE11 * chore: fix coverage
1 parent 6ce9921 commit 1ee3e7a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/events.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,19 @@ Object.keys(eventMap).forEach(key => {
392392
Object.assign(node, targetProperties)
393393
const window = getWindowFromNode(node)
394394
const EventConstructor = window[EventType] || window.Event
395-
return new EventConstructor(eventName, eventInit)
395+
/* istanbul ignore else */
396+
if (typeof EventConstructor === 'function') {
397+
return new EventConstructor(eventName, eventInit)
398+
} else {
399+
// IE11 polyfill from https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
400+
const event = window.document.createEvent(EventType)
401+
const {bubbles, cancelable, detail, ...otherInit} = eventInit
402+
event.initEvent(eventName, bubbles, cancelable, detail)
403+
Object.keys(otherInit).forEach(eventKey => {
404+
event[eventKey] = otherInit[eventKey]
405+
})
406+
return event
407+
}
396408
}
397409

398410
fireEvent[key] = (node, init) => fireEvent(node, createEvent[key](node, init))

0 commit comments

Comments
 (0)