Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-4776 fix: input default value handling #2518

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,8 @@ export const InputFieldState: InputFieldType = observer<InputFieldStateProps<any
return null;
}

return (
<InputFieldBase
{...rest}
ref={ref}
name={name}
value={(controlState.stringValue || controlState.defaultValue) ?? ''}
onChange={controlState.onChange}
/>
);
const defaultValue = rest.type === 'password' ? null : controlState.defaultStringValue;

return <InputFieldBase {...rest} ref={ref} name={name} value={controlState.stringValue ?? defaultValue ?? ''} onChange={controlState.onChange} />;
}),
) as InputFieldType;
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ export function useFormStateControl<TState extends Record<string, any>, TKey ext
value = value[name];
}

let stringValue: string | typeof value;
let defaultStringValue: string | typeof defaultValue;
let stringValue: string | typeof value | null;
let defaultStringValue: string | typeof defaultValue | null;
if (mapToString) {
stringValue = mapToString(value as any);
defaultStringValue = mapToString(defaultValue as any);
} else {
stringValue = isNotNullDefined(value) ? String(value) : '';
defaultStringValue = isNotNullDefined(defaultValue) ? String(defaultValue) : '';
stringValue = isNotNullDefined(value) ? String(value) : null;
defaultStringValue = isNotNullDefined(defaultValue) ? String(defaultValue) : null;
}

const hide = 'autoHide' in rest && !!rest.autoHide && presented === false;
Expand Down
Loading