(element, props)
| 1984 | } |
| 1985 | } |
| 1986 | function updateWrapper(element, props) { |
| 1987 | var node = element; |
| 1988 | |
| 1989 | { |
| 1990 | var controlled = isControlled(props); |
| 1991 | |
| 1992 | if (!node._wrapperState.controlled && controlled && !didWarnUncontrolledToControlled) { |
| 1993 | error('A component is changing an uncontrolled input of type %s to be controlled. ' + 'Input elements should not switch from uncontrolled to controlled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + 'element for the lifetime of the component. More info: https://fb.me/react-controlled-components', props.type); |
| 1994 | |
| 1995 | didWarnUncontrolledToControlled = true; |
| 1996 | } |
| 1997 | |
| 1998 | if (node._wrapperState.controlled && !controlled && !didWarnControlledToUncontrolled) { |
| 1999 | error('A component is changing a controlled input of type %s to be uncontrolled. ' + 'Input elements should not switch from controlled to uncontrolled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + 'element for the lifetime of the component. More info: https://fb.me/react-controlled-components', props.type); |
| 2000 | |
| 2001 | didWarnControlledToUncontrolled = true; |
| 2002 | } |
| 2003 | } |
| 2004 | |
| 2005 | updateChecked(element, props); |
| 2006 | var value = getToStringValue(props.value); |
| 2007 | var type = props.type; |
| 2008 | |
| 2009 | if (value != null) { |
| 2010 | if (type === 'number') { |
| 2011 | if (value === 0 && node.value === '' || // We explicitly want to coerce to number here if possible. |
| 2012 | // eslint-disable-next-line |
| 2013 | node.value != value) { |
| 2014 | node.value = toString(value); |
| 2015 | } |
| 2016 | } else if (node.value !== toString(value)) { |
| 2017 | node.value = toString(value); |
| 2018 | } |
| 2019 | } else if (type === 'submit' || type === 'reset') { |
| 2020 | // Submit/reset inputs need the attribute removed completely to avoid |
| 2021 | // blank-text buttons. |
| 2022 | node.removeAttribute('value'); |
| 2023 | return; |
| 2024 | } |
| 2025 | |
| 2026 | { |
| 2027 | // When syncing the value attribute, the value comes from a cascade of |
| 2028 | // properties: |
| 2029 | // 1. The value React property |
| 2030 | // 2. The defaultValue React property |
| 2031 | // 3. Otherwise there should be no change |
| 2032 | if (props.hasOwnProperty('value')) { |
| 2033 | setDefaultValue(node, props.type, value); |
| 2034 | } else if (props.hasOwnProperty('defaultValue')) { |
| 2035 | setDefaultValue(node, props.type, getToStringValue(props.defaultValue)); |
| 2036 | } |
| 2037 | } |
| 2038 | |
| 2039 | { |
| 2040 | // When syncing the checked attribute, it only changes when it needs |
| 2041 | // to be removed, such as transitioning from a checkbox into a text input |
| 2042 | if (props.checked == null && props.defaultChecked != null) { |
| 2043 | node.defaultChecked = !!props.defaultChecked; |
no test coverage detected