Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit e24c332

Browse files
committed
Do not pass defaultValue into components rendered in <Control>. Fixes #630
1 parent 5a8983e commit e24c332

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/components/control-component.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const propTypes = {
6161
]).isRequired,
6262
modelValue: PropTypes.any,
6363
viewValue: PropTypes.any,
64+
defaultValue: PropTypes.any,
6465
control: PropTypes.any,
6566
onLoad: PropTypes.func,
6667
onSubmit: PropTypes.func,
@@ -463,6 +464,8 @@ function createControlClass(s = defaultStrategy) {
463464
defaultValue = controlProps.defaultValue;
464465
} else if (controlProps.hasOwnProperty('defaultChecked')) {
465466
defaultValue = controlProps.defaultChecked;
467+
} else if (this.props.hasOwnProperty('defaultValue')) {
468+
defaultValue = this.props.defaultValue;
466469
}
467470

468471
const loadActions = [this.getValidateAction(defaultValue)];

src/constants/control-props-map.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ const standardPropsMap = {
3232

3333
const textPropsMap = {
3434
...standardPropsMap,
35-
value: (props) => ((!props.defaultValue && !props.hasOwnProperty('value'))
36-
? getTextValue(props.viewValue)
37-
: props.value),
35+
// the value passed into the control is either the original control's
36+
// value prop (if the control is controlled) or the value controlled by
37+
// <Control>.
38+
value: (props) => (props.hasOwnProperty('value')
39+
? props.value
40+
: getTextValue(props.viewValue)),
3841
};
3942

4043
const getModelValue = ({ modelValue }) => modelValue;

0 commit comments

Comments
 (0)