question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IE11: Exception onBlur when next focused element is SVG

See original GitHub issue
  • downshift version: 1.31.2
  • node version: 8.9.1
  • npm (or yarn) version: yarn 1.5.1

Relevant code or config

input_handleBlur = () => {
    // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
    setTimeout(() => {
      const downshiftButtonIsActive =
        this.props.environment.document.activeElement.dataset.toggle &&
        (this._rootNode &&
          this._rootNode.contains(
            this.props.environment.document.activeElement,
          ))
      if (!this.isMouseDown && !downshiftButtonIsActive) {
        this.reset({type: Downshift.stateChangeTypes.blurInput})
      }
    })
  }

What you did:

Click the clear button (in IE11)

What happened:

Unable to get property 'toggle' of undefined or null reference

Reproduction repository:

<Downshift>
  {({ getButtonProps, getInputProps, clearSelection }) =>(
    <div>
      <input {...getInputProps()}/>
      <div>
        <button onClick={clearSelection}>X</button>
        <svg>
           {/* some SVG here */}
        </svg>
      </div>
    </div>
  )
</Downshift>

Problem description: dataset doesn’t exist on svg elements in IE11.

Suggested solution: Add additional check:

const downshiftButtonIsActive =
  this.props.environment.document.activeElement.dataset &&
  this.props.environment.document.activeElement.dataset.toggle &&
    (this._rootNode &&
    this._rootNode.contains(
    his.props.environment.document.activeElement,
   ))

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kentcdoddscommented, Jan 30, 2019

I’m fine with extra null checks.

0reactions
nmchavescommented, Jan 30, 2019

Today I saw this exception for an IE 11 user on our system:

TypeError: Unable to get property 'dataset' of undefined or null reference
  at fn(../../node_modules/downshift/dist/downshift.esm.js:855:1)

My team is using Downshift v3.2.0.

The MDN docs explain that activeElement will be null if there is no focused element. The current logic that resolved this issue doesn’t test if document.activeElement is non-null. Unfortunately, I’m not exactly sure how the user got into this state, and I haven’t been able to reproduce the issue myself. Based on our Sentry error report, it doesn’t look like the user did anything unusual…I just haven’t been able to reproduce it 😅.

@kentcdodds would you be open to a PR with another check to make sure that activeElement is non-null?

Read more comments on GitHub >

github_iconTop Results From Across the Web

SVG a element not receiving focus correctly in Firefox and IE11
The problem is that the basic DOM methods .focus() and .blur() (which are used internally by the JQuery methods) are not defined on...
Read more >
ASPxLoadingPanel - A JavaScript exception in IE 11 when the ...
... exception in IE 11 when the Active Element in the Document is SVGElement ... runtime error: Object doesn't support property or method...
Read more >
UI Events - W3C
The event target MUST be the element which is about to lose focus. This event type is similar to blur , but is...
Read more >
changelog.txt - True
#TINY-1877 Changed the keyboard shortcut to move focus to contextual toolbars to ... Fixed bug where pressing enter after/before hr element threw exception....
Read more >
Using SVG with CSS3 and HTML5
Future Focus: Selective Scaling ... Building a Better Blur ... drawing elements in SVG, and how to control their geometry and layout:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found