From a01450debbf2605fdeadc75d0cad2285472b4d92 Mon Sep 17 00:00:00 2001 From: HeskeyBaozi Date: Sat, 15 Sep 2018 00:00:16 +0800 Subject: [PATCH] add suffix interface to select --- .../__tests__/__snapshots__/demo.test.js.snap | 103 ++++++++++++++++++ components/select/demo/suffix.md | 41 +++++++ components/select/index.en-US.md | 1 + components/select/index.tsx | 15 ++- components/select/index.zh-CN.md | 1 + 5 files changed, 157 insertions(+), 4 deletions(-) create mode 100644 components/select/demo/suffix.md diff --git a/components/select/__tests__/__snapshots__/demo.test.js.snap b/components/select/__tests__/__snapshots__/demo.test.js.snap index a227072666..a88a498a24 100644 --- a/components/select/__tests__/__snapshots__/demo.test.js.snap +++ b/components/select/__tests__/__snapshots__/demo.test.js.snap @@ -974,6 +974,109 @@ exports[`renders ./components/select/demo/size.md correctly 1`] = ` `; +exports[`renders ./components/select/demo/suffix.md correctly 1`] = ` +
+
+ +
+
+ +
+
+`; + exports[`renders ./components/select/demo/tags.md correctly 1`] = `
; +const mehIcon = ; +const Option = Select.Option; + +function handleChange(value) { + console.log(`selected ${value}`); +} + +ReactDOM.render( +
+ + +
, + mountNode); +```` diff --git a/components/select/index.en-US.md b/components/select/index.en-US.md index 01d78a6f90..2f701f2296 100644 --- a/components/select/index.en-US.md +++ b/components/select/index.en-US.md @@ -45,6 +45,7 @@ Select component to select value from options. | showArrow | Whether to show the drop-down arrow | boolean | true | | showSearch | Whether show search input in single mode. | boolean | false | | size | Size of Select input. `default` `large` `small` | string | default | +| suffix | The custom suffix icon | ReactNode | - | | tokenSeparators | Separator used to tokenize on tag/multiple mode | string\[] | | | value | Current selected option. | string\|number\|string\[]\|number\[] | - | | onBlur | Called when blur | function | - | diff --git a/components/select/index.tsx b/components/select/index.tsx index 51422915e5..2d7253cc9c 100755 --- a/components/select/index.tsx +++ b/components/select/index.tsx @@ -4,6 +4,7 @@ import RcSelect, { Option, OptGroup } from 'rc-select'; import classNames from 'classnames'; import LocaleReceiver from '../locale-provider/LocaleReceiver'; import defaultLocale from '../locale-provider/default'; +import omit from 'omit.js'; import warning from 'warning'; import Icon from '../icon'; @@ -63,6 +64,7 @@ export interface SelectProps extends AbstractSelectProps { tokenSeparators?: string[]; getInputElement?: () => React.ReactElement; autoFocus?: boolean; + suffix?: React.ReactNode; } export interface OptionProps { @@ -155,8 +157,11 @@ export default class Select extends React.Component { className = '', size, mode, + suffix, ...restProps } = this.props; + const rest = omit(restProps, ['inputIcon', 'removeIcon', 'clearIcon']); + const cls = classNames({ [`${prefixCls}-lg`]: size === 'large', [`${prefixCls}-sm`]: size === 'small', @@ -174,9 +179,11 @@ export default class Select extends React.Component { combobox: this.isCombobox(), }; - const inputIcon = ( - - ); + const inputIcon = suffix && ( + React.isValidElement<{ className?: string }>(suffix) + ? React.cloneElement(suffix) : suffix) || ( + + ); const removeIcon = ( @@ -196,7 +203,7 @@ export default class Select extends React.Component { removeIcon={removeIcon} clearIcon={clearIcon} menuItemSelectedIcon={menuItemSelectedIcon} - {...restProps} + {...rest} {...modeConfig} prefixCls={prefixCls} className={cls} diff --git a/components/select/index.zh-CN.md b/components/select/index.zh-CN.md index 4529c7df05..05e53e7a72 100644 --- a/components/select/index.zh-CN.md +++ b/components/select/index.zh-CN.md @@ -46,6 +46,7 @@ title: Select | showArrow | 是否显示下拉小箭头 | boolean | true | | showSearch | 使单选模式可搜索 | boolean | false | | size | 选择框大小,可选 `large` `small` | string | default | +| suffix | 自定义的选择框后缀图标 | ReactNode | - | | tokenSeparators | 在 tags 和 multiple 模式下自动分词的分隔符 | string\[] | | | value | 指定当前选中的条目 | string\|string\[]\|number\|number\[] | - | | onBlur | 失去焦点的时回调 | function | - |