Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Selector/SingleSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ const SingleSelector: React.FC<SelectorProps> = ({
const inputEditable = combobox || (showSearch && open);
const item = values[0];

const getDisplayValue = (value: React.ReactText): string => (value === null ? '' : String(value));
let inputValue: string = searchValue;
if (combobox) {
inputValue = item ? String(item.value) : activeValue || searchValue;
inputValue = item ? getDisplayValue(item.value) : activeValue || searchValue;
}

const hasTextInput = !!inputValue;
Expand Down
41 changes: 12 additions & 29 deletions tests/Combobox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import Select, { Option, SelectProps } from '../src';
import focusTest from './shared/focusTest';
import keyDownTest from './shared/keyDownTest';
import openControlledTest from './shared/openControlledTest';
import {
expectOpen,
toggleOpen,
selectItem,
injectRunAllTimers,
} from './utils/common';
import { expectOpen, toggleOpen, selectItem, injectRunAllTimers } from './utils/common';
import allowClearTest from './shared/allowClearTest';
import throwOptionValue from './shared/throwOptionValue';

Expand Down Expand Up @@ -61,9 +56,7 @@ describe('Select.Combobox', () => {
);

expect(wrapper.find('input').props().value).toBe('');
expect(wrapper.find('.rc-select-selection-placeholder').text()).toEqual(
'placeholder',
);
expect(wrapper.find('.rc-select-selection-placeholder').text()).toEqual('placeholder');
wrapper.find('input').simulate('change', { target: { value: '1' } });
expect(wrapper.find('.rc-select-selection-placeholder').length).toBeFalsy();
expect(wrapper.find('input').props().value).toBe('1');
Expand Down Expand Up @@ -224,13 +217,7 @@ describe('Select.Combobox', () => {
const handleChange = jest.fn();
const handleSelect = jest.fn();
const wrapper = mount(
<Select
mode="combobox"
backfill
open
onChange={handleChange}
onSelect={handleSelect}
>
<Select mode="combobox" backfill open onChange={handleChange} onSelect={handleSelect}>
<Option value="One">One</Option>
<Option value="Two">Two</Option>
</Select>,
Expand All @@ -243,14 +230,8 @@ describe('Select.Combobox', () => {

input.simulate('keyDown', { which: KeyCode.ENTER });
expect(wrapper.find('input').props().value).toEqual('One');
expect(handleChange).toHaveBeenCalledWith(
'One',
expect.objectContaining({ value: 'One' }),
);
expect(handleSelect).toHaveBeenCalledWith(
'One',
expect.objectContaining({ value: 'One' }),
);
expect(handleChange).toHaveBeenCalledWith('One', expect.objectContaining({ value: 'One' }));
expect(handleSelect).toHaveBeenCalledWith('One', expect.objectContaining({ value: 'One' }));
});

it("should hide clear icon when value is ''", () => {
Expand Down Expand Up @@ -340,11 +321,7 @@ describe('Select.Combobox', () => {
jest.useFakeTimers();
const onDropdownVisibleChange = jest.fn();
const wrapper = mount(
<Select
mode="combobox"
open
onDropdownVisibleChange={onDropdownVisibleChange}
>
<Select mode="combobox" open onDropdownVisibleChange={onDropdownVisibleChange}>
<Option value="One">One</Option>
<Option value="Two">Two</Option>
</Select>,
Expand Down Expand Up @@ -399,4 +376,10 @@ describe('Select.Combobox', () => {
wrapper.update();
expectOpen(wrapper, false);
});

it('expect null value display empty string', () => {
const wrapper = mount(<Select mode="combobox" value={null} />);

expect(wrapper.find('input').props().value).toBe('');
});
});