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.

[Slider] Cannot read property 'focus' of null at focusThumb

See original GitHub issue

Hi, I’m getting inconsistent behavior with the slider component. I’m using a slider with a min, max, and range property. Sometimes it works, sometimes it crashes with the error:

Cannot read property 'focus' of null
    at focusThumb (node_modules/material-ui/core/Slider/Slider.js:144:98)
    at eval (node_modules/material-ui/core/Slider/Slider.js:824:5
    at eval (node_modules/material-ui/core/utils/useEventCallback.js:25:29
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

When you click on the slider’s minium range point, an error throws. Sometimes it throws, sometimes it doesnt, depending on a developer sets up the slider component. I’ve been investigating to see why the slider throws, and which configuration makes it throw. So far, the best I’ve done, is isolate the issue to the following configuration of slider:

  • Developer sets up a slider with the props min, max, value, and onChange
  • Developer changes the min property
  • The component throws when a user clicks the slider’s min ticker

It seems like if you change the min prop, you must change the value prop, otherwise the error appears.

It seems like the error is due to an out range design pattern. Perhaps your source code keeps track of the the range of HTML elements that represent the ticks, so when the user clicks the Min mark, that HTML element is now null, so your source code throws. Its an edge case in your design, and should be fixed.

A good fix would be, if the min prop changes, and if you’re keeping track of the discrete HTML elements that represent marks, then you must update your internal state to account for the new min, and set the state of the component to the slider’s new min mark’s element. Failing to do so, would cause a null error on click…which what we’re observing here.

Any who, thats the edge case and the fix, based on my observation. Please patch. Should be a simple fix to cover the missing edge case the component’s state.

Expected Behavior 🤔

No error

Steps to Reproduce 🕹

Codesandbox with error: Codesandbox with no error / with the isolated

Context 🔦

Your Environment 🌎

Tech Version
Material-UI v4.?.?
React
Browser
TypeScript
etc.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:29 (17 by maintainers)

github_iconTop GitHub Comments

4reactions
NawarAcommented, Jul 2, 2020

@mageprincess Rock on! 🧙‍♀️ 👸

3reactions
oliviertassinaricommented, Jul 2, 2020

@mageprincess It sounds like a solid start, do you want to open a pull request on the next branch? 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Slider] Cannot read property 'focus' of null at focusThumb
Hi, I'm getting inconsistent behavior with the slider component. I'm using a slider with a min, max, and range property.
Read more >
Material UI Range Min Max Error: Cannot read property 'focus ...
If I use prop 'value' to Slider, when I try to move thumb, the error throws: Uncaught TypeError: Cannot read property 'focus' of...
Read more >
JavaScript error: Cannot read property "focus" of null
I have an issue when applying this Javascript to focus an input. This error appears to me. I have this JavaScript and when...
Read more >
How To Write Unit Test For Material Ui Slider "Error - ADocLib
This error pops up. Cannot read property 'direction' of null It happens because of the as React from 'react'; import Avatar from '@materialui/core/Avatar'; ......
Read more >
afterRender threw an error in 'c:lwcErrorsListComp' [Cannot ...
I'm setting the objError value from the parent component which holds the id and type properties. Id value in objError record passed to...
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