Skip to content

Commit

Permalink
fix: select ref typescript typo (ant-design#27482)
Browse files Browse the repository at this point in the history
* fix: select ref typescript typo

* improve
  • Loading branch information
hengkx authored and headwindz committed Nov 4, 2020
1 parent ac5acaa commit 7d4bc38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 3 additions & 4 deletions components/auto-complete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import * as React from 'react';
import toArray from 'rc-util/lib/Children/toArray';
import classNames from 'classnames';
import omit from 'omit.js';
import RcSelect from 'rc-select';
import Select, { InternalSelectProps, OptionType } from '../select';
import Select, { InternalSelectProps, OptionType, RefSelectProps } from '../select';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import devWarning from '../_util/devWarning';
import { isValidElement } from '../_util/reactNode';
Expand All @@ -35,7 +34,7 @@ function isSelectOptionOrSelectOptGroup(child: any): Boolean {
return child && child.type && (child.type.isSelectOption || child.type.isSelectOptGroup);
}

const AutoComplete: React.ForwardRefRenderFunction<RcSelect<any>, AutoCompleteProps> = (
const AutoComplete: React.ForwardRefRenderFunction<RefSelectProps, AutoCompleteProps> = (
props,
ref,
) => {
Expand Down Expand Up @@ -126,7 +125,7 @@ const AutoComplete: React.ForwardRefRenderFunction<RcSelect<any>, AutoCompletePr
);
};

const RefAutoComplete = React.forwardRef<unknown, AutoCompleteProps>(AutoComplete);
const RefAutoComplete = React.forwardRef<RefSelectProps, AutoCompleteProps>(AutoComplete);

type RefAutoCompleteWithOption = typeof RefAutoComplete & {
Option: OptionType;
Expand Down
9 changes: 7 additions & 2 deletions components/select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export interface SelectProps<VT>
mode?: 'multiple' | 'tags';
}

export interface RefSelectProps {
focus: () => void;
blur: () => void;
}

const SECRET_COMBOBOX_MODE_DO_NOT_USE = 'SECRET_COMBOBOX_MODE_DO_NOT_USE';

const InternalSelect = <VT extends SelectValue = SelectValue>(
Expand All @@ -51,7 +56,7 @@ const InternalSelect = <VT extends SelectValue = SelectValue>(
transitionName = 'slide-up',
...props
}: SelectProps<VT>,
ref: React.Ref<RcSelect<VT>>,
ref: React.Ref<RefSelectProps>,
) => {
const {
getPopupContainer: getContextPopupContainer,
Expand Down Expand Up @@ -140,7 +145,7 @@ const InternalSelect = <VT extends SelectValue = SelectValue>(
};

const SelectRef = React.forwardRef(InternalSelect) as <VT extends SelectValue = SelectValue>(
props: SelectProps<VT> & { ref?: React.Ref<RcSelect<VT>> },
props: SelectProps<VT> & { ref?: React.Ref<HTMLInputElement> },
) => React.ReactElement;

type InternalSelectType = typeof SelectRef;
Expand Down

0 comments on commit 7d4bc38

Please sign in to comment.