Skip to content

Commit

Permalink
chore: refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
xiamiao committed Jul 30, 2024
1 parent 729614f commit 925f851
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 5 additions & 1 deletion packages/ui/picker/src/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ export const Picker = forwardRef<HTMLDivElement | null, PickerProps>(
}
)

export interface PickerHelper {
resetSearch: () => void
}

export interface PickerProps extends HiBaseHTMLFieldProps<'div'> {
/**
* 是否禁用
Expand Down Expand Up @@ -313,7 +317,7 @@ export interface PickerProps extends HiBaseHTMLFieldProps<'div'> {
/**
* 提供辅助方法的内部引用
*/
innerRef?: React.Ref<HTMLDivElement>
innerRef?: React.Ref<PickerHelper>
}

if (__DEV__) {
Expand Down
9 changes: 4 additions & 5 deletions packages/ui/select/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useLatestCallback } from '@hi-ui/use-latest'
import VirtualList, { useCheckInVirtual } from '@hi-ui/virtual-list'
import type { ListRef } from 'rc-virtual-list'
import { isArrayNonEmpty, isUndef } from '@hi-ui/type-assertion'
import { Picker, PickerProps } from '@hi-ui/picker'
import { Picker, PickerProps, PickerHelper } from '@hi-ui/picker'
import { Highlighter } from '@hi-ui/highlighter'
import { UseDataSource } from '@hi-ui/use-data-source'
import {
Expand All @@ -32,7 +32,6 @@ import { uniqBy } from '@hi-ui/array-utils'
import { HiBaseAppearanceEnum, HiBaseSizeEnum, useLocaleContext } from '@hi-ui/core'
import { callAllFuncs } from '@hi-ui/func-utils'
import { mockDefaultHandlers } from '@hi-ui/dom-utils'
import { mergeRefs } from '@hi-ui/react-utils'

const _role = 'select'
const _prefix = getPrefixCls(_role)
Expand Down Expand Up @@ -85,7 +84,7 @@ export const Select = forwardRef<HTMLDivElement | null, SelectProps>(
ref
) => {
const i18n = useLocaleContext()
const innerRef = useRef<HTMLDivElement>()
const innerRef = useRef<PickerHelper>()
const placeholder = isUndef(placeholderProp) ? i18n.get('select.placeholder') : placeholderProp

const [menuVisible, menuVisibleAction] = useUncontrolledToggle({
Expand Down Expand Up @@ -229,7 +228,8 @@ export const Select = forwardRef<HTMLDivElement | null, SelectProps>(
return (
<SelectProvider value={context}>
<Picker
ref={mergeRefs(ref, innerRef)}
ref={ref}
innerRef={innerRef}
className={cls}
{...rootProps}
visible={menuVisible}
Expand All @@ -243,7 +243,6 @@ export const Select = forwardRef<HTMLDivElement | null, SelectProps>(
loading={rest.loading !== undefined ? rest.loading : loading}
footer={renderExtraFooter ? renderExtraFooter() : null}
scrollable={!inVirtual}
innerRef={innerRef}
trigger={
customRender ? (
typeof customRender === 'function' ? (
Expand Down

0 comments on commit 925f851

Please sign in to comment.