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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export default () => (
| loading | show loading icon in arrow | Boolean | false |
| virtual | Disable virtual scroll | Boolean | true |
| direction | direction of dropdown | 'ltr' \| 'rtl' | 'ltr' |
| suffix | suffix of select input | ReactNode | - |

### Methods

Expand Down
12 changes: 12 additions & 0 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,18 @@
color: #999;
}
}

&-has-suffix {
.@{select-prefix}-arrow {
right: 16px;
}
}

&-suffix {
position: absolute;
right: 4px;
top: 0;
}
}

.@{select-prefix}-selection__choice-zoom {
Expand Down
2 changes: 2 additions & 0 deletions docs/demo/suffix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## suffix
<code src="../examples/suffix.tsx">
15 changes: 15 additions & 0 deletions docs/examples/suffix.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React, { FC } from 'react';
import Select from 'rc-select';

const SuffixDemo: FC = () => {
return (
<Select suffix=":)">
{Array(10).fill(1).map((item, index) => (
// eslint-disable-next-line react/no-array-index-key
<Select.Option key={`pick me ${index}`} value={index}>{`pick me ${index}`}</Select.Option>
))}
</Select>
)
}

export default SuffixDemo;
6 changes: 6 additions & 0 deletions src/BaseSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import useDelayReset from './hooks/useDelayReset';
import TransBtn from './TransBtn';
import useLock from './hooks/useLock';
import { BaseSelectContext } from './hooks/useBaseProps';
import type { ReactNode } from 'react';

const DEFAULT_OMIT_PROPS = [
'value',
Expand Down Expand Up @@ -169,6 +170,7 @@ export interface BaseSelectProps extends BaseSelectPrivateProps, React.AriaAttri
clearIcon?: RenderNode;
/** Selector remove icon */
removeIcon?: RenderNode;
suffix?: ReactNode;

// >>> Dropdown
animation?: string;
Expand Down Expand Up @@ -273,6 +275,8 @@ const BaseSelect = React.forwardRef((props: BaseSelectProps, ref: React.Ref<Base
onKeyDown,
onMouseDown,

suffix,

// Rest Props
...restProps
} = props;
Expand Down Expand Up @@ -718,6 +722,7 @@ const BaseSelect = React.forwardRef((props: BaseSelectProps, ref: React.Ref<Base
[`${prefixCls}-open`]: mergedOpen,
[`${prefixCls}-customize-input`]: customizeInputElement,
[`${prefixCls}-show-search`]: mergedShowSearch,
[`${prefixCls}-has-suffix`]: suffix,
});

// >>> Selector
Expand Down Expand Up @@ -815,6 +820,7 @@ const BaseSelect = React.forwardRef((props: BaseSelectProps, ref: React.Ref<Base

{arrowNode}
{clearNode}
{suffix && <span className={`${prefixCls}-suffix`}>{suffix}</span>}
</div>
);
}
Expand Down
9 changes: 7 additions & 2 deletions src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@
import * as React from 'react';
import warning from 'rc-util/lib/warning';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import type {
BaseSelectProps,
BaseSelectPropsWithoutPrivate,
BaseSelectRef,
DisplayValueType,
RenderNode,
} from './BaseSelect';
import BaseSelect, { isMultiple } from './BaseSelect';
import type { DisplayValueType, RenderNode } from './BaseSelect';
import OptionList from './OptionList';
import Option from './Option';
import OptGroup from './OptGroup';
import type { BaseSelectRef, BaseSelectPropsWithoutPrivate, BaseSelectProps } from './BaseSelect';
import useOptions from './hooks/useOptions';
import SelectContext from './SelectContext';
import useId from './hooks/useId';
Expand Down
3 changes: 3 additions & 0 deletions src/Selector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

import * as React from 'react';
import type { ReactNode } from 'react';
import { useRef } from 'react';
import KeyCode from 'rc-util/lib/KeyCode';
import type { ScrollTo } from 'rc-virtual-list/lib/List';
Expand Down Expand Up @@ -93,6 +94,8 @@ export interface SelectorProps {
* This may be removed after React provides replacement of `findDOMNode`
*/
domRef: React.Ref<HTMLDivElement>;

suffix?: ReactNode;
}

const Selector: React.RefForwardingComponent<RefSelectorProps, SelectorProps> = (props, ref) => {
Expand Down
8 changes: 8 additions & 0 deletions tests/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1789,4 +1789,12 @@ describe('Select.Basic', () => {
.visibility,
).toBe('hidden');
});

it('should support suffix', () => {
const wrapper = mount(<Select suffix=":)" />);

expect(wrapper.find('.rc-select-has-suffix')).toBeTruthy();
expect(wrapper.find('.rc-select-suffix')).toBeTruthy();
expect(wrapper.find('.rc-select-suffix').text()).toEqual(':)');
});
});