Skip to content
Merged
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
40 changes: 6 additions & 34 deletions packages/react-dom-bindings/src/client/ReactDOMInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@ import {checkAttributeStringCoercion} from 'shared/CheckStringCoercion';

import type {ToStringValue} from './ToStringValue';

export type InputWithWrapperState = HTMLInputElement & {
_wrapperState: {
initialValue: ToStringValue,
initialChecked: ?boolean,
controlled?: boolean,
...
},
checked: boolean,
value: string,
defaultChecked: boolean,
defaultValue: string,
...
};

let didWarnValueDefaultValue = false;
let didWarnCheckedDefaultChecked = false;

Expand Down Expand Up @@ -93,32 +79,18 @@ export function initInput(element: Element, props: Object) {
didWarnValueDefaultValue = true;
}
}

const node = ((element: any): InputWithWrapperState);
const defaultValue = props.defaultValue == null ? '' : props.defaultValue;
const initialChecked =
props.checked != null ? props.checked : props.defaultChecked;
node._wrapperState = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

initialChecked:
typeof initialChecked !== 'function' &&
typeof initialChecked !== 'symbol' &&
!!initialChecked,
initialValue: getToStringValue(
props.value != null ? props.value : defaultValue,
),
};
}

export function updateInputChecked(element: Element, props: Object) {
const node = ((element: any): InputWithWrapperState);
const node: HTMLInputElement = (element: any);
const checked = props.checked;
if (checked != null) {
node.checked = checked;
}
}

export function updateInput(element: Element, props: Object) {
const node = ((element: any): InputWithWrapperState);
const node: HTMLInputElement = (element: any);

updateInputChecked(element, props);

Expand Down Expand Up @@ -189,7 +161,7 @@ export function postInitInput(
props: Object,
isHydrating: boolean,
) {
const node = ((element: any): InputWithWrapperState);
const node: HTMLInputElement = (element: any);

if (props.value != null || props.defaultValue != null) {
const type = props.type;
Expand Down Expand Up @@ -309,12 +281,12 @@ export function postInitInput(
}

export function restoreControlledInputState(element: Element, props: Object) {
const node = ((element: any): InputWithWrapperState);
const node: HTMLInputElement = (element: any);
updateInput(node, props);
updateNamedCousins(node, props);
}

function updateNamedCousins(rootNode: InputWithWrapperState, props: any) {
function updateNamedCousins(rootNode: HTMLInputElement, props: any) {
const name = props.name;
if (props.type === 'radio' && name != null) {
let queryRoot: Element = rootNode;
Expand Down Expand Up @@ -376,7 +348,7 @@ function updateNamedCousins(rootNode: InputWithWrapperState, props: any) {
//
// https://github.com/facebook/react/issues/7253
export function setDefaultValue(
node: InputWithWrapperState,
node: HTMLInputElement,
type: ?string,
value: ToStringValue,
) {
Expand Down