From 33e8617050d2d29a61c0a94a37702acdc8270455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E8=89=B3=E5=85=B5?= Date: Thu, 3 Sep 2026 08:43:23 +0800 Subject: [PATCH 1/3] refactor: use renderable guards --- package.json | 2 +- src/BaseSelect/index.tsx | 4 ++-- src/Select.tsx | 6 +++--- src/SelectInput/index.tsx | 12 ++++++++++-- src/hooks/useAllowClear.tsx | 9 ++++++++- src/utils/commonUtil.ts | 4 ---- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index b8c18ee7..14b6d995 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "dependencies": { "@rc-component/overflow": "^1.0.0", "@rc-component/trigger": "^3.0.0", - "@rc-component/util": "^1.11.1", + "@rc-component/util": "^1.13.0", "@rc-component/virtual-list": "^1.2.0", "clsx": "^2.1.1" }, diff --git a/src/BaseSelect/index.tsx b/src/BaseSelect/index.tsx index bd2f9925..0389f623 100644 --- a/src/BaseSelect/index.tsx +++ b/src/BaseSelect/index.tsx @@ -1,6 +1,6 @@ import type { AlignType, BuildInPlacements } from '@rc-component/trigger'; import { clsx } from 'clsx'; -import { getDOM, useEvent } from '@rc-component/util'; +import { getDOM, isNonNullable, useEvent } from '@rc-component/util'; import type { ScrollConfig, ScrollTo } from '@rc-component/virtual-list'; import * as React from 'react'; import { useAllowClear } from '../hooks/useAllowClear'; @@ -744,7 +744,7 @@ const BaseSelect = React.forwardRef((props, ref) [`${prefixCls}-multiple`]: multiple, [`${prefixCls}-single`]: !multiple, [`${prefixCls}-allow-clear`]: mergedAllowClear, - [`${prefixCls}-show-arrow`]: mergedSuffixIcon !== undefined && mergedSuffixIcon !== null, + [`${prefixCls}-show-arrow`]: isNonNullable(mergedSuffixIcon), [`${prefixCls}-disabled`]: disabled, [`${prefixCls}-loading`]: loading, [`${prefixCls}-open`]: mergedOpen, diff --git a/src/Select.tsx b/src/Select.tsx index 2489e2a3..9735154f 100644 --- a/src/Select.tsx +++ b/src/Select.tsx @@ -29,7 +29,7 @@ * - `combobox` mode not support `optionLabelProp` */ -import { useControlledState, useId, warning } from '@rc-component/util'; +import { isNonNullable, useControlledState, useId, warning } from '@rc-component/util'; import * as React from 'react'; import type { BaseSelectProps, @@ -51,7 +51,7 @@ import useFilterOptions from './hooks/useFilterOptions'; import useOptions from './hooks/useOptions'; import useRefFunc from './hooks/useRefFunc'; import type { FlattenOptionData } from './interface'; -import { hasValue, isComboNoValue, toArray } from './utils/commonUtil'; +import { isComboNoValue, toArray } from './utils/commonUtil'; import { fillFieldNames, flattenOptions, injectPropsWithOption } from './utils/valueUtil'; import warningProps, { warningNullOptions } from './utils/warningPropsUtil'; import useSearchConfig from './hooks/useSearchConfig'; @@ -392,7 +392,7 @@ const Select = React.forwardRef { if (mode === 'combobox') { const strValue = mergedValues[0]?.value; - setSearchValue(hasValue(strValue) ? String(strValue) : ''); + setSearchValue(isNonNullable(strValue) ? String(strValue) : ''); } }, [mergedValues]); diff --git a/src/SelectInput/index.tsx b/src/SelectInput/index.tsx index cc22674b..0035803a 100644 --- a/src/SelectInput/index.tsx +++ b/src/SelectInput/index.tsx @@ -4,7 +4,15 @@ import SelectContent from './Content'; import SelectInputContext from './context'; import type { DisplayValueType, Mode, RenderNode } from '../interface'; import useBaseProps from '../hooks/useBaseProps'; -import { composeRef, getDOM, KeyCode, omit, pickAttrs, useEvent } from '@rc-component/util'; +import { + composeRef, + getDOM, + isReactRenderable, + KeyCode, + omit, + pickAttrs, + useEvent, +} from '@rc-component/util'; import { isValidateOpenKey } from '../utils/keyUtil'; import { clsx } from 'clsx'; import type { ComponentsConfig } from '../hooks/useComponents'; @@ -298,7 +306,7 @@ export default React.forwardRef(function Selec {suffix} {/* Clear Icon */} - {clearIcon && ( + {isReactRenderable(clearIcon) && (