Skip to content

Commit

Permalink
refactor: fix type definition
Browse files Browse the repository at this point in the history
  • Loading branch information
RedJue committed Oct 25, 2023
1 parent ba330ec commit c07e7fd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default () => (
| loading | show loading icon in arrow | boolean | false |
| virtual | Disable virtual scroll | boolean | true |
| direction | direction of dropdown | 'ltr' \| 'rtl' | 'ltr' |
| optionRender | Custom rendering options | (oriOption: OptionType, info: { index: number }) => React.ReactNode | - |
| optionRender | Custom rendering options | (oriOption: FlattenOptionData\<BaseOptionType\> , info: { index: number }) => React.ReactNode | - |

### Methods

Expand Down
8 changes: 4 additions & 4 deletions src/OptionList.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import classNames from 'classnames';
import useMemo from 'rc-util/lib/hooks/useMemo';
import KeyCode from 'rc-util/lib/KeyCode';
import useMemo from 'rc-util/lib/hooks/useMemo';
import omit from 'rc-util/lib/omit';
import pickAttrs from 'rc-util/lib/pickAttrs';
import type { ListRef } from 'rc-virtual-list';
import List from 'rc-virtual-list';
import type { ScrollConfig } from 'rc-virtual-list/lib/List';
import * as React from 'react';
import { useEffect } from 'react';
import useBaseProps from './hooks/useBaseProps';
import type { FlattenOptionData } from './interface';
import type { BaseOptionType, RawValueType } from './Select';
import SelectContext from './SelectContext';
import TransBtn from './TransBtn';
import useBaseProps from './hooks/useBaseProps';
import type { FlattenOptionData } from './interface';
import { isPlatformMac } from './utils/platformUtil';

// export interface OptionListProps<OptionsType extends object[]> {
Expand Down Expand Up @@ -369,7 +369,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
>
<div className={`${optionPrefixCls}-content`}>
{typeof optionRender === 'function'
? optionRender({ ...item.data, label: item.label }, { index: itemIndex })
? optionRender(item, { index: itemIndex })
: content}
</div>
{React.isValidElement(menuItemSelectedIcon) || selected}
Expand Down
14 changes: 9 additions & 5 deletions src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ import type {
RenderNode,
} from './BaseSelect';
import BaseSelect, { isMultiple } from './BaseSelect';
import OptGroup from './OptGroup';
import Option from './Option';
import OptionList from './OptionList';
import SelectContext from './SelectContext';
import useCache from './hooks/useCache';
import useFilterOptions from './hooks/useFilterOptions';
import useId from './hooks/useId';
import useOptions from './hooks/useOptions';
import useRefFunc from './hooks/useRefFunc';
import OptGroup from './OptGroup';
import Option from './Option';
import OptionList from './OptionList';
import SelectContext from './SelectContext';
import type { FlattenOptionData } from './interface';
import { hasValue, isComboNoValue, toArray } from './utils/commonUtil';
import { fillFieldNames, flattenOptions, injectPropsWithOption } from './utils/valueUtil';
import warningProps, { warningNullOptions } from './utils/warningPropsUtil';
Expand Down Expand Up @@ -138,7 +139,10 @@ export interface SelectProps<ValueType = any, OptionType extends BaseOptionType
optionLabelProp?: string;
children?: React.ReactNode;
options?: OptionType[];
optionRender?: (oriOption: OptionType, info: { index: number }) => React.ReactNode;
optionRender?: (
oriOption: FlattenOptionData<BaseOptionType>,
info: { index: number },
) => React.ReactNode;
defaultActiveFirstOption?: boolean;
virtual?: boolean;
direction?: 'ltr' | 'rtl';
Expand Down
2 changes: 1 addition & 1 deletion src/SelectContext.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from 'react';
import type { RawValueType, RenderNode } from './BaseSelect';
import type { FlattenOptionData } from './interface';
import type {
BaseOptionType,
FieldNames,
OnActiveValue,
OnInternalSelect,
SelectProps,
} from './Select';
import type { FlattenOptionData } from './interface';

// Use any here since we do not get the type during compilation
export interface SelectContextProps {
Expand Down

0 comments on commit c07e7fd

Please sign in to comment.