Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Range input value not set on initial render in 15.2.0 #7170

Closed
mikecao opened this issue Jul 2, 2016 · 7 comments
Closed

Range input value not set on initial render in 15.2.0 #7170

mikecao opened this issue Jul 2, 2016 · 7 comments

Comments

@mikecao
Copy link

mikecao commented Jul 2, 2016

Do you want to request a feature or report a bug?

This is a bug.

What is the current behavior?

When rendering a range input element, the value of the input isn't set on the initial render. You have to call render again for the value to get picked up.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template: https://jsfiddle.net/reactjs/69z2wepo/).

I've created a demo here, https://jsfiddle.net/caozilla/qchxo3qb/4/.

The demo includes a component called Test which simply renders an range input component by passing some props. There is an update button which calls setState and should trigger the render. There are also console.log statements which show the values being used during the render.

When you run the demo you'll notice that you have to click the update button twice before the input value updates. The strange thing is that it seems to have something to do with the min and max attributes of the input. There is a commented out line where it does var max = 100 and that seems to work fine on initial render. But when it references the state value, it doesn't work.

What is the expected behavior?

The input value should be set properly on initial render.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

This affects React 15.2.0. It works fine in 15.1.0. I've only tested on the latest Chrome.

@syranide
Copy link
Contributor

syranide commented Jul 2, 2016

It works just fine: https://jsfiddle.net/4feqLmmy/

You even log the value yourself in the console and it shows 0 0 0, then when you press the button value is updated to 50 and thus prints 50 0 100 and it updates the range correctly. I don't see anything wrong here besides your jsfiddle.

EDIT: my bad (mouse is buggy and double clicks automatically sometimes >_<), ok I see what you mean now. Yeah something's wrong here.

@syranide
Copy link
Contributor

syranide commented Jul 2, 2016

Duplicate of #7099

Basically, range input truncates the value according to min/max but React doesn't consider this and can apply the properties in the wrong order causing it to be truncated first and then the limits updated.

@syranide
Copy link
Contributor

syranide commented Jul 2, 2016

It's really kind of hacky and a bad idea in some cases, but if you put min+max as a key on the range input it will always show correctly (for now).

@mikecao
Copy link
Author

mikecao commented Jul 13, 2016

@syranide I just saw that #7099 was fixed but the fix only applied to the step parameter. Would this fix also work for min/max values?

@syranide
Copy link
Contributor

@mikecao Yeah that should work.

@mikecao mikecao mentioned this issue Jul 30, 2016
@troydemonbreun
Copy link
Contributor

Okay, will fix this one like I fixed for #7251

aweary pushed a commit that referenced this issue Aug 15, 2016
* Write failing test

* Ensure .min and .max are set before .value

* Adjusting test for false negative

* Revert test adjustment (apparently it was only failing locally)
zpao pushed a commit that referenced this issue Aug 15, 2016
* Write failing test

* Ensure .min and .max are set before .value

* Adjusting test for false negative

* Revert test adjustment (apparently it was only failing locally)

(cherry picked from commit 3013afe)
anmonteiro added a commit to ladderlife/cellophane that referenced this issue Aug 17, 2016
@zpao
Copy link
Member

zpao commented Aug 23, 2016

This was fixed.

@zpao zpao closed this as completed Aug 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants