Skip to content

Commit

Permalink
chore(select): suffix优化
Browse files Browse the repository at this point in the history
  • Loading branch information
zyprepare committed Feb 26, 2024
1 parent 1aeeb1c commit b97069b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
19 changes: 7 additions & 12 deletions packages/ui/input/src/MockInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { __DEV__ } from '@hi-ui/env'
import { useUncontrolledState } from '@hi-ui/use-uncontrolled-state'
import { CloseCircleFilled } from '@hi-ui/icons'
import type { HiBaseAppearanceEnum, HiBaseDataItem, HiBaseHTMLFieldProps } from '@hi-ui/core'
import { isArray } from '@hi-ui/type-assertion'

const _role = 'mock-input'
const _prefix = getPrefixCls(_role)
Expand Down Expand Up @@ -35,8 +36,7 @@ export const MockInput = forwardRef<HTMLDivElement | null, MockInputProps>(
clearableTrigger = 'hover',
displayRender,
prefix,
suffix,
secondarySuffix,
suffix: suffixProp,
onMouseOver,
onMouseLeave,
...rest
Expand Down Expand Up @@ -84,6 +84,7 @@ export const MockInput = forwardRef<HTMLDivElement | null, MockInputProps>(
)

const hasValue = !!displayValue
const suffix = isArray(suffixProp) ? suffixProp : [suffixProp]

// 在开启 clearable 下展示 清除内容按钮,可点击进行内容清除
const showClearableIcon = useMemo(() => {
Expand Down Expand Up @@ -122,10 +123,8 @@ export const MockInput = forwardRef<HTMLDivElement | null, MockInputProps>(
) : (
<span className={`${prefixCls}__placeholder`}>{placeholder}</span>
)}
{secondarySuffix ? (
<span className={`${prefixCls}__secondary-suffix`}>{secondarySuffix}</span>
) : null}
{suffix || showClearableIcon ? (
{suffix[1] ? <span className={`${prefixCls}__secondary-suffix`}>{suffix[1]}</span> : null}
{suffix[0] || showClearableIcon ? (
<span className={`${prefixCls}__suffix`}>
{showClearableIcon ? (
<span
Expand All @@ -137,7 +136,7 @@ export const MockInput = forwardRef<HTMLDivElement | null, MockInputProps>(
<CloseCircleFilled />
</span>
) : (
suffix
suffix[0]
)}
</span>
) : null}
Expand Down Expand Up @@ -199,11 +198,7 @@ export type MockInputProps = HiBaseHTMLFieldProps<
/**
* 输入框后置内容
*/
suffix?: React.ReactNode
/**
* 输入框次要后置内容
*/
secondarySuffix?: React.ReactNode
suffix?: React.ReactNode | React.ReactNode[]
/**
* 点击 Input 时触发回调
*/
Expand Down
3 changes: 1 addition & 2 deletions packages/ui/select/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ export const Select = forwardRef<HTMLDivElement | null, SelectProps>(
: undefined
}
prefix={prefix}
suffix={menuVisible ? <UpOutlined /> : <DownOutlined />}
secondarySuffix={suffix}
suffix={[menuVisible ? <UpOutlined /> : <DownOutlined />, suffix]}
focused={menuVisible}
value={value}
onChange={(value, item) => {
Expand Down

0 comments on commit b97069b

Please sign in to comment.