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.

Thumb is difficult to drag using touch input with custom <input type="range"> controls

See original GitHub issue

When using custom <input type="range"> controls with .custom-range, the thumb is difficult to drag using touch input (mobile and tablet). This occurs on iOS and Android, across browsers.

I recently observed some users interacting with the Bootstrap range sliders in my own project, and almost unanimously they had difficulties with tapping the thumb to drag it. Of course, anywhere in the track can be tapped to ‘jump’ the thumb to that position, but that doesn’t seem to be the primary way users try to interact with it.

Could the hitbox for the thumb be increased in size? Perhaps with the ::before / ::after pseudo elements. It looks like material-ui does something like this, and in my own testing their slider thumb is far easier to drag.

The current effective hitbox is a 1.4rem square (marked in transparent green): current

Could this be increased to twice the value of $custom-range-thumb-width — so by default a 2rem diameter circle? (marked in transparent green): proposed

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
polarstoatcommented, Jul 5, 2020

Actually I’ve got it working in Firefox just fine (see updated CodePen):

.custom-range {
  &::-webkit-slider-thumb {
    background-clip: padding-box;
    border: 0.4rem solid rgba(0, 255, 0, 0.5);
    transform: scale(4);
  }
  &::-moz-range-thumb {
    background-clip: padding-box;
    border: 0.4rem solid rgba(0, 255, 0, 0.5);
    box-sizing: border-box;
    transform: scale(4);
  }
}

I’m not sure why it becomes necessary to explicitly set box-sizing: border-box; for Firefox, but with it it seems to look/work exactly as Safari/Chrome.

It seems unlikely we’ll see better browser support for touch controls like this anytime soon, and currently the usability of them is quite poor. I don’t think this solution (once the :focus outline if figured out/fixed) is a particularly hacky one.

1reaction
patrickhlaukecommented, Jul 5, 2020

note that material-UI and similar frameworks end up “faking” the sliders with extra spans/divs etc, wihch in the end break them for users of touch+assistive technologies (i’ve filed issues with some of them about this).

currently, the bootstrap slider simply adds a bit of style/finesse to the native <input type="range">, so the problem is fundamentally one of the browsers not making these controls touch-friendly enough. not sure if there’s a clean solution to this at this point, i’m afraid.

Read more comments on GitHub >

github_iconTop Results From Across the Web

<input type="range"> - HTML: HyperText Markup Language
The range input type lets you ask the user for a value in cases where the user may not even care—or know—what the...
Read more >
A Sliding Nightmare: Understanding the Range Input
Having a different structure and being unable to access all the elements inside in order to style everything as we wish means that...
Read more >
onchange event on input type=range is not triggering in ...
Apparently Chrome and Safari are wrong: onchange should only be triggered when the user releases the mouse. To get continuous updates, you should...
Read more >
How To Create Range Sliders - W3Schools
Learn how to create custom range sliders with CSS and JavaScript. ... <input type="range" min="1" max="100" value="50" class="slider" id="myRange">
Read more >
How to Style Input Type Range in Chrome, Firefox, and IE
Best to take advantage of the vendor specific track and thumb selectors as much as possible. We'll be using them to recreate this...
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