Skip to content

Commit d31b0ab

Browse files
authored
type: type lint fix (#1010)
1 parent c01fe37 commit d31b0ab

File tree

6 files changed

+61
-74
lines changed

6 files changed

+61
-74
lines changed

src/BaseSelect.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,6 @@ const BaseSelect = React.forwardRef((props: BaseSelectProps, ref: React.Ref<Base
711711
allowClear,
712712
clearIcon,
713713
disabled,
714-
715714
mergedSearchValue,
716715
mode,
717716
);

src/Select.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ const Select = React.forwardRef(
266266
} else {
267267
rawKey = val.key;
268268
rawLabel = val.label;
269-
rawValue = val.value ?? rawKey;
269+
rawValue = val.value ?? (rawKey as RawValueType);
270270
}
271271

272272
const option = valueOptions.get(rawValue);
@@ -680,9 +680,8 @@ const TypedSelect = Select as unknown as (<
680680
ValueType = any,
681681
OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType,
682682
>(
683-
props: React.PropsWithChildren<SelectProps<ValueType, OptionType>> & {
684-
ref?: React.Ref<BaseSelectRef>;
685-
},
683+
props: React.PropsWithChildren<SelectProps<ValueType, OptionType>> &
684+
React.RefAttributes<BaseSelectRef>,
686685
) => React.ReactElement) & {
687686
Option: typeof Option;
688687
OptGroup: typeof OptGroup;

src/Selector/MultipleSelector.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,14 @@ const SelectSelector: React.FC<SelectorProps> = (props) => {
8080
const selectionPrefixCls = `${prefixCls}-selection`;
8181

8282
// ===================== Search ======================
83-
const inputValue = open || (mode === "multiple" && autoClearSearchValue === false) || mode === 'tags' ? searchValue : '';
84-
const inputEditable: boolean = mode === 'tags' || (mode === "multiple" && autoClearSearchValue === false) || (showSearch && (open || focused));
83+
const inputValue =
84+
open || (mode === 'multiple' && autoClearSearchValue === false) || mode === 'tags'
85+
? searchValue
86+
: '';
87+
const inputEditable: boolean =
88+
mode === 'tags' ||
89+
(mode === 'multiple' && autoClearSearchValue === false) ||
90+
(showSearch && (open || focused));
8591

8692
// We measure width and set to the input immediately
8793
useLayoutEffect(() => {
@@ -236,7 +242,6 @@ const SelectSelector: React.FC<SelectorProps> = (props) => {
236242
return (
237243
<>
238244
{selectionNode}
239-
240245
{!values.length && !inputValue && (
241246
<span className={`${selectionPrefixCls}-placeholder`}>{placeholder}</span>
242247
)}

src/TransBtn.tsx

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,20 @@ export interface TransBtnProps {
1111
children?: React.ReactNode;
1212
}
1313

14-
const TransBtn: React.FC<TransBtnProps> = ({
15-
className,
16-
customizeIcon,
17-
customizeIconProps,
18-
onMouseDown,
19-
onClick,
20-
children,
21-
}) => {
22-
let icon: React.ReactNode;
14+
const TransBtn: React.FC<TransBtnProps> = (props) => {
15+
const { className, customizeIcon, customizeIconProps, children, onMouseDown, onClick } = props;
2316

24-
if (typeof customizeIcon === 'function') {
25-
icon = customizeIcon(customizeIconProps);
26-
} else {
27-
icon = customizeIcon;
28-
}
17+
const icon =
18+
typeof customizeIcon === 'function' ? customizeIcon(customizeIconProps) : customizeIcon;
2919

3020
return (
3121
<span
3222
className={className}
3323
onMouseDown={(event) => {
3424
event.preventDefault();
35-
if (onMouseDown) {
36-
onMouseDown(event);
37-
}
38-
}}
39-
style={{
40-
userSelect: 'none',
41-
WebkitUserSelect: 'none',
25+
onMouseDown?.(event);
4226
}}
27+
style={{ userSelect: 'none', WebkitUserSelect: 'none' }}
4328
unselectable="on"
4429
onClick={onClick}
4530
aria-hidden

src/hooks/useAllowClear.tsx

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
import TransBtn from '../TransBtn';
2-
import type { DisplayValueType, Mode } from '../interface';
3-
import type { ReactNode } from 'react';
2+
import type { DisplayValueType, Mode, RenderNode } from '../interface';
43
import React from 'react';
54

6-
export function useAllowClear(
7-
prefixCls,
8-
onClearMouseDown,
9-
displayValues: DisplayValueType[],
10-
allowClear?: boolean | { clearIcon?: ReactNode },
11-
clearIcon?: ReactNode,
12-
disabled = false,
13-
mergedSearchValue?: string,
14-
mode?: Mode
15-
) {
16-
const mergedClearIcon = React.useMemo(() => {
17-
if (typeof allowClear === "object") {
18-
return allowClear.clearIcon;
19-
}
20-
if (!!clearIcon) return clearIcon;
21-
}, [allowClear, clearIcon]);
5+
export const useAllowClear = (
6+
prefixCls: string,
7+
onClearMouseDown: React.MouseEventHandler<HTMLSpanElement>,
8+
displayValues: DisplayValueType[],
9+
allowClear?: boolean | { clearIcon?: RenderNode },
10+
clearIcon?: RenderNode,
11+
disabled: boolean = false,
12+
mergedSearchValue?: string,
13+
mode?: Mode,
14+
) => {
15+
const mergedClearIcon = React.useMemo(() => {
16+
if (typeof allowClear === 'object') {
17+
return allowClear.clearIcon;
18+
}
19+
if (clearIcon) {
20+
return clearIcon;
21+
}
22+
}, [allowClear, clearIcon]);
2223

24+
const mergedAllowClear = React.useMemo<boolean>(() => {
25+
if (
26+
!disabled &&
27+
!!allowClear &&
28+
(displayValues.length || mergedSearchValue) &&
29+
!(mode === 'combobox' && mergedSearchValue === '')
30+
) {
31+
return true;
32+
}
33+
return false;
34+
}, [allowClear, disabled, displayValues.length, mergedSearchValue, mode]);
2335

24-
const mergedAllowClear = React.useMemo(() => {
25-
if (
26-
!disabled &&
27-
!!allowClear &&
28-
(displayValues.length || mergedSearchValue) &&
29-
!(mode === 'combobox' && mergedSearchValue === '')
30-
) {
31-
return true;
32-
}
33-
return false;
34-
}, [allowClear, disabled, displayValues.length, mergedSearchValue, mode]);
35-
36-
return {
37-
allowClear: mergedAllowClear,
38-
clearIcon: (
39-
<TransBtn
40-
className={`${prefixCls}-clear`}
41-
onMouseDown={onClearMouseDown}
42-
customizeIcon={mergedClearIcon}
43-
>
44-
×
45-
</TransBtn>
46-
)
47-
};
48-
}
36+
return {
37+
allowClear: mergedAllowClear,
38+
clearIcon: (
39+
<TransBtn
40+
className={`${prefixCls}-clear`}
41+
onMouseDown={onClearMouseDown}
42+
customizeIcon={mergedClearIcon}
43+
>
44+
×
45+
</TransBtn>
46+
),
47+
};
48+
};

src/interface.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface DisplayValueType {
1414
key?: React.Key;
1515
value?: RawValueType;
1616
label?: React.ReactNode;
17-
title?: string | number;
17+
title?: React.ReactNode;
1818
disabled?: boolean;
1919
}
2020

@@ -27,4 +27,3 @@ export type Mode = 'multiple' | 'tags' | 'combobox';
2727
export type Placement = 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight';
2828

2929
export type DisplayInfoType = 'add' | 'remove' | 'clear';
30-

0 commit comments

Comments
 (0)