Skip to content

Commit 901baba

Browse files
committed
Fix props for <select> and <option> elements
Unlike in HTML, passing a `selected` attribute to `<option>` is not supported. Instead, the selected option's value should be passed to the`value` or `defaultValue` props of the `<select>` element. Fix #335
1 parent 55aa8d2 commit 901baba

6 files changed

Lines changed: 15 additions & 15 deletions

File tree

apps/website/docs/api/03-html/09-option.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ To display an item within `<html.select>`, render the `<html.option>` component.
1414
import { html } from 'react-strict-dom';
1515

1616
const Foo = () => (
17-
<html.select>
18-
<html.option>Red</html.option>
17+
<html.select value="red">
18+
<html.option value="red">Red</html.option>
1919
</html.select>
2020
);
2121
```
@@ -25,5 +25,4 @@ const Foo = () => (
2525
* [...Common props](/api/html/common/)
2626
* `disabled`
2727
* `label`
28-
* `selected`
2928
* `value`

apps/website/docs/api/03-html/10-select.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ title: <html.select>
88

99
## Overview
1010

11-
To display a select box, render the `<html.select` component.
11+
To display a select box, render the `<html.select>` component.
1212

1313
```jsx
1414
import { html } from 'react-strict-dom';
1515

1616
const Foo = () => (
17-
<html.select>
18-
<html.option>Red</html.option>
17+
<html.select value="red">
18+
<html.option value="red">Red</html.option>
1919
</html.select>
2020
);
2121
```
@@ -24,6 +24,7 @@ const Foo = () => (
2424

2525
* [...Common props](/api/html/common/)
2626
* `autoComplete`
27+
* `defaultValue`
2728
* `multiple`
2829
* `name`
2930
* `required`
@@ -32,3 +33,4 @@ const Foo = () => (
3233
* `onInput`
3334
* `onInvalid`
3435
* `onSelect`
36+
* `value`

packages/react-strict-dom/src/types/StrictReactDOMOptionProps.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ export type StrictReactDOMOptionProps = $ReadOnly<{
1313
...StrictReactDOMProps,
1414
disabled?: ?boolean,
1515
label?: ?Stringish,
16-
selected?: ?boolean,
1716
value?: ?Stringish
1817
}>;

packages/react-strict-dom/src/types/StrictReactDOMSelectProps.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import type { AutoComplete, StrictReactDOMProps } from './StrictReactDOMProps';
1212
export type StrictReactDOMSelectProps = $ReadOnly<{
1313
...StrictReactDOMProps,
1414
autoComplete?: AutoComplete,
15+
defaultValue?: ?(Stringish | Array<Stringish>),
1516
multiple?: ?boolean,
1617
name?: ?string,
1718
required?: ?boolean,
1819
onBeforeInput?: $FlowFixMe,
1920
onChange?: $FlowFixMe,
2021
onInput?: $FlowFixMe,
2122
onInvalid?: $FlowFixMe,
22-
onSelect?: $FlowFixMe
23+
onSelect?: $FlowFixMe,
24+
value?: ?(Stringish | Array<Stringish>)
2325
}>;

packages/react-strict-dom/tests/__snapshots__/html-test.js.snap-dom

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5070,7 +5070,6 @@ exports[`html "option" supports inline event handlers 1`] = `
50705070
exports[`html "option" supports input attributes 1`] = `
50715071
<option
50725072
className="html-option"
5073-
defaultValue="defaultValue"
50745073
disabled={true}
50755074
label="label"
50765075
ref={null}
@@ -5647,6 +5646,7 @@ exports[`html "select" ignores and warns about unsupported attributes 1`] = `
56475646
exports[`html "select" supports additional select attributes 1`] = `
56485647
<select
56495648
className="html-select x1y0btm7 x1ghz6dp x1717udv"
5649+
defaultValue="defaultValue"
56505650
disabled={true}
56515651
name="user-language"
56525652
onBeforeInput={[Function]}
@@ -5658,6 +5658,7 @@ exports[`html "select" supports additional select attributes 1`] = `
56585658
readOnly={true}
56595659
ref={null}
56605660
required={true}
5661+
value="value"
56615662
/>
56625663
`;
56635664

packages/react-strict-dom/tests/html-test.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,7 @@ describe('html', () => {
351351
let root;
352352
act(() => {
353353
root = create(
354-
<html.option
355-
defaultValue="defaultValue"
356-
disabled={true}
357-
label="label"
358-
value="value"
359-
/>
354+
<html.option disabled={true} label="label" value="value" />
360355
);
361356
});
362357
expect(root.toJSON()).toMatchSnapshot();
@@ -367,6 +362,7 @@ describe('html', () => {
367362
act(() => {
368363
root = create(
369364
<html.select
365+
defaultValue="defaultValue"
370366
disabled={true}
371367
name="user-language"
372368
onBeforeInput={function onBeforeInput() {}}
@@ -377,6 +373,7 @@ describe('html', () => {
377373
onSelectionChange={function onSelectionChange() {}}
378374
readOnly={true}
379375
required={true}
376+
value="value"
380377
/>
381378
);
382379
});

0 commit comments

Comments
 (0)