IE11: Exception onBlur when next focused element is SVG
See original GitHub issuedownshift
version: 1.31.2node
version: 8.9.1npm
(oryarn
) 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:
- Created 5 years ago
- Comments:10 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m fine with extra null checks.
Today I saw this exception for an IE 11 user on our system:
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 ifdocument.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?