Skip to content

Commit

Permalink
CB-4776 fix: input default value handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Wroud committed Mar 28, 2024
1 parent f3c6cf9 commit 74f37e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
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

0 comments on commit 74f37e2

Please sign in to comment.