react-component / react-component/slider

Bug: Incorrect value when bounding client rect has fractional values

Open
#459 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.1k
Forks
768
Avg merge
11d 22h
Merged PRs (30d)
5

Description

It seems rc-slider computes the value by calling getBoundingClientRect on the handle element and comparing it to the size and position of the containing element.

There are cases where those rectangles may have fractional x values. This can be determined by the size or placement of a neighboring element, whose width is fractional due to an explicitly set value, a percentage or an auto width. In some of these cases, values are not computed correctly, particularly at the max edge of the range.

See the following example. To replicate, drag the right handle of the range anywhere and leave it all the way to the right. The resulting value should be 1, which is the max value set on the range, but it comes out as a fractional value slightly higher than 1.

https://codesandbox.io/s/8n8kq0njjj

Thanks.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the getBoundingClientRect handling in src/utils.js and the containing-element position logic in src/common/createSlider.jsx. Reproduce the fractional-position case using the linked CodeSandbox, especially by dragging the right handle to the range maximum. Done means the resulting value is exactly the configured max value of 1 rather than a slightly higher fractional value.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.