diff --git a/packages/uniforms-antd/__tests__/SelectField.tsx b/packages/uniforms-antd/__tests__/SelectField.tsx index 2566a4da2..3ee8f7730 100644 --- a/packages/uniforms-antd/__tests__/SelectField.tsx +++ b/packages/uniforms-antd/__tests__/SelectField.tsx @@ -177,6 +177,21 @@ test(' - renders a select which correctly reacts on change (array)' expect(onChange).toHaveBeenLastCalledWith('x', ['b']); }); +test(' - renders a select (undefined values)', () => { + const element = ; + const wrapper = mount( + element, + createContext({ + x: { type: Array }, + 'x.$': { type: String, allowedValues: ['a', 'b'] }, + }), + ); + + expect(wrapper.find(Select)).toHaveLength(1); + expect(wrapper.find(Select).prop('value')).not.toContain(undefined); + expect(wrapper.find(Select).prop('value')).toContain('a'); +}); + test(' - renders a select which correctly reacts on change (empty)', () => { const onChange = jest.fn(); diff --git a/packages/uniforms-antd/src/SelectField.tsx b/packages/uniforms-antd/src/SelectField.tsx index b158ee474..77913add7 100644 --- a/packages/uniforms-antd/src/SelectField.tsx +++ b/packages/uniforms-antd/src/SelectField.tsx @@ -39,7 +39,13 @@ const renderSelect = props => ( onChange={value => props.onChange(value)} placeholder={props.placeholder} ref={props.inputRef} - value={props.value || (props.fieldType === Array ? [] : undefined)} + value={ + props.fieldType === Array + ? props.value + ? props.value.filter(value => value !== undefined) + : [] + : props.value + } {...filterDOMProps(props)} > {props.allowedValues.map(value => (