Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixes
  • Loading branch information
gaearon committed Aug 1, 2018
commit a6a8d1cd471befd072fd43617a49528e0ee140e4
16 changes: 3 additions & 13 deletions packages/react-dom/src/__tests__/ReactDOMSelect-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ describe('ReactDOMSelect', () => {
expect(node.options[2].selected).toBe(false); // gorilla
});

it('Options with stateful children; it should change its state properly and shouldn\'t fail', () => {
it('should support options with dynamic children', () => {
const container = document.createElement('div');

let node;
Expand All @@ -566,25 +566,15 @@ describe('ReactDOMSelect', () => {
);
}

ReactDOM.render(
<App value={'monkey'} />,
container,
);

ReactDOM.render(<App value="monkey" />, container);
expect(node.options[0].selected).toBe(true); // monkey
expect(node.options[1].selected).toBe(false); // giraffe
expect(node.options[2].selected).toBe(false); // gorilla


ReactDOM.render(
<App value={'giraffe'} />,
container,
);

ReactDOM.render(<App value="giraffe" />, container);
expect(node.options[0].selected).toBe(false); // monkey
expect(node.options[1].selected).toBe(true); // giraffe
expect(node.options[2].selected).toBe(false); // gorilla

});

it('should warn if value is null', () => {
Expand Down
8 changes: 6 additions & 2 deletions packages/react-dom/src/client/ReactDOMFiberComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ export function setInitialProperties(
tag: string,
rawProps: Object,
rootContainerElement: Element | Document,
hostContext: Object,
hostContext: *,
): void {
const isCustomComponentTag = isCustomComponent(tag, rawProps);
if (__DEV__) {
Expand Down Expand Up @@ -486,7 +486,11 @@ export function setInitialProperties(
break;
case 'option':
ReactDOMFiberOption.validateProps(domElement, rawProps);
props = ReactDOMFiberOption.getHostProps(domElement, rawProps, hostContext);
props = ReactDOMFiberOption.getHostProps(
domElement,
rawProps,
hostContext,
);
break;
case 'select':
ReactDOMFiberSelect.initWrapperState(domElement, rawProps);
Expand Down
15 changes: 10 additions & 5 deletions packages/react-dom/src/client/ReactDOMFiberOption.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
* @flow
*/

import type {HostContextDev} from './ReactDOMHostConfig';

import React from 'react';
import warning from 'shared/warning';
import validateDOMNesting from './validateDOMNesting';

let didWarnSelectedSetOnOption = false;

function flattenChildren(children, hostContext = {}) {
function flattenChildren(children, hostContext) {
let content = '';

// Flatten children and warn if they aren't strings or numbers;
Expand All @@ -27,9 +29,12 @@ function flattenChildren(children, hostContext = {}) {
return;
}
if (__DEV__) {
// We do not have HostContext here, but we can at least
// put some parent information
validateDOMNesting(child.type, null, hostContext.ancestorInfo);
const hostContextDev = ((hostContext: any): HostContextDev);
const optionAncestorInfo = validateDOMNesting.updatedAncestorInfo(
hostContextDev.ancestorInfo,
'option',
);
validateDOMNesting(child.type, null, optionAncestorInfo);
}
});

Expand Down Expand Up @@ -61,7 +66,7 @@ export function postMountWrapper(element: Element, props: Object) {
}
}

export function getHostProps(element: Element, props: Object, hostContext: Object = {}) {
export function getHostProps(element: Element, props: Object, hostContext: *) {
const hostProps = {children: undefined, ...props};
const content = flattenChildren(props.children, hostContext);

Expand Down
10 changes: 8 additions & 2 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type Instance = Element;
export type TextInstance = Text;
export type HydratableInstance = Element | Text;
export type PublicInstance = Element | Text;
type HostContextDev = {
export type HostContextDev = {
namespace: string,
ancestorInfo: mixed,
};
Expand Down Expand Up @@ -208,7 +208,13 @@ export function finalizeInitialChildren(
rootContainerInstance: Container,
hostContext: HostContext,
): boolean {
setInitialProperties(domElement, type, props, rootContainerInstance, hostContext);
setInitialProperties(
domElement,
type,
props,
rootContainerInstance,
hostContext,
);
return shouldAutoFocusHostComponent(type, props);
}

Expand Down