material-design-lite: problems with MDL and polyfilled CustomEvent on IE11
MDL version: 1.1.3 Browser: Internet Explorer Browser version: 11 Operating system: Windows Operating system version: 10 CodePen: http://codepen.io/anon/pen/ZWrKjX?fork=xGWgXa (use this in IE11 or Edge)
What steps will reproduce the problem:
- use a CustomEvent polyfill (for example the one from MDN)
- create some content with MDL components đ
- (optionally) watch your console
What is the expected result? MDL is initialized on page load âautomaticallyâ or by upgrading elements manually.
What happens instead of that? The CSS is applied but components do not get upgraded. The debug console shows an error: âObject doesnât support this actionâ
I am using MDL 1.1.3 in an environment which uses a polyfill for CustomEvent
. When I run my app with IE11 and using componentHandler.upgradeElement
Iâm getting the following error:
TypeError: Object doesn't support this action.
at upgradeElementInternal (Unknown script code:96:13)
I could track it down to this part of componentHandler:
if ('CustomEvent' in window && typeof window.CustomEvent === 'function') {
ev = new Event('mdl-componentupgraded', {
'bubbles': true, 'cancelable': false
});
}
The check for CustomEvent
does not fail (basically a false positive) and the componentHandler tries to create an Event by calling the new Event(...)
constructor which apparently isnât accessible with IE11. Doing a manual new Event('test', { bubbles: true });
leads to the exact same error mentioned above.
I have read in another issue that new Event()
is used to stay compatible with IE10, so this may not be a bug but intentional.
Suggested fix: use CustomEvent
to raise events on upgrading components instead of Event
which is not usable in IE11/Edge.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 24
Well, if the browser doesnât support
CustomEvent
you do nearly the same as the MDN polyfill but if it does supportCustomEvent
you donât have any problem at all because itâs there anyway, right?IE11 simply doesnât allow using the
Event
constructor directly so in a strict sense you could technically say that this isnât compatible, either. đIE11 without a polyfill doesnât have this problem for the sole fact that
createEvent
is used in that case.PR #4348 is open to fix this, just needs lots of device testing.
Thank you for testing and confirming this, @leifoolsen.