Skip to content

Commit 97bce99

Browse files
committed
chore: of it
1 parent 30bdebe commit 97bce99

File tree

7 files changed

+45
-33
lines changed

7 files changed

+45
-33
lines changed

docs/examples/multiple.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class Test extends React.Component {
9999
style={{ width: 500 }}
100100
mode="multiple"
101101
loading={loading}
102-
suffixIcon={suffixIcon}
102+
suffix={suffixIcon}
103103
allowClear
104104
optionFilterProp="children"
105105
optionLabelProp="children"

src/BaseSelect/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
439439
);
440440

441441
const onInternalSearch = (searchText: string, fromTyping: boolean, isCompositing: boolean) => {
442-
console.log('is', searchText);
443442
if (multiple && isValidCount(maxCount) && displayValues.length >= maxCount) {
444443
return;
445444
}

src/Select.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,6 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
611611
const onInternalSearch: BaseSelectProps['onSearch'] = (searchText, info) => {
612612
setSearchValue(searchText);
613613
setActiveValue(null);
614-
console.log('???', searchText);
615614

616615
// [Submit] Tag mode should flush input
617616
if (info.source === 'submit') {

src/SelectInput/Content/MultipleContent.tsx

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import TransBtn from '../../TransBtn';
1111
import { getTitle } from '../../utils/commonUtil';
1212
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
1313
import useBaseProps from '../../hooks/useBaseProps';
14+
import Placeholder from './Placeholder';
1415

1516
function itemKey(value: DisplayValueType) {
1617
return value.key ?? value.value;
@@ -178,24 +179,27 @@ export default React.forwardRef<HTMLInputElement, SharedContentProps>(function M
178179

179180
// ======================= Render =======================
180181
return (
181-
<Overflow
182-
prefixCls={`${prefixCls}-content`}
183-
data={displayValues}
184-
renderItem={renderItem}
185-
renderRest={renderRest}
186-
// suffix={inputNode}
187-
suffix={
188-
<Input
189-
ref={ref}
190-
disabled={disabled}
191-
readOnly={!inputEditable}
192-
{...inputProps}
193-
value={inputValue || ''}
194-
syncWidth
195-
/>
196-
}
197-
itemKey={itemKey}
198-
maxCount={maxTagCount}
199-
/>
182+
<>
183+
<Placeholder show={!searchValue || !triggerOpen} />
184+
<Overflow
185+
prefixCls={`${prefixCls}-content`}
186+
data={displayValues}
187+
renderItem={renderItem}
188+
renderRest={renderRest}
189+
// suffix={inputNode}
190+
suffix={
191+
<Input
192+
ref={ref}
193+
disabled={disabled}
194+
readOnly={!inputEditable}
195+
{...inputProps}
196+
value={inputValue || ''}
197+
syncWidth
198+
/>
199+
}
200+
itemKey={itemKey}
201+
maxCount={maxTagCount}
202+
/>
203+
</>
200204
);
201205
});

src/SelectInput/Content/Placeholder.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ import * as React from 'react';
22
import { useSelectInputContext } from '../context';
33

44
export interface PlaceholderProps {
5-
hasSearchValue?: boolean;
5+
show: boolean;
66
}
77

88
export default function Placeholder(props: PlaceholderProps) {
99
const { prefixCls, placeholder, displayValues } = useSelectInputContext();
10-
11-
const { searchValue } = useSelectInputContext();
12-
13-
const { hasSearchValue = !!searchValue } = props;
10+
const { show } = props;
1411

1512
if (displayValues.length) {
1613
return null;
@@ -20,7 +17,7 @@ export default function Placeholder(props: PlaceholderProps) {
2017
<div
2118
className={`${prefixCls}-placeholder`}
2219
style={{
23-
visibility: hasSearchValue ? 'hidden' : 'visible',
20+
visibility: show ? 'visible' : 'hidden',
2421
}}
2522
>
2623
{placeholder}

src/SelectInput/Content/SingleContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const SingleContent = React.forwardRef<HTMLInputElement, SharedContentProps>(
7575
{displayValue ? (
7676
<div {...optionProps}>{displayValue.label}</div>
7777
) : (
78-
<Placeholder hasSearchValue={!!mergedSearchValue} />
78+
<Placeholder show={!mergedSearchValue} />
7979
)}
8080
<Input
8181
ref={ref}

tests/Multiple.test.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ describe('Select.Multiple', () => {
3333
dynamicChildrenTest('multiple');
3434
inputFilterTest('multiple');
3535

36+
beforeEach(() => {
37+
jest.useFakeTimers();
38+
});
39+
40+
afterEach(() => {
41+
jest.useRealTimers();
42+
});
43+
3644
it('tokenize input', () => {
3745
const handleChange = jest.fn();
3846
const handleSelect = jest.fn();
@@ -426,9 +434,13 @@ describe('Select.Multiple', () => {
426434
const { container } = render(
427435
<Select mode="multiple" searchValue="light" placeholder="bamboo" />,
428436
);
429-
expect(container.querySelector('.rc-select-placeholder')).toBeTruthy();
437+
expect(container.querySelector('.rc-select-placeholder')).toHaveStyle({
438+
visibility: 'visible',
439+
});
430440
toggleOpen(container);
431-
expect(container.querySelector('.rc-select-placeholder')).toBeFalsy();
441+
expect(container.querySelector('.rc-select-placeholder')).toHaveStyle({
442+
visibility: 'hidden',
443+
});
432444
});
433445

434446
it('clear input when popup closed', () => {
@@ -437,12 +449,13 @@ describe('Select.Multiple', () => {
437449
);
438450
toggleOpen(container);
439451
fireEvent.change(container.querySelector('input'), { target: { value: 'bamboo' } });
440-
expect(container.querySelector('input').value).toEqual('bamboo');
452+
expect(container.querySelector('input')).toHaveValue('bamboo');
441453

442454
// Close and open again
443455
toggleOpen(container);
456+
fireEvent.blur(container.querySelector('input'));
444457
toggleOpen(container);
445-
expect(container.querySelector('input').value).toEqual('');
458+
expect(container.querySelector('input')).toHaveValue('');
446459
});
447460

448461
it('ajax update should keep options', () => {

0 commit comments

Comments
 (0)