Skip to content

Change warning for <select value={null} /> to suggest an empty array rather than empty string #9038

@ryb73

Description

@ryb73

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

What is the current behavior?
Setting the value to "" on a <select> with size > 3 does not deselect the currently selected option.

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/).
JSFiddle: https://jsfiddle.net/rpbiwer/55jzq7dq/2/

What is the expected behavior?
After rendering a <select> with the value set to an empty string, I expect there to be no selection in the rendered select box. Mainly this expectation comes from this React warning when I use null instead of "":

Warning: `value` prop on `select` should not be null. Consider using the empty string to clear the component or `undefined` for uncontrolled components.

In the fiddle, if I change this line:

let newSelection = nowHidden ? "" : this.state.selected;

to

let newSelection = nowHidden ? undefined : this.state.selected;

I get the behavior I expect.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
I've gotten this with React 15.3.0 and whichever version is used in the fiddle. I don't know if it worked in previous versions.
This was tested using Chrome 56 on OS X.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions