Mithril.js: IE11: when document.activeElement is not an HTML element, the rendering fails

Created on 4 Oct 2017  路  2Comments  路  Source: MithrilJS/mithril.js

In case document.activeElement is not an HTML element (e.g. an SVG), the fix from #1943 still fails as focus can only be called on an HTML element.

Expected Behavior

No error occurs, the rendering should complete and document.activeElement should not be modified by mithril when it is no HTML element

Current Behavior

mithril invokes document.activeElement.focus() no matter if the element is an HTML element. The following error is thrown and the rendering is aborted:
TypeError: Object doesn't support property or method 'focus'

Possible Solution

Change https://github.com/MithrilJS/mithril.js/blob/next/render/render.js#L647 to:
if (active != null && $doc.activeElement !== active && active instanceof HTMLElement) active.focus()

Steps to Reproduce (for bugs)

Click on an svg that triggers document.activeElement = svg

Your Environment

  • Version used: mitril-1.1.4
  • Browser Name and version: IE 11
  • Operating System and version (desktop or mobile): Win10 desktop & mobile

Most helpful comment

@mpfau thanks for the report. I suppose we should strive for homogenous behavior and implement your suggestion, though my fingers are burning to use typeof active.focus === 'function' instead...

All 2 comments

@mpfau thanks for the report. I suppose we should strive for homogenous behavior and implement your suggestion, though my fingers are burning to use typeof active.focus === 'function' instead...

I'm coming up against this. Mithril 1.1.6 on IE11.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StephanHoyer picture StephanHoyer  路  4Comments

omenking picture omenking  路  3Comments

simov picture simov  路  4Comments

mikejav picture mikejav  路  3Comments

marciomunhoz picture marciomunhoz  路  4Comments