Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Select deprecated showArrow prop #43520

Merged
merged 8 commits into from Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/auto-complete/index.tsx
Expand Up @@ -38,7 +38,7 @@ export interface AutoCompleteProps<
OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType,
> extends Omit<
InternalSelectProps<ValueType, OptionType>,
'inputIcon' | 'loading' | 'mode' | 'optionLabelProp' | 'labelInValue'
'loading' | 'mode' | 'optionLabelProp' | 'labelInValue'
> {
dataSource?: DataSourceItemType[];
status?: InputStatus;
Expand Down Expand Up @@ -147,7 +147,7 @@ const AutoComplete: React.ForwardRefRenderFunction<RefSelectProps, AutoCompleteP
return (
<Select
ref={ref}
showArrow={false}
suffixIcon={null}
{...omit(props, ['dataSource', 'dropdownClassName'])}
prefixCls={prefixCls}
popupClassName={popupClassName || dropdownClassName}
Expand Down
8 changes: 3 additions & 5 deletions components/cascader/index.tsx
Expand Up @@ -156,7 +156,6 @@ const Cascader = React.forwardRef((props: CascaderProps<any>, ref: React.Ref<Cas
direction,
getPopupContainer,
status: customStatus,
showArrow,
builtinPlacements,
style,
...rest
Expand Down Expand Up @@ -265,12 +264,12 @@ const Cascader = React.forwardRef((props: CascaderProps<any>, ref: React.Ref<Cas
);

// ===================== Icons =====================
const mergedShowArrow = useShowArrow(showArrow);
const showSuffixIcon = useShowArrow(props.suffixIcon);
const { suffixIcon, removeIcon, clearIcon } = getIcons({
...props,
hasFeedback,
feedbackIcon,
showArrow: mergedShowArrow,
showSuffixIcon,
multiple,
prefixCls,
});
Expand Down Expand Up @@ -315,7 +314,7 @@ const Cascader = React.forwardRef((props: CascaderProps<any>, ref: React.Ref<Cas
allowClear={allowClear}
showSearch={mergedShowSearch}
expandIcon={mergedExpandIcon}
inputIcon={suffixIcon}
suffixIcon={suffixIcon}
removeIcon={removeIcon}
clearIcon={clearIcon}
loadingIcon={loadingIcon}
Expand All @@ -330,7 +329,6 @@ const Cascader = React.forwardRef((props: CascaderProps<any>, ref: React.Ref<Cas
)}
getPopupContainer={getPopupContainer || getContextPopupContainer}
ref={ref}
showArrow={hasFeedback || mergedShowArrow}
/>
);

Expand Down
1 change: 0 additions & 1 deletion components/select/demo/custom-tag-render.tsx
Expand Up @@ -26,7 +26,6 @@ const tagRender = (props: CustomTagProps) => {
const App: React.FC = () => (
<Select
mode="multiple"
showArrow
tagRender={tagRender}
defaultValue={['gold', 'cyan']}
style={{ width: '100%' }}
Expand Down
2 changes: 1 addition & 1 deletion components/select/demo/search-box.tsx
Expand Up @@ -58,7 +58,7 @@ const SearchInput: React.FC<{ placeholder: string; style: React.CSSProperties }>
placeholder={props.placeholder}
style={props.style}
defaultActiveFirstOption={false}
showArrow={false}
suffixIcon={null}
filterOption={false}
onSearch={handleSearch}
onChange={handleChange}
Expand Down
3 changes: 1 addition & 2 deletions components/select/index.en-US.md
Expand Up @@ -85,11 +85,10 @@ Select component to select value from options.
| placement | The position where the selection box pops up | `bottomLeft` `bottomRight` `topLeft` `topRight` | bottomLeft | |
| removeIcon | The custom remove icon | ReactNode | - | |
| searchValue | The current input "search" text | string | - | |
| showArrow | Whether to show the drop-down arrow | boolean | `true` | |
| showSearch | Whether select is searchable | boolean | single: false, multiple: true | |
| size | Size of Select input | `large` \| `middle` \| `small` | `middle` | |
| status | Set validation status | 'error' \| 'warning' | - | 4.19.0 |
| suffixIcon | The custom suffix icon. Customize icon will not response click open to avoid icon designed to do other interactive. You can use `pointer-events: none` style to bypass | ReactNode | - | |
| suffixIcon | The custom suffix icon. Customize icon will not response click open to avoid icon designed to do other interactive. You can use `pointer-events: none` style to bypass | ReactNode | `<DownOutlined />` | |
| tagRender | Customize tag render, only applies when `mode` is set to `multiple` or `tags` | (props) => ReactNode | - | |
| tokenSeparators | Separator used to tokenize, only applies when `mode="tags"` | string\[] | - | |
| value | Current selected option (considered as a immutable array) | string \| string\[] \| <br />number \| number\[] \| <br />LabeledValue \| LabeledValue\[] | - | |
Expand Down
14 changes: 9 additions & 5 deletions components/select/index.tsx
Expand Up @@ -45,14 +45,19 @@ export interface InternalSelectProps<
disabled?: boolean;
mode?: 'multiple' | 'tags' | 'SECRET_COMBOBOX_MODE_DO_NOT_USE' | 'combobox';
bordered?: boolean;
/**
* @deprecated `showArrow` is deprecated which will be removed in next major version. It will be a
* default behavior, you can hide it by setting `suffixIcon` to null.
*/
showArrow?: boolean;
}

export interface SelectProps<
ValueType = any,
OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType,
> extends Omit<
InternalSelectProps<ValueType, OptionType>,
'inputIcon' | 'mode' | 'getInputElement' | 'getRawInputElement' | 'backfill' | 'placement'
'mode' | 'getInputElement' | 'getRawInputElement' | 'backfill' | 'placement'
> {
placement?: SelectCommonPlacement;
mode?: 'multiple' | 'tags';
Expand Down Expand Up @@ -131,7 +136,7 @@ const InternalSelect = <
}, [props.mode]);

const isMultiple = mode === 'multiple' || mode === 'tags';
const mergedShowArrow = useShowArrow(showArrow);
const showSuffixIcon = useShowArrow(props.suffixIcon);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要兼容 showArrow,留个 test case 保证废弃的 api 也有效


const mergedPopupMatchSelectWidth =
popupMatchSelectWidth ?? dropdownMatchSelectWidth ?? contextPopupMatchSelectWidth;
Expand Down Expand Up @@ -161,7 +166,7 @@ const InternalSelect = <
multiple: isMultiple,
hasFeedback,
feedbackIcon,
showArrow: mergedShowArrow,
showSuffixIcon,
prefixCls,
});

Expand Down Expand Up @@ -244,15 +249,14 @@ const InternalSelect = <
prefixCls={prefixCls}
placement={memoPlacement}
direction={direction}
inputIcon={suffixIcon}
suffixIcon={suffixIcon}
menuItemSelectedIcon={itemIcon}
removeIcon={removeIcon}
clearIcon={clearIcon}
notFoundContent={mergedNotFound}
className={mergedClassName}
getPopupContainer={getPopupContainer || getContextPopupContainer}
dropdownClassName={rcSelectRtlDropdownClassName}
showArrow={hasFeedback || mergedShowArrow}
disabled={mergedDisabled}
/>,
);
Expand Down
3 changes: 1 addition & 2 deletions components/select/index.zh-CN.md
Expand Up @@ -86,11 +86,10 @@ demo:
| placement | 选择框弹出的位置 | `bottomLeft` `bottomRight` `topLeft` `topRight` | bottomLeft | |
| removeIcon | 自定义的多选框清除图标 | ReactNode | - | |
| searchValue | 控制搜索文本 | string | - | |
| showArrow | 是否显示下拉小箭头 | boolean | `true` | |
| showSearch | 配置是否可搜索 | boolean | 单选为 false,多选为 true | |
| size | 选择框大小 | `large` \| `middle` \| `small` | `middle` | |
| status | 设置校验状态 | 'error' \| 'warning' | - | 4.19.0 |
| suffixIcon | 自定义的选择框后缀图标。以防止图标被用于其他交互,替换的图标默认不会响应展开、收缩事件,可以通过添加 `pointer-events: none` 样式透传。 | ReactNode | - | |
| suffixIcon | 自定义的选择框后缀图标。以防止图标被用于其他交互,替换的图标默认不会响应展开、收缩事件,可以通过添加 `pointer-events: none` 样式透传。 | ReactNode | `<DownOutlined />` | |
| tagRender | 自定义 tag 内容 render,仅在 `mode` 为 `multiple` 或 `tags` 时生效 | (props) => ReactNode | - | |
| tokenSeparators | 自动分词的分隔符,仅在 `mode="tags"` 时生效 | string\[] | - | |
| value | 指定当前选中的条目,多选时为一个数组。(value 数组引用未变化时,Select 不会更新) | string \| string\[] \| <br />number \| number\[] \| <br />LabeledValue \| LabeledValue\[] | - | |
Expand Down
8 changes: 5 additions & 3 deletions components/select/useShowArrow.ts
@@ -1,9 +1,11 @@
import type { ReactNode } from 'react';

/**
* Since Select, TreeSelect, Cascader is same Select like component.
* We just use same hook to handle this logic.
*
* If `showArrow` not configured, always show it.
* If `suffixIcon` is not equal to `null`, always show it.
*/
export default function useShowArrow(showArrow?: boolean) {
return showArrow ?? true;
export default function useShowArrow(suffixIcon?: ReactNode) {
return suffixIcon !== null;
}
21 changes: 13 additions & 8 deletions components/select/utils/iconUtil.tsx
Expand Up @@ -18,7 +18,7 @@ export default function getIcons({
multiple,
hasFeedback,
prefixCls,
showArrow,
showSuffixIcon,
feedbackIcon,
}: {
suffixIcon?: React.ReactNode;
Expand All @@ -30,18 +30,23 @@ export default function getIcons({
hasFeedback?: boolean;
feedbackIcon?: ReactNode;
prefixCls: string;
showArrow?: boolean;
showSuffixIcon?: boolean;
}) {
// Clear Icon
const mergedClearIcon = clearIcon ?? <CloseCircleFilled />;

// Validation Feedback Icon
const getSuffixIconNode = (arrowIcon?: ReactNode) => (
<>
{showArrow !== false && arrowIcon}
{hasFeedback && feedbackIcon}
</>
);
const getSuffixIconNode = (arrowIcon?: ReactNode) => {
if (suffixIcon === null && !hasFeedback) {
return null;
}
return (
<>
{showSuffixIcon !== false && arrowIcon}
{hasFeedback && feedbackIcon}
</>
);
};

// Arrow item icon
let mergedSuffixIcon = null;
Expand Down
3 changes: 1 addition & 2 deletions components/tree-select/index.en-US.md
Expand Up @@ -57,12 +57,11 @@ Tree selection control.
| placeholder | Placeholder of the select input | string | - | |
| placement | The position where the selection box pops up | `bottomLeft` `bottomRight` `topLeft` `topRight` | bottomLeft | |
| searchValue | Work with `onSearch` to make search value controlled | string | - | |
| showArrow | Whether to show the `suffixIcon` | boolean | `true` | |
| showCheckedStrategy | The way show selected item in box when `treeCheckable` set. **Default:** just show child nodes. **`TreeSelect.SHOW_ALL`:** show all checked treeNodes (include parent treeNode). **`TreeSelect.SHOW_PARENT`:** show checked treeNodes (just show parent treeNode) | `TreeSelect.SHOW_ALL` \| `TreeSelect.SHOW_PARENT` \| `TreeSelect.SHOW_CHILD` | `TreeSelect.SHOW_CHILD` | |
| showSearch | Support search or not | boolean | single: false \| multiple: true | |
| size | To set the size of the select input | `large` \| `middle` \| `small` | - | |
| status | Set validation status | 'error' \| 'warning' | - | 4.19.0 |
| suffixIcon | The custom suffix icon,you must set `showArrow` to `true` manually in multiple selection mode | ReactNode | - | |
| suffixIcon | The custom suffix icon | ReactNode | `<DownOutlined />` | |
| switcherIcon | Customize collapse/expand icon of tree node | ReactNode \| ((props: AntTreeNodeProps) => ReactNode) | - | renderProps: 4.20.0 |
| tagRender | Customize tag render when `multiple` | (props) => ReactNode | - | |
| treeCheckable | Whether to show checkbox on the treeNodes | boolean | false | |
Expand Down
9 changes: 3 additions & 6 deletions components/tree-select/index.tsx
Expand Up @@ -45,7 +45,6 @@ export interface TreeSelectProps<
RcTreeSelectProps<ValueType, OptionType>,
| 'showTreeIcon'
| 'treeMotion'
| 'inputIcon'
| 'mode'
| 'getInputElement'
| 'backfill'
Expand Down Expand Up @@ -96,7 +95,6 @@ const InternalTreeSelect = <
transitionName,
choiceTransitionName = '',
status: customStatus,
showArrow,
treeExpandAction,
builtinPlacements,
dropdownMatchSelectWidth,
Expand Down Expand Up @@ -155,7 +153,7 @@ const InternalTreeSelect = <
);

const isMultiple = !!(treeCheckable || multiple);
const mergedShowArrow = useShowArrow(showArrow);
const showSuffixIcon = useShowArrow(props.suffixIcon);

const mergedPopupMatchSelectWidth =
popupMatchSelectWidth ?? dropdownMatchSelectWidth ?? contextPopupMatchSelectWidth;
Expand All @@ -173,7 +171,7 @@ const InternalTreeSelect = <
const { suffixIcon, removeIcon, clearIcon } = getIcons({
...props,
multiple: isMultiple,
showArrow: mergedShowArrow,
showSuffixIcon,
hasFeedback,
feedbackIcon,
prefixCls,
Expand Down Expand Up @@ -253,7 +251,7 @@ const InternalTreeSelect = <
treeCheckable ? <span className={`${prefixCls}-tree-checkbox-inner`} /> : treeCheckable
}
treeLine={!!treeLine}
inputIcon={suffixIcon}
suffixIcon={suffixIcon}
multiple={isMultiple}
placement={memoizedPlacement}
removeIcon={removeIcon}
Expand All @@ -270,7 +268,6 @@ const InternalTreeSelect = <
getTransitionDirection(placement),
transitionName,
)}
showArrow={hasFeedback || mergedShowArrow}
treeExpandAction={treeExpandAction}
/>
);
Expand Down
3 changes: 1 addition & 2 deletions components/tree-select/index.zh-CN.md
Expand Up @@ -58,12 +58,11 @@ demo:
| placeholder | 选择框默认文字 | string | - | |
| placement | 选择框弹出的位置 | `bottomLeft` `bottomRight` `topLeft` `topRight` | bottomLeft | |
| searchValue | 搜索框的值,可以通过 `onSearch` 获取用户输入 | string | - | |
| showArrow | 是否显示 `suffixIcon` | boolean | `true` | |
| showCheckedStrategy | 配置 `treeCheckable` 时,定义选中项回填的方式。`TreeSelect.SHOW_ALL`: 显示所有选中节点(包括父节点)。`TreeSelect.SHOW_PARENT`: 只显示父节点(当父节点下所有子节点都选中时)。 默认只显示子节点 | `TreeSelect.SHOW_ALL` \| `TreeSelect.SHOW_PARENT` \| `TreeSelect.SHOW_CHILD` | `TreeSelect.SHOW_CHILD` | |
| showSearch | 是否支持搜索框 | boolean | 单选:false \| 多选:true | |
| size | 选择框大小 | `large` \| `middle` \| `small` | - | |
| status | 设置校验状态 | 'error' \| 'warning' | - | 4.19.0 |
| suffixIcon | 自定义的选择框后缀图标, 多选模式下必须同时设置 `showArrow` 为 true | ReactNode | - | |
| suffixIcon | 自定义的选择框后缀图标 | ReactNode | `<DownOutlined />` | |
| switcherIcon | 自定义树节点的展开/折叠图标 | ReactNode \| ((props: AntTreeNodeProps) => ReactNode) | - | renderProps: 4.20.0 |
| tagRender | 自定义 tag 内容,多选时生效 | (props) => ReactNode | - | |
| treeCheckable | 显示 Checkbox | boolean | false | |
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -122,7 +122,7 @@
"copy-to-clipboard": "^3.2.0",
"dayjs": "^1.11.1",
"qrcode.react": "^3.1.0",
"rc-cascader": "~3.12.0",
"rc-cascader": "3.13.0-alpha.0",
"rc-checkbox": "~3.1.0",
"rc-collapse": "~3.7.0",
"rc-dialog": "~9.1.0",
Expand All @@ -142,7 +142,7 @@
"rc-rate": "~2.12.0",
"rc-resize-observer": "^1.2.0",
"rc-segmented": "~2.2.0",
"rc-select": "~14.5.0",
"rc-select": "14.6.0-alpha.0",
"rc-slider": "~10.1.0",
"rc-steps": "~6.0.0",
"rc-switch": "~4.1.0",
Expand All @@ -151,7 +151,7 @@
"rc-textarea": "~1.3.2",
"rc-tooltip": "~6.0.0",
"rc-tree": "~5.7.6",
"rc-tree-select": "~5.9.0",
"rc-tree-select": "5.10.0-alpha.0",
"rc-upload": "~4.3.0",
"rc-util": "^5.32.0",
"scroll-into-view-if-needed": "^3.0.3",
Expand Down