Skip to content

Commit 0efce14

Browse files
authored
Merge pull request #8442 from marmelab/revert-8422-fix-numberinput-format-parse
Revert "Fix `NumberInput` not passing `format` and `parse` props to `useInput` call"
2 parents 7e9b7a1 + e574c20 commit 0efce14

File tree

3 files changed

+2
-76
lines changed

3 files changed

+2
-76
lines changed

packages/ra-ui-materialui/src/input/NumberInput.spec.tsx

+1-27
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { AdminContext } from '../AdminContext';
77
import { SaveButton } from '../button';
88
import { SimpleForm, Toolbar } from '../form';
99
import { required } from 'ra-core';
10-
import { Format, Parse } from './NumberInput.stories';
1110

1211
describe('<NumberInput />', () => {
1312
const defaultProps = {
@@ -199,7 +198,7 @@ describe('<NumberInput />', () => {
199198
});
200199

201200
describe('format and parse', () => {
202-
it('should get the same value as injected value', async () => {
201+
it('should get the same value as injected value ', async () => {
203202
const onSubmit = jest.fn();
204203

205204
render(
@@ -291,31 +290,6 @@ describe('<NumberInput />', () => {
291290
});
292291
expect(onSubmit.mock.calls[0][0].views).toBeNull();
293292
});
294-
295-
it('should use custom format function prop', async () => {
296-
render(<Format />);
297-
298-
const input = screen.getByLabelText('resources.posts.fields.views');
299-
fireEvent.change(input, { target: { value: 5.6356487 } });
300-
301-
await waitFor(() => {
302-
expect((input as HTMLInputElement).value).toEqual('5.6356487');
303-
expect(
304-
(screen.getByDisplayValue('5.64') as HTMLInputElement).value
305-
).toEqual('5.64');
306-
});
307-
});
308-
309-
it('should use custom parse function prop', async () => {
310-
render(<Parse />);
311-
312-
const input = screen.getByLabelText('Parse to two decimal');
313-
fireEvent.change(input, { target: { value: 5.6356487 } });
314-
315-
await waitFor(() => {
316-
expect((input as HTMLInputElement).value).toEqual('5.64');
317-
});
318-
});
319293
});
320294

321295
describe('onChange event', () => {

packages/ra-ui-materialui/src/input/NumberInput.stories.tsx

-46
Original file line numberDiff line numberDiff line change
@@ -313,49 +313,3 @@ export const FieldState = () => (
313313
</Create>
314314
</AdminContext>
315315
);
316-
317-
export const Format = () => (
318-
<AdminContext>
319-
<Create
320-
resource="posts"
321-
record={{ id: 123, views: 3.7594157 }}
322-
sx={{ width: 600 }}
323-
>
324-
<SimpleForm>
325-
<NumberInput source="views" />
326-
<NumberInput
327-
source="views"
328-
label="Two decimals"
329-
format={v =>
330-
isNaN(v) ? 0 : Number(parseFloat(v).toFixed(2))
331-
}
332-
disabled
333-
/>
334-
<FormInspector name="views" />
335-
</SimpleForm>
336-
</Create>
337-
</AdminContext>
338-
);
339-
340-
export const Parse = () => (
341-
<AdminContext>
342-
<Create
343-
resource="posts"
344-
record={{ id: 123, views: 3.77 }}
345-
sx={{ width: 600 }}
346-
>
347-
<SimpleForm>
348-
<NumberInput
349-
source="views"
350-
label="Parse to two decimal"
351-
format={v => (v ? String(v) : '0')}
352-
parse={v => {
353-
const float = Number(parseFloat(v).toFixed(2));
354-
return isNaN(float) ? null : float;
355-
}}
356-
/>
357-
<FormInspector name="views" />
358-
</SimpleForm>
359-
</Create>
360-
</AdminContext>
361-
);

packages/ra-ui-materialui/src/input/NumberInput.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ export const NumberInput = ({
4747
isRequired,
4848
} = useInput({
4949
defaultValue,
50-
format,
51-
parse,
5250
onBlur,
5351
resource,
5452
source,
@@ -60,7 +58,7 @@ export const NumberInput = ({
6058

6159
// This is a controlled input that renders directly the string typed by the user.
6260
// This string is converted to a number on change, and stored in the form state,
63-
// but that number is not displayed.
61+
// but that number is not not displayed.
6462
// This is to allow transitory values like '1.0' that will lead to '1.02'
6563

6664
// text typed by the user and displayed in the input, unparsed

0 commit comments

Comments
 (0)