Skip to content

Commit 5213c6d

Browse files
authored
fix: Select width became 0px when search after select something (#935)
* chore: publish on branch 14.1.x * 14.1.17-0 * fix: Select width 0px when search again
1 parent f367024 commit 5213c6d

File tree

5 files changed

+22
-62
lines changed

5 files changed

+22
-62
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-select",
3-
"version": "14.1.16",
3+
"version": "14.1.17-0",
44
"description": "React Select",
55
"engines": {
66
"node": ">=8.x"
@@ -33,7 +33,7 @@
3333
"start": "dumi dev",
3434
"build": "dumi build",
3535
"compile": "father build",
36-
"prepublishOnly": "npm run compile && np --yolo --no-publish",
36+
"prepublishOnly": "npm run compile && np --yolo --no-publish --branch 14.1.x",
3737
"lint": "eslint src/ docs/examples/ --ext .tsx,.ts,.jsx,.js",
3838
"test": "rc-test",
3939
"tsc": "tsc --noEmit",

src/Selector/SingleSelector.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,17 @@ const SingleSelector: React.FC<SelectorProps> = (props) => {
6161
// Get title
6262
const title = getTitle(item);
6363

64-
// 当 Select 已经选中了选型时,placeholder 隐藏,但留在原地占位,内容是选中项文本,这样宽度不会缩减为 0px
65-
// https://github.com/ant-design/ant-design/issues/27688
66-
// https://github.com/ant-design/ant-design/issues/41530
6764
const renderPlaceholder = () => {
68-
const hiddenStyle = (hasTextInput || item)
69-
? { visibility: 'hidden' } as React.CSSProperties : undefined;
65+
if (item) {
66+
return null;
67+
}
68+
const hiddenStyle = hasTextInput ? { visibility: 'hidden' } as React.CSSProperties : undefined;
7069
return (
7170
<span
7271
className={`${prefixCls}-selection-placeholder`}
7372
style={hiddenStyle}
7473
>
75-
{item ? item.label : placeholder}
74+
{placeholder}
7675
</span>
7776
);
7877
};
@@ -108,11 +107,18 @@ const SingleSelector: React.FC<SelectorProps> = (props) => {
108107
</span>
109108

110109
{/* Display value */}
111-
{!combobox && item && !hasTextInput && (
112-
<span className={`${prefixCls}-selection-item`} title={title}>
110+
{(!combobox && item) ? (
111+
<span
112+
className={`${prefixCls}-selection-item`}
113+
title={title}
114+
// 当 Select 已经选中选项时,还需 selection 隐藏但留在原地占位
115+
// https://github.com/ant-design/ant-design/issues/27688
116+
// https://github.com/ant-design/ant-design/issues/41530
117+
style={hasTextInput ? { visibility: 'hidden' } as React.CSSProperties : undefined}
118+
>
113119
{item.label}
114120
</span>
115-
)}
121+
) : null}
116122

117123
{/* Display placeholder */}
118124
{renderPlaceholder()}

tests/Combobox.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('Select.Combobox', () => {
7474
expect(wrapper.find('input').props().value).toBe('');
7575
expect(wrapper.find('.rc-select-selection-placeholder').text()).toEqual('placeholder');
7676
wrapper.find('input').simulate('change', { target: { value: '1' } });
77-
expect(wrapper.find('.rc-select-selection-placeholder').length).toBe(1);
77+
expect(wrapper.find('.rc-select-selection-placeholder').length).toBe(0);
7878
expect(wrapper.find('input').props().value).toBe('1');
7979
});
8080

tests/__snapshots__/Select.test.tsx.snap

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,6 @@ exports[`Select.Basic no search 1`] = `
226226
>
227227
1
228228
</span>
229-
<span
230-
class="rc-select-selection-placeholder"
231-
style="visibility:hidden"
232-
>
233-
1
234-
</span>
235229
</div>
236230
<span
237231
aria-hidden="true"
@@ -279,12 +273,6 @@ exports[`Select.Basic render renders aria-attributes correctly 1`] = `
279273
>
280274
2
281275
</span>
282-
<span
283-
class="antd-selection-placeholder"
284-
style="visibility:hidden"
285-
>
286-
2
287-
</span>
288276
</div>
289277
<span
290278
aria-hidden="true"
@@ -340,12 +328,6 @@ exports[`Select.Basic render renders correctly 1`] = `
340328
>
341329
2
342330
</span>
343-
<span
344-
class="antd-selection-placeholder"
345-
style="visibility:hidden"
346-
>
347-
2
348-
</span>
349331
</div>
350332
<span
351333
aria-hidden="true"
@@ -403,12 +385,6 @@ exports[`Select.Basic render renders data-attributes correctly 1`] = `
403385
>
404386
2
405387
</span>
406-
<span
407-
class="antd-selection-placeholder"
408-
style="visibility:hidden"
409-
>
410-
2
411-
</span>
412388
</div>
413389
<span
414390
aria-hidden="true"
@@ -466,12 +442,6 @@ exports[`Select.Basic render renders disabled select correctly 1`] = `
466442
>
467443
2
468444
</span>
469-
<span
470-
class="antd-selection-placeholder"
471-
style="visibility:hidden"
472-
>
473-
2
474-
</span>
475445
</div>
476446
<span
477447
aria-hidden="true"
@@ -516,12 +486,6 @@ exports[`Select.Basic render renders dropdown correctly 1`] = `
516486
>
517487
2
518488
</span>
519-
<span
520-
class="antd-selection-placeholder"
521-
style="visibility:hidden"
522-
>
523-
2
524-
</span>
525489
</div>
526490
<div>
527491
<div
@@ -708,12 +672,6 @@ exports[`Select.Basic render renders role prop correctly 1`] = `
708672
>
709673
2
710674
</span>
711-
<span
712-
class="antd-selection-placeholder"
713-
style="visibility:hidden"
714-
>
715-
2
716-
</span>
717675
</div>
718676
<span
719677
aria-hidden="true"
@@ -773,12 +731,6 @@ exports[`Select.Basic should contain falsy children 1`] = `
773731
>
774732
1
775733
</span>
776-
<span
777-
class="rc-select-selection-placeholder"
778-
style="visibility:hidden"
779-
>
780-
1
781-
</span>
782734
</div>
783735
<div>
784736
<div

tests/placeholder.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ describe('Select placeholder', () => {
2626
const wrapper = mount(
2727
<Select value={null} placeholder="bamboo" options={[{ value: null, label: 'light' }]} />,
2828
);
29-
expect(wrapper.find('.rc-select-selection-placeholder').length).toBe(1);
30-
expect(wrapper.find('.rc-select-selection-placeholder').text()).toBe('light');
29+
expect(wrapper.find('.rc-select-selection-placeholder').length).toBe(0);
30+
expect(wrapper.find('.rc-select-selection-item').text()).toBe('light');
31+
toggleOpen(wrapper);
32+
expect(wrapper.find('.rc-select-selection-item').text()).toBe('light');
3133
});
3234

3335
it('should hide placeholder if force closed and showSearch with searchValue', () => {

0 commit comments

Comments
 (0)