react-component / react-component/slider

getPrecision always returns 0 when step size value is an integer

Open
#645 0 comments 0 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

When the value for the step size is an integer, the function getPrecision (https://github.com/react-component/slider/blob/9.2.4/src/utils.js#L35) always returns a precision of 0, which is not desired. There should be a way to pass the precision of a step to allow a situation as the following:

const sliderProps = {
  value: 5.5,
  step: 3,
  min: 2.5,
  max: 20.5
};

In the situation above, the handle won't take a value lower than 3 with the current implementation in v9.2.4. Although the closest point of 2.5 is found when dragging the handle, the ensureValuePrecision function (https://github.com/react-component/slider/blob/9.2.4/src/utils.js#L69) will round it off to an integer (3 in this case).

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 in src/utils.js at getPrecision and ensureValuePrecision, then trace how the step size and minimum value reach those helpers. Verify the reported case with value 5.5, step 3, min 2.5, and max 20.5; done means the slider can retain the valid minimum of 2.5 instead of rounding it to 3.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.