diff --git a/src/_common b/src/_common index f3226c488..9cdb227bd 160000 --- a/src/_common +++ b/src/_common @@ -1 +1 @@ -Subproject commit f3226c48864cc056f985ad3be3ab8e0e8001f79e +Subproject commit 9cdb227bdbb8b555511652b2b08bc91ae8b310c8 diff --git a/src/select/__tests__/__snapshots__/select.test.tsx.snap b/src/select/__tests__/__snapshots__/select.test.tsx.snap index bffedf988..81e617f79 100644 --- a/src/select/__tests__/__snapshots__/select.test.tsx.snap +++ b/src/select/__tests__/__snapshots__/select.test.tsx.snap @@ -808,6 +808,89 @@ exports[`options.jsx 1`] = ` `; +exports[`panel.jsx 1`] = ` + + + + + + + + 请选择云解决方案 + + + + + + + + + + + + + 请选择云产品 + + + + + + + + + +`; + exports[`popup-props.jsx 1`] = ` { + const filteredValue = OPTIONS.filter((item) => item.label.indexOf(v) !== -1); + setTopOptions(filteredValue); + }; + + const handleClickConfirm = () => { + const id = Math.round(Math.random() * 100); + const newBottomOptions = bottomOptions.concat({ label: inputVal, value: id }); + setBottomOptions(newBottomOptions); + changeInputVal(''); + toggleEditOrCreate('edit'); + }; + return ( + + + + + } + > + + {editOrCreate === 'edit' ? ( + toggleEditOrCreate('create')}> + 新增选项 + + ) : ( + + changeInputVal(v)}> + + 确认 + + toggleEditOrCreate('edit')} + > + 取消 + + + )} + + } + > + + ); +} diff --git a/src/select/base/PopupContent.tsx b/src/select/base/PopupContent.tsx index 900a8d09d..1c2850d00 100644 --- a/src/select/base/PopupContent.tsx +++ b/src/select/base/PopupContent.tsx @@ -10,7 +10,18 @@ type OptionsType = TdOptionProps[]; interface SelectPopupProps extends Pick< TdSelectProps, - 'value' | 'size' | 'multiple' | 'empty' | 'options' | 'max' | 'loadingText' | 'loading' | 'valueType' | 'keys' + | 'value' + | 'size' + | 'multiple' + | 'empty' + | 'options' + | 'max' + | 'loadingText' + | 'loading' + | 'valueType' + | 'keys' + | 'panelTopContent' + | 'panelBottomContent' > { onChange?: (value: SelectValue, context?: { label?: string | number; restData?: Record }) => void; /** @@ -40,6 +51,8 @@ const PopupContent = (props: SelectPopupProps) => { valueType, children, keys, + panelTopContent, + panelBottomContent, } = props; // 国际化文本初始化 @@ -115,14 +128,15 @@ const PopupContent = (props: SelectPopupProps) => { const isEmpty = (Array.isArray(childrenWithProps) && !childrenWithProps.length) || (options && options.length === 0); - if (isEmpty) { - return {empty ? empty : {emptyText}}; - } - - if (loading) { - return {loadingText}; - } - return {renderOptions()}; + return ( + + {panelTopContent} + {isEmpty && {empty ? empty : {emptyText}}} + {!isEmpty && loading && {loadingText}} + {!isEmpty && !loading && renderOptions()} + {panelBottomContent} + + ); }; export default PopupContent; diff --git a/src/select/base/Select.tsx b/src/select/base/Select.tsx index 6e5cbc666..016385c6f 100644 --- a/src/select/base/Select.tsx +++ b/src/select/base/Select.tsx @@ -81,6 +81,10 @@ const Select = forwardRefWithStatics( valueDisplay, onEnter, onVisibleChange, + showArrow = true, + inputProps, + panelBottomContent, + panelTopContent, } = useDefaultValue(props); const { classPrefix } = useConfig(); @@ -324,6 +328,7 @@ const Select = forwardRefWithStatics( onFocus={(_, context) => onFocus?.({ value, e: context?.e })} onBlur={(_, context) => onBlur?.({ value, e: context?.e })} onEnter={(_, context) => onEnter?.({ inputValue: inputVal, value, e: context?.e })} + {...inputProps} /> ); @@ -365,7 +370,9 @@ const Select = forwardRefWithStatics( /> ); } - return ; + return ( + showArrow && + ); }; const popupContentProps = { @@ -383,6 +390,8 @@ const Select = forwardRefWithStatics( loading, valueType, keys, + panelBottomContent, + panelTopContent, }; const renderContent = () => {children}; diff --git a/src/select/select.md b/src/select/select.md index 07bffd35c..8bfac3ead 100644 --- a/src/select/select.md +++ b/src/select/select.md @@ -5,6 +5,8 @@ 名称 | 类型 | 默认值 | 说明 | 必传 -- | -- | -- | -- | -- +className | String | - | 类名 | N +style | Object | - | 样式,TS 类型:`React.CSSProperties` | N bordered | Boolean | true | 是否有边框 | N clearable | Boolean | false | 是否可以清空选项 | N collapsedItems | TElement | - | 多选情况下,用于设置折叠项内容,默认为 `+N`。如果需要悬浮就显示其他内容,可以使用 collapsedItems 自定义。TS 类型:`TNode<{ value: T[]; collapsedSelectedItems: T[]; count: number }>`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N @@ -13,6 +15,7 @@ disabled | Boolean | false | 是否禁用组件 | N empty | TNode | '' | 当下拉列表为空时显示的内容。TS 类型:`string | TNode`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N filter | Function | - | 自定义过滤方法,用于对现有数据进行搜索过滤,判断是否过滤某一项数据。TS 类型:`(filterWords: string, option: T) => boolean | Promise` | N filterable | Boolean | false | 是否可搜索 | N +inputProps | Object | - | 透传 Input 组件全部属性。TS 类型:`InputProps`。[详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/select/type.ts) | N keys | Object | - | 用来定义 value / label 在 `options` 中对应的字段别名。TS 类型:`SelectKeysType`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts)。[详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/select/type.ts) | N loading | Boolean | false | 是否为加载状态 | N loadingText | TNode | '' | 远程加载时显示的文字,支持自定义。如加上超链接。TS 类型:`string | TNode`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N @@ -46,6 +49,8 @@ onVisibleChange | Function | | TS 类型:`(visible: boolean) => void`下 名称 | 类型 | 默认值 | 说明 | 必传 -- | -- | -- | -- | -- +className | String | - | 类名 | N +style | Object | - | 样式,TS 类型:`React.CSSProperties` | N children | TNode | - | 用于定义复杂的选项内容,同 content。TS 类型:`string | TNode`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N content | TNode | - | 用于定义复杂的选项内容。TS 类型:`string | TNode`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N disabled | Boolean | false | 是否禁用该选项 | N @@ -56,5 +61,7 @@ value | String / Number | - | 选项值 | N 名称 | 类型 | 默认值 | 说明 | 必传 -- | -- | -- | -- | -- +className | String | - | 类名 | N +style | Object | - | 样式,TS 类型:`React.CSSProperties` | N divider | Boolean | true | 是否显示分隔线 | N label | String | - | 分组别名 | N diff --git a/src/select/type.ts b/src/select/type.ts index 9a2b73649..867d7e66b 100644 --- a/src/select/type.ts +++ b/src/select/type.ts @@ -2,9 +2,9 @@ /** * 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC - * updated at 2021-12-27 17:08:43 * */ +import { InputProps } from '../input'; import { PopupProps } from '../popup'; import { TNode, TElement, SizeEnum } from '../common'; import { MouseEvent, KeyboardEvent, FocusEvent } from 'react'; @@ -48,6 +48,10 @@ export interface TdSelectProps { * @default false */ filterable?: boolean; + /** + * 透传 Input 组件全部属性 + */ + inputProps?: InputProps; /** * 用来定义 value / label 在 `options` 中对应的字段别名 */ @@ -82,9 +86,16 @@ export interface TdSelectProps { * @default [] */ options?: Array; + /** + * 面板内的底部内容 + */ + panelBottomContent?: TNode; + /** + * 面板内的顶部内容 + */ + panelTopContent?: TNode; /** * 占位符 - * @default '' */ placeholder?: string; /** @@ -100,6 +111,11 @@ export interface TdSelectProps { * @default false */ reserveKeyword?: boolean; + /** + * 是否显示右侧箭头,默认显示 + * @default true + */ + showArrow?: boolean; /** * 组件尺寸 * @default medium diff --git a/test/ssr/__snapshots__/ssr.test.js.snap b/test/ssr/__snapshots__/ssr.test.js.snap index 05a1add8a..f2391f4b0 100644 --- a/test/ssr/__snapshots__/ssr.test.js.snap +++ b/test/ssr/__snapshots__/ssr.test.js.snap @@ -506,6 +506,8 @@ exports[`ssr snapshot test renders ./src/select/_example/noborder.jsx correctly exports[`ssr snapshot test renders ./src/select/_example/options.jsx correctly 1`] = `""`; +exports[`ssr snapshot test renders ./src/select/_example/panel.jsx correctly 1`] = `"请选择云解决方案请选择云产品"`; + exports[`ssr snapshot test renders ./src/select/_example/popup-props.jsx correctly 1`] = `"-请选择-"`; exports[`ssr snapshot test renders ./src/select/_example/prefix.jsx correctly 1`] = `"-请选择-"`;
{emptyText}