fix(widget-number): allow zero as value (#2261)

This commit is contained in:
Luis Correia 2019-04-02 22:47:52 +01:00 committed by Shawn Erquhart
parent 9e08b65502
commit 800c3ee1a4
2 changed files with 12 additions and 1 deletions

View File

@ -100,7 +100,7 @@ export default class NumberControl extends React.Component {
className={classNameWrapper}
onFocus={setActiveStyle}
onBlur={setInactiveStyle}
value={value || ''}
value={value || (value === 0 ? value : '')}
step={step}
min={min}
max={max}

View File

@ -119,4 +119,15 @@ describe('Number widget', () => {
expect(onChangeSpy).toHaveBeenCalledTimes(1);
expect(onChangeSpy).toHaveBeenCalledWith(parseInt(testValue, 10));
});
it('should allow 0 as a value', () => {
const field = fromJS(fieldSettings);
const testValue = 0;
const { input } = setup({ field });
fireEvent.focus(input);
fireEvent.change(input, { target: { value: String(testValue) } });
expect(input.value).toBe('0');
});
});