Skip to content

Commit

Permalink
Fix React Vanilla IntegerCell not rendering zero
Browse files Browse the repository at this point in the history
The React Vanilla IntegerCell now correctly displays the number 0
instead of an empty string.
  • Loading branch information
nmay231 authored Apr 11, 2022
1 parent 7e5ac13 commit 23e1a55
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vanilla/src/cells/IntegerCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const IntegerCell = (props: CellProps & VanillaRendererProps) => {
<input
type='number'
step='1'
value={data || ''}
value={data ?? ''}
onChange={ev => handleChange(path, parseInt(ev.target.value, 10))}
className={className}
id={id}
Expand Down
11 changes: 11 additions & 0 deletions packages/vanilla/test/renderers/IntegerCell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,15 @@ describe('Integer cell', () => {
const input = wrapper.find('input').getDOMNode() as HTMLInputElement;
expect(input.disabled).toBe(false);
});

test('shows 0 instead of empty string', () => {
const core = initCore(fixture.schema, fixture.uischema, { foo: 0 });
wrapper = mount(
<JsonFormsStateProvider initState={{ core }}>
<IntegerCell schema={fixture.schema} uischema={fixture.uischema} path='foo' />
</JsonFormsStateProvider>
);
const input = wrapper.find('input').getDOMNode() as HTMLInputElement;
expect(input.value).toBe('0');
});
});

0 comments on commit 23e1a55

Please sign in to comment.