Skip to content

Commit

Permalink
Merge pull request #5890 from facebook/chore/fix-input-component-chan…
Browse files Browse the repository at this point in the history
…ging-from-uncontrolled-to-controlled

ReactJS: Fix an input component changing from uncontrolled to controlled
  • Loading branch information
HelNershingThapa committed Jun 22, 2023
2 parents d1e1c9f + 93803fb commit f65fc5e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
5 changes: 4 additions & 1 deletion frontend/src/components/projectEdit/metadataForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ export const MetadataForm = () => {
values={{ link: <IdDocsLink /> }}
/>
</p>
<ExtraIdParams value={projectInfo.extraIdParams} setProjectInfo={setProjectInfo} />
<ExtraIdParams
value={projectInfo.extraIdParams ? projectInfo.extraIdParams : ''}
setProjectInfo={setProjectInfo}
/>
</div>
<div className={styleClasses.divClass}>
<label className={styleClasses.labelClass}>
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/components/user/forms/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,37 @@ export function UserNotificationsForm(props) {
labelId: 'mentions',
descriptionId: 'mentionsDescription',
fieldName: 'mentionsNotifications',
default: true,
},
{
labelId: 'teamUpdates',
descriptionId: 'teamUpdatesDescription',
fieldName: 'teamsAnnouncementNotifications',
default: false,
},
{
labelId: 'taskUpdates',
descriptionId: 'taskUpdatesDescription',
fieldName: 'tasksNotifications',
default: true,
},
{
labelId: 'projectUpdates',
descriptionId: 'projectUpdatesDescription',
fieldName: 'projectsNotifications',
default: true,
},
{
labelId: 'questionsAndComments',
descriptionId: 'questionsAndCommentsDescription',
fieldName: 'questionsAndCommentsNotifications',
default: false,
},
{
labelId: 'taskComments',
descriptionId: 'taskCommentsDescription',
fieldName: 'taskCommentsNotifications',
default: false,
},
];

Expand All @@ -51,7 +57,11 @@ export function UserNotificationsForm(props) {
labelId={field.labelId}
descriptionId={field.descriptionId}
>
<SwitchToggleField fieldName={field.fieldName} removeVerticalPadding />
<SwitchToggleField
fieldName={field.fieldName}
default={field.default}
removeVerticalPadding
/>
</CustomField>
))}
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/user/forms/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function _UserSettingsForm(props) {
</h3>
<div className="blue-grey">
<CustomField labelId="expertMode" descriptionId="expertModeDescription">
<SwitchToggleField fieldName="isExpert" removeVerticalPadding />
<SwitchToggleField fieldName="isExpert" default={false} removeVerticalPadding />
</CustomField>
<CustomField labelId="defaultEditor" descriptionId="defaultEditorDescription" isDropdown>
<EditorDropdown />
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/user/forms/switchToggleField.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ function _SwitchToggleField(props) {
setValue(!value);
};

let val = value;
if ((val === undefined || val === null) && props.hasOwnProperty('default')) {
val = props.default;
}
return (
<div className={`fr ${props.removeVerticalPadding ? '' : 'pv2'} dib`}>
<SwitchToggle onChange={(e) => onSwitchChange()} isChecked={value} />
<SwitchToggle onChange={(e) => onSwitchChange()} isChecked={val} />
</div>
);
}
Expand Down

0 comments on commit f65fc5e

Please sign in to comment.