diff --git a/src/Field.js b/src/Field.js index 8d31322b..714546da 100644 --- a/src/Field.js +++ b/src/Field.js @@ -143,18 +143,16 @@ export default class Field extends React.PureComponent { value = '' } const input = { name, value, ...this.handlers } - if (component === 'input') { - if (rest.type === 'checkbox') { - if (_value === undefined) { - input.checked = !!value - } else { - input.checked = Array.isArray(value) && ~value.indexOf(_value) - input.value = _value - } - } else if (rest.type === 'radio') { - input.checked = value === _value + if (rest.type === 'checkbox') { + if (_value === undefined) { + input.checked = !!value + } else { + input.checked = Array.isArray(value) && ~value.indexOf(_value) input.value = _value } + } else if (rest.type === 'radio') { + input.checked = value === _value + input.value = _value } if (component === 'select' && rest.multiple) { input.value = input.value || [] diff --git a/src/Field.test.js b/src/Field.test.js index b81da3b9..929a28cc 100644 --- a/src/Field.test.js +++ b/src/Field.test.js @@ -541,6 +541,40 @@ describe('Field', () => { expect(bazInput.checked).toBe(true) }) + it('should render custom radio component with checked prop', () => { + const Radio = jest.fn(() => null) + TestUtils.renderIntoDocument( +
( + + + + )} + initialValues={{ foo: 'yes' }} + /> + ) + expect(Radio.mock.calls[0][0]).toMatchObject({ input: { checked: true } }) + }) + + it('should render custom checkbox component with checked prop', () => { + const Checkbox = jest.fn(() => null) + TestUtils.renderIntoDocument( +
( + + + + )} + initialValues={{ foo: true }} + /> + ) + expect(Checkbox.mock.calls[0][0]).toMatchObject({ + input: { checked: true } + }) + }) + it('should use isEqual to calculate dirty/pristine', () => { const input = jest.fn(({ input }) => )