Skip to content

Commit 64c9ff5

Browse files
authored
fix: no need warning when provide optionLabelProp (#717)
1 parent efcacc0 commit 64c9ff5

File tree

2 files changed

+54
-26
lines changed

2 files changed

+54
-26
lines changed

src/Select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ const Select = React.forwardRef(
253253
rawDisabled = option?.disabled;
254254

255255
// Warning if label not same as provided
256-
if (process.env.NODE_ENV !== 'production' && !isRawValue(val)) {
256+
if (process.env.NODE_ENV !== 'production' && !optionLabelProp) {
257257
const optionLabel = option?.[mergedFieldNames.label];
258258
if (optionLabel !== undefined && optionLabel !== rawLabel) {
259259
warning(false, '`label` of `value` is not same as `label` in Select options.');

tests/Multiple.test.tsx

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -475,31 +475,59 @@ describe('Select.Multiple', () => {
475475
expect(wrapper.exists('.rc-select-selection-item-remove')).toBeFalsy();
476476
});
477477

478-
it('optionLabelProp', () => {
479-
const wrapper = mount(
480-
<Select
481-
mode="multiple"
482-
value={['bamboo', 'little']}
483-
open
484-
optionLabelProp="selector"
485-
options={[
486-
{
487-
label: 'Bamboo',
488-
value: 'bamboo',
489-
selector: 'BAMBOO',
490-
},
491-
{
492-
label: 'Little',
493-
value: 'little',
494-
selector: 'LITTLE',
495-
},
496-
]}
497-
/>,
498-
);
478+
describe('optionLabelProp', () => {
479+
it('basic', () => {
480+
const wrapper = mount(
481+
<Select
482+
mode="multiple"
483+
value={['bamboo', 'little']}
484+
open
485+
optionLabelProp="selector"
486+
options={[
487+
{
488+
label: 'Bamboo',
489+
value: 'bamboo',
490+
selector: 'BAMBOO',
491+
},
492+
{
493+
label: 'Little',
494+
value: 'little',
495+
selector: 'LITTLE',
496+
},
497+
]}
498+
/>,
499+
);
499500

500-
expect(findSelection(wrapper, 0).text()).toBe('BAMBOO');
501-
expect(findSelection(wrapper, 1).text()).toBe('LITTLE');
502-
expect(wrapper.find('div.rc-select-item-option-content').at(0).text()).toBe('Bamboo');
503-
expect(wrapper.find('div.rc-select-item-option-content').at(1).text()).toBe('Little');
501+
expect(findSelection(wrapper, 0).text()).toBe('BAMBOO');
502+
expect(findSelection(wrapper, 1).text()).toBe('LITTLE');
503+
expect(wrapper.find('div.rc-select-item-option-content').at(0).text()).toBe('Bamboo');
504+
expect(wrapper.find('div.rc-select-item-option-content').at(1).text()).toBe('Little');
505+
});
506+
507+
it('select no warning', () => {
508+
const wrapper = mount(
509+
<Select
510+
mode="multiple"
511+
open
512+
optionLabelProp="selector"
513+
options={[
514+
{
515+
label: 'Bamboo',
516+
value: 'bamboo',
517+
selector: 'BAMBOO',
518+
},
519+
]}
520+
/>,
521+
);
522+
523+
// Select one
524+
const errSpy = jest.spyOn(console, 'error');
525+
526+
toggleOpen(wrapper);
527+
selectItem(wrapper);
528+
529+
expect(errSpy).not.toHaveBeenCalled();
530+
errSpy.mockRestore();
531+
});
504532
});
505533
});

0 commit comments

Comments
 (0)