Skip to content

Commit cdfd8eb

Browse files
committed
feat: support prefix
1 parent bbe6b41 commit cdfd8eb

File tree

8 files changed

+23
-15
lines changed

8 files changed

+23
-15
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export default () => (
121121
| showAction | actions trigger the dropdown to show | String[]? | - |
122122
| autoFocus | focus select after mount | boolean | - |
123123
| autoClearSearchValue | auto clear search input value when multiple select is selected/deselected | boolean | true |
124+
| prefix | specify the select prefix icon or text | ReactNode | - | |
124125
| suffixIcon | specify the select arrow icon | ReactNode | - |
125126
| clearIcon | specify the clear icon | ReactNode | - |
126127
| removeIcon | specify the remove icon | ReactNode | - |

assets/index.less

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272

7373
.@{select-prefix}-selection-search {
7474
width: 100%;
75+
position: relative;
7576

7677
&-input {
7778
width: 100%;
@@ -101,7 +102,6 @@
101102
// -------------- Multiple ---------------
102103
&-multiple .@{select-prefix}-selector {
103104
display: flex;
104-
flex-wrap: wrap;
105105
padding: 1px;
106106
border: 1px solid #000;
107107

@@ -121,7 +121,6 @@
121121
.@{select-prefix}-selection-overflow {
122122
display: flex;
123123
flex-wrap: wrap;
124-
width: 100%;
125124

126125
&-item {
127126
flex: none;

docs/examples/custom-icon.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class CustomIconComponent extends React.Component {
103103
value={value}
104104
mode="combobox"
105105
backfill
106+
prefix="Foobar"
106107
suffixIcon={({ searchValue }) => {
107108
if (searchValue) {
108109
return '😺';
@@ -193,6 +194,7 @@ class Test extends React.Component {
193194
onChange={this.onChange}
194195
onFocus={() => console.log('focus')}
195196
tokenSeparators={[' ', ',']}
197+
prefix="Foobar"
196198
suffixIcon={getSvg(arrowPath)}
197199
clearIcon={getSvg(clearPath)}
198200
removeIcon={getSvg(clearPath)}

src/BaseSelect/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export interface BaseSelectProps extends BaseSelectPrivateProps, React.AriaAttri
173173

174174
// >>> Icons
175175
allowClear?: boolean | { clearIcon?: RenderNode };
176+
prefix?: RenderNode;
176177
suffixIcon?: RenderNode;
177178
/**
178179
* Clear all icon
@@ -259,6 +260,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
259260

260261
// Icons
261262
allowClear,
263+
prefix,
262264
suffixIcon,
263265
clearIcon,
264266

@@ -795,6 +797,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
795797
inputElement={customizeInputElement}
796798
ref={selectorRef}
797799
id={id}
800+
prefix={prefix}
798801
showSearch={mergedShowSearch}
799802
autoClearSearchValue={autoClearSearchValue}
800803
mode={mode}

src/Selector/SingleSelector.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ const SingleSelector: React.FC<SelectorProps> = (props) => {
104104
attrs={pickAttrs(props, true)}
105105
maxLength={combobox ? maxLength : undefined}
106106
/>
107+
{/* Display placeholder */}
108+
{placeholderNode}
107109
</span>
108110

109111
{/* Display value */}
@@ -119,8 +121,6 @@ const SingleSelector: React.FC<SelectorProps> = (props) => {
119121
{item.label}
120122
</span>
121123
) : null}
122-
{/* Display placeholder */}
123-
{placeholderNode}
124124
</>
125125
);
126126
};

src/Selector/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export interface SelectorProps {
7272
disabled?: boolean;
7373
placeholder?: React.ReactNode;
7474
removeIcon?: RenderNode;
75+
prefix?: RenderNode;
7576

7677
// Tags
7778
maxTagCount?: number | 'responsive';
@@ -110,6 +111,7 @@ const Selector: React.ForwardRefRenderFunction<RefSelectorProps, SelectorProps>
110111
showSearch,
111112
tokenWithEnter,
112113
disabled,
114+
prefix,
113115

114116
autoClearSearchValue,
115117

@@ -269,6 +271,7 @@ const Selector: React.ForwardRefRenderFunction<RefSelectorProps, SelectorProps>
269271
onClick={onClick}
270272
onMouseDown={onMouseDown}
271273
>
274+
{prefix && <div className={`${prefixCls}-prefix`}>{typeof prefix === 'function' ? prefix(props): prefix}</div>}
272275
{selectNode}
273276
</div>
274277
);

tests/__snapshots__/Combobox.test.tsx.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ exports[`Select.Combobox renders controlled correctly 1`] = `
2323
type="search"
2424
value=""
2525
/>
26-
</span>
27-
<span
28-
class="rc-select-selection-placeholder"
29-
>
30-
Search
26+
<span
27+
class="rc-select-selection-placeholder"
28+
>
29+
Search
30+
</span>
3131
</span>
3232
</div>
3333
</div>
@@ -56,11 +56,11 @@ exports[`Select.Combobox renders correctly 1`] = `
5656
type="search"
5757
value=""
5858
/>
59-
</span>
60-
<span
61-
class="rc-select-selection-placeholder"
62-
>
63-
Search
59+
<span
60+
class="rc-select-selection-placeholder"
61+
>
62+
Search
63+
</span>
6464
</span>
6565
</div>
6666
</div>

tests/__snapshots__/ssr.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Select.SSR should work 1`] = `"<div class="rc-select rc-select-single"><div class="rc-select-selector"><span class="rc-select-selection-search"><input type="search" autoComplete="off" class="rc-select-selection-search-input" role="combobox" aria-expanded="false" aria-haspopup="listbox" aria-owns="undefined_list" aria-autocomplete="list" aria-controls="undefined_list" readonly="" unselectable="on" style="opacity:0" value=""/></span><span class="rc-select-selection-placeholder"></span></div></div>"`;
3+
exports[`Select.SSR should work 1`] = `"<div class="rc-select rc-select-single"><div class="rc-select-selector"><span class="rc-select-selection-search"><input type="search" autoComplete="off" class="rc-select-selection-search-input" role="combobox" aria-expanded="false" aria-haspopup="listbox" aria-owns="undefined_list" aria-autocomplete="list" aria-controls="undefined_list" readonly="" unselectable="on" style="opacity:0" value=""/><span class="rc-select-selection-placeholder"></span></span></div></div>"`;

0 commit comments

Comments
 (0)