diff --git a/docs/examples/optgroup.tsx b/docs/examples/optgroup.tsx index cc32968a..deef68b4 100644 --- a/docs/examples/optgroup.tsx +++ b/docs/examples/optgroup.tsx @@ -1,6 +1,6 @@ /* eslint-disable no-console */ import React from 'react'; -import Select, { Option, OptGroup } from 'rc-select'; +import Select from 'rc-select'; import '../../assets/index.less'; function onChange(value, option) { @@ -16,27 +16,23 @@ const Test = () => ( defaultValue="lucy" style={{ width: 500 }} onChange={onChange} - > - - - - - - - - + options={[{ + label: 'manager', + options: [ + { label: 'jack', value: 'jack' }, + { label: 'lucy', value: 'lucy' } + ], + }, { + label: 'engineer', + options: [{ label: 'yiminghe', value: 'yiminghe' }] + }, { + label: 'bamboo', + options: undefined, + }, { + label: 'mocha', + options: null, + }]} + /> ); diff --git a/src/utils/valueUtil.ts b/src/utils/valueUtil.ts index ea332015..93501757 100644 --- a/src/utils/valueUtil.ts +++ b/src/utils/valueUtil.ts @@ -51,6 +51,10 @@ export function flattenOptions { if (isGroupOption || !(fieldOptions in data)) { const value = data[fieldValue]; diff --git a/tests/Group.test.tsx b/tests/Group.test.tsx index 0114db38..c5dc79ab 100644 --- a/tests/Group.test.tsx +++ b/tests/Group.test.tsx @@ -66,4 +66,34 @@ describe('Select.Group', () => { expect(wrapper.find('.rc-select-item-group').prop('title')).toBeUndefined(); }); }); + + it('group options exist undefined/null', () => { + const wrapper = mount( +