Lucifier129 / react-lite

An implementation of React v15.x that optimizes for small script size
MIT License
1.73k stars 100 forks source link

Select Value not selecting option #125

Closed gpltaylor closed 6 years ago

gpltaylor commented 6 years ago

When using "select" tag, the selected option is not displayed. This works in Chrome, but not IE or Edge.

Expected Dropdown to show with the selected value picked in Edge or IE.

Actual The first item is selected

Example https://jsfiddle.net/xy99xexh/3/

Lucifier129 commented 6 years ago

try selected attribute, it can work

<option value="0" key="0">zero</option>
<option value="1" key="1">1</option>
<option selected={typeValue === 2} value="2" key="2">2</option>
 <option value="3" key="3">3</option>
<option value="4" key="4">4</option>

An Option component will be better

function Option({ value, select, children }) {
  return <option selected={value === select} value={value}>{children}</options>
}
gpltaylor commented 6 years ago

Hi @Lucifier129 thank you for your response. We have implemented this solution, however, we get React warning to use value or defaultValue within the select tag.

Do you think that React/lite will remove support for this? I want to limit technical debt for upgrading.

Lucifier129 commented 6 years ago

@gpltaylor No, selected is a native dom property, I think react and react-lite will always support this feature.

gpltaylor commented 6 years ago

Thanx @Lucifier129 I will implement this shortcut. Will react-lite be updated to support this or do you want me to close this issue? It's working in some browsers and is a bug in React-lite (IMO)...

Lucifier129 commented 6 years ago

Yeah, it is a bug of react-lite, let's keep this issue open until it has been resolved~

gpltaylor commented 6 years ago

Ta, and thank you for the effort you put into this project. 👍

gpltaylor commented 6 years ago

Hi @Lucifier129 I have submitted a pull request https://github.com/Lucifier129/react-lite/pull/127