Skip to content

Commit

Permalink
Merge pull request #3815 from marmelab/fix-final-form-props-spread
Browse files Browse the repository at this point in the history
Fix FinalForm Props Leak to Root Component
  • Loading branch information
fzaninotto authored Oct 14, 2019
2 parents dd78406 + 1106271 commit 46e97e6
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const AutocompleteArrayInput: FunctionComponent<
choices = [],
emptyText,
emptyValue,
format,
helperText,
id: idOverride,
input: inputOverride,
Expand All @@ -117,6 +118,7 @@ const AutocompleteArrayInput: FunctionComponent<
} = {},
optionText = 'name',
optionValue = 'id',
parse,
resource,
setFilter,
shouldRenderSuggestions: shouldRenderSuggestionsOverride,
Expand Down Expand Up @@ -147,13 +149,15 @@ const AutocompleteArrayInput: FunctionComponent<
isRequired,
meta: { touched, error },
} = useInput({
format,
id: idOverride,
input: inputOverride,
isRequired: isRequiredOverride,
meta: metaOverride,
onBlur,
onChange,
onFocus,
parse,
resource,
source,
validate,
Expand Down
4 changes: 4 additions & 0 deletions packages/ra-ui-materialui/src/input/AutocompleteInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const AutocompleteInput: FunctionComponent<
choices = [],
emptyText,
emptyValue,
format,
helperText,
id: idOverride,
input: inputOverride,
Expand All @@ -117,6 +118,7 @@ const AutocompleteInput: FunctionComponent<
} = {},
optionText = 'name',
optionValue = 'id',
parse,
resource,
setFilter,
shouldRenderSuggestions: shouldRenderSuggestionsOverride,
Expand Down Expand Up @@ -147,13 +149,15 @@ const AutocompleteInput: FunctionComponent<
isRequired,
meta: { touched, error },
} = useInput({
format,
id: idOverride,
input: inputOverride,
isRequired: isRequiredOverride,
meta: metaOverride,
onBlur,
onChange,
onFocus,
parse,
resource,
source,
validate,
Expand Down
4 changes: 4 additions & 0 deletions packages/ra-ui-materialui/src/input/BooleanInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ const BooleanInput: FunctionComponent<
InputProps<SwitchProps> &
Omit<FormGroupProps, 'defaultValue' | 'onChange' | 'onBlur' | 'onFocus'>
> = ({
format,
label,
fullWidth,
helperText,
onBlur,
onChange,
onFocus,
options,
parse,
resource,
source,
validate,
Expand All @@ -32,9 +34,11 @@ const BooleanInput: FunctionComponent<
isRequired,
meta: { error, touched },
} = useInput({
format,
onBlur,
onChange,
onFocus,
parse,
resource,
source,
type: 'checkbox',
Expand Down
4 changes: 4 additions & 0 deletions packages/ra-ui-materialui/src/input/CheckboxGroupInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const CheckboxGroupInput: FunctionComponent<
ChoicesProps & InputProps<CheckboxProps> & FormControlProps
> = ({
choices = [],
format,
helperText,
label,
onBlur,
Expand All @@ -102,6 +103,7 @@ const CheckboxGroupInput: FunctionComponent<
optionText,
optionValue,
options,
parse,
resource,
row,
source,
Expand All @@ -118,9 +120,11 @@ const CheckboxGroupInput: FunctionComponent<
isRequired,
meta: { error, touched },
} = useInput({
format,
onBlur,
onChange,
onFocus,
parse,
resource,
source,
validate,
Expand Down
5 changes: 4 additions & 1 deletion packages/ra-ui-materialui/src/input/DateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const convertDateToString = (value: Date) => {

const dateRegex = /^\d{4}-\d{2}-\d{2}$/;

const format = (value: string | Date) => {
const getStringFromDate = (value: string | Date) => {
// null, undefined and empty string values should not go through dateFormatter
// otherwise, it returns undefined and will make the input an uncontrolled one.
if (value == null || value === '') {
Expand All @@ -45,6 +45,7 @@ const format = (value: string | Date) => {
export const DateInput: FunctionComponent<
InputProps<TextFieldProps> & Omit<TextFieldProps, 'helperText' | 'label'>
> = ({
format = getStringFromDate,
label,
options,
source,
Expand All @@ -54,6 +55,7 @@ export const DateInput: FunctionComponent<
onBlur,
onChange,
onFocus,
parse,
validate,
variant = 'filled',
...rest
Expand All @@ -68,6 +70,7 @@ export const DateInput: FunctionComponent<
onBlur,
onChange,
onFocus,
parse,
resource,
source,
validate,
Expand Down
6 changes: 4 additions & 2 deletions packages/ra-ui-materialui/src/input/FileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const FileInput: FunctionComponent<
children,
className,
classes: classesOverride,
format,
helperText,
label,
labelMultiple = 'ra.input.file.upload_several',
Expand All @@ -59,6 +60,7 @@ const FileInput: FunctionComponent<
minSize,
multiple = false,
options: { inputProps: inputPropsOptions, ...options } = {},
parse,
placeholder,
resource,
source,
Expand Down Expand Up @@ -109,8 +111,8 @@ const FileInput: FunctionComponent<
meta,
isRequired,
} = useInput({
format: transformFiles,
parse: transformFiles,
format: format || transformFiles,
parse: parse || transformFiles,
source,
type: 'file',
validate,
Expand Down
6 changes: 4 additions & 2 deletions packages/ra-ui-materialui/src/input/NullableBooleanInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ const NullableBooleanInput: FunctionComponent<
InputProps<TextFieldProps> & Omit<TextFieldProps, 'label' | 'helperText'>
> = ({
className,
format = getStringFromBoolean,
helperText,
label,
margin = 'dense',
onBlur,
onChange,
onFocus,
options,
parse = getBooleanFromString,
resource,
source,
validate,
Expand All @@ -51,11 +53,11 @@ const NullableBooleanInput: FunctionComponent<
isRequired,
meta: { error, touched },
} = useInput({
format: getStringFromBoolean,
format,
onBlur,
onChange,
onFocus,
parse: getBooleanFromString,
parse,
resource,
source,
type: 'checkbox',
Expand Down
4 changes: 3 additions & 1 deletion packages/ra-ui-materialui/src/input/NumberInput.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ describe('<NumberInput />', () => {
render={() => <NumberInput {...defaultProps} step="0.1" />}
/>
);
const input = getByLabelText('resources.posts.fields.views');
const input = getByLabelText(
'resources.posts.fields.views'
) as HTMLInputElement;
expect(input.step).toEqual('0.1');
});
});
Expand Down
15 changes: 9 additions & 6 deletions packages/ra-ui-materialui/src/input/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { useInput, FieldTitle, InputProps } from 'ra-core';
import InputHelperText from './InputHelperText';
import sanitizeRestProps from './sanitizeRestProps';

const parse = value => {
const convertStringToNumber = value => {
const float = parseFloat(value);

return isNaN(float) ? null : float;
};

interface Props {
step: string | number;
step?: string | number;
}

/**
Expand All @@ -33,16 +33,18 @@ const NumberInput: FunctionComponent<
InputProps<TextFieldProps> &
Omit<TextFieldProps, 'label' | 'helperText'>
> = ({
format,
helperText,
label,
margin = 'dense',
options,
source,
step,
resource,
onBlur,
onFocus,
onChange,
options,
parse = convertStringToNumber,
resource,
source,
step,
validate,
variant = 'filled',
inputProps: overrideInputProps,
Expand All @@ -54,6 +56,7 @@ const NumberInput: FunctionComponent<
isRequired,
meta: { error, touched },
} = useInput({
format,
onBlur,
onChange,
onFocus,
Expand Down
4 changes: 4 additions & 0 deletions packages/ra-ui-materialui/src/input/RadioButtonGroupInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const RadioButtonGroupInput: FunctionComponent<
> = ({
choices = [],
classes: classesOverride,
format,
helperText,
label,
onBlur,
Expand All @@ -92,6 +93,7 @@ export const RadioButtonGroupInput: FunctionComponent<
options,
optionText,
optionValue,
parse,
resource,
source,
translateChoice,
Expand All @@ -106,9 +108,11 @@ export const RadioButtonGroupInput: FunctionComponent<
isRequired,
meta: { error, touched },
} = useInput({
format,
onBlur,
onChange,
onFocus,
parse,
resource,
source,
validate,
Expand Down
4 changes: 4 additions & 0 deletions packages/ra-ui-materialui/src/input/ReferenceInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,20 @@ interface Props {
* </ReferenceInput>
*/
export const ReferenceInput: FunctionComponent<Props & InputProps> = ({
format,
onBlur,
onChange,
onFocus,
parse,
validate,
...props
}) => {
const inputProps = useInput({
format,
onBlur,
onChange,
onFocus,
parse,
validate,
...props,
});
Expand Down
6 changes: 5 additions & 1 deletion packages/ra-ui-materialui/src/input/SelectArrayInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,17 @@ const SelectArrayInput: FunctionComponent<
choices = [],
classes: classesOverride,
className,
format,
helperText,
label,
margin = 'dense',
helperText,
onBlur,
onChange,
onFocus,
options,
optionText,
optionValue,
parse,
resource,
source,
translateChoice,
Expand All @@ -165,9 +167,11 @@ const SelectArrayInput: FunctionComponent<
isRequired,
meta: { error, touched },
} = useInput({
format,
onBlur,
onChange,
onFocus,
parse,
resource,
source,
validate,
Expand Down
4 changes: 4 additions & 0 deletions packages/ra-ui-materialui/src/input/SelectInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const SelectInput: FunctionComponent<
disableValue,
emptyText,
emptyValue,
format,
helperText,
label,
onBlur,
Expand All @@ -156,6 +157,7 @@ const SelectInput: FunctionComponent<
options,
optionText,
optionValue,
parse,
resource,
source,
translateChoice,
Expand All @@ -176,9 +178,11 @@ const SelectInput: FunctionComponent<
isRequired,
meta: { error, touched },
} = useInput({
format,
onBlur,
onChange,
onFocus,
parse,
resource,
source,
validate,
Expand Down
Loading

0 comments on commit 46e97e6

Please sign in to comment.