Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/types/react-18.2.45
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jia-nan authored Dec 27, 2023
2 parents 052bdbb + d31b0ab commit b759345
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 89 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"jsonp": "^0.2.1",
"less": "^4.2.0",
"np": "^9.2.0",
"prettier": "^2.7.1",
"prettier": "^3.1.1",
"querystring": "^0.2.1",
"rc-dialog": "^9.0.0",
"rc-test": "^7.0.9",
Expand Down
1 change: 0 additions & 1 deletion src/BaseSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,6 @@ const BaseSelect = React.forwardRef((props: BaseSelectProps, ref: React.Ref<Base
allowClear,
clearIcon,
disabled,

mergedSearchValue,
mode,
);
Expand Down
5 changes: 4 additions & 1 deletion src/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
};

const RefOptionList = React.forwardRef(OptionList);
RefOptionList.displayName = 'OptionList';

if (process.env.NODE_ENV !== 'production') {
RefOptionList.displayName = 'OptionList';
}

export default RefOptionList;
7 changes: 3 additions & 4 deletions src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ const Select = React.forwardRef(
} else {
rawKey = val.key;
rawLabel = val.label;
rawValue = val.value ?? rawKey;
rawValue = val.value ?? (rawKey as RawValueType);
}

const option = valueOptions.get(rawValue);
Expand Down Expand Up @@ -680,9 +680,8 @@ const TypedSelect = Select as unknown as (<
ValueType = any,
OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType,
>(
props: React.PropsWithChildren<SelectProps<ValueType, OptionType>> & {
ref?: React.Ref<BaseSelectRef>;
},
props: React.PropsWithChildren<SelectProps<ValueType, OptionType>> &
React.RefAttributes<BaseSelectRef>,
) => React.ReactElement) & {
Option: typeof Option;
OptGroup: typeof OptGroup;
Expand Down
7 changes: 5 additions & 2 deletions src/SelectTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export interface SelectTriggerProps {
onPopupMouseEnter: () => void;
}

const SelectTrigger: React.RefForwardingComponent<RefTriggerProps, SelectTriggerProps> = (
const SelectTrigger: React.ForwardRefRenderFunction<RefTriggerProps, SelectTriggerProps> = (
props,
ref,
) => {
Expand Down Expand Up @@ -180,6 +180,9 @@ const SelectTrigger: React.RefForwardingComponent<RefTriggerProps, SelectTrigger
};

const RefSelectTrigger = React.forwardRef<RefTriggerProps, SelectTriggerProps>(SelectTrigger);
RefSelectTrigger.displayName = 'SelectTrigger';

if (process.env.NODE_ENV !== 'production') {
RefSelectTrigger.displayName = 'SelectTrigger';
}

export default RefSelectTrigger;
7 changes: 5 additions & 2 deletions src/Selector/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface InputProps {
>;
}

const Input: React.RefForwardingComponent<InputRef, InputProps> = (
const Input: React.ForwardRefRenderFunction<InputRef, InputProps> = (
{
prefixCls,
id,
Expand Down Expand Up @@ -141,6 +141,9 @@ const Input: React.RefForwardingComponent<InputRef, InputProps> = (
};

const RefInput = React.forwardRef<InputRef, InputProps>(Input);
RefInput.displayName = 'Input';

if (process.env.NODE_ENV !== 'production') {
RefInput.displayName = 'Input';
}

export default RefInput;
11 changes: 8 additions & 3 deletions src/Selector/MultipleSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@ const SelectSelector: React.FC<SelectorProps> = (props) => {
const selectionPrefixCls = `${prefixCls}-selection`;

// ===================== Search ======================
const inputValue = open || (mode === "multiple" && autoClearSearchValue === false) || mode === 'tags' ? searchValue : '';
const inputEditable: boolean = mode === 'tags' || (mode === "multiple" && autoClearSearchValue === false) || (showSearch && (open || focused));
const inputValue =
open || (mode === 'multiple' && autoClearSearchValue === false) || mode === 'tags'
? searchValue
: '';
const inputEditable: boolean =
mode === 'tags' ||
(mode === 'multiple' && autoClearSearchValue === false) ||
(showSearch && (open || focused));

// We measure width and set to the input immediately
useLayoutEffect(() => {
Expand Down Expand Up @@ -236,7 +242,6 @@ const SelectSelector: React.FC<SelectorProps> = (props) => {
return (
<>
{selectionNode}

{!values.length && !inputValue && (
<span className={`${selectionPrefixCls}-placeholder`}>{placeholder}</span>
)}
Expand Down
13 changes: 6 additions & 7 deletions src/Selector/SingleSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ const SingleSelector: React.FC<SelectorProps> = (props) => {
if (item) {
return null;
}
const hiddenStyle = hasTextInput ? { visibility: 'hidden' } as React.CSSProperties : undefined;
const hiddenStyle = hasTextInput
? ({ visibility: 'hidden' } as React.CSSProperties)
: undefined;
return (
<span
className={`${prefixCls}-selection-placeholder`}
style={hiddenStyle}
>
<span className={`${prefixCls}-selection-placeholder`} style={hiddenStyle}>
{placeholder}
</span>
);
Expand Down Expand Up @@ -108,14 +107,14 @@ const SingleSelector: React.FC<SelectorProps> = (props) => {
</span>

{/* Display value */}
{(!combobox && item) ? (
{!combobox && item ? (
<span
className={`${prefixCls}-selection-item`}
title={selectionTitle}
// 当 Select 已经选中选项时,还需 selection 隐藏但留在原地占位
// https://github.com/ant-design/ant-design/issues/27688
// https://github.com/ant-design/ant-design/issues/41530
style={hasTextInput ? { visibility: 'hidden' } as React.CSSProperties : undefined}
style={hasTextInput ? ({ visibility: 'hidden' } as React.CSSProperties) : undefined}
>
{item.label}
</span>
Expand Down
7 changes: 5 additions & 2 deletions src/Selector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export interface SelectorProps {
domRef: React.Ref<HTMLDivElement>;
}

const Selector: React.RefForwardingComponent<RefSelectorProps, SelectorProps> = (props, ref) => {
const Selector: React.ForwardRefRenderFunction<RefSelectorProps, SelectorProps> = (props, ref) => {
const inputRef = useRef<HTMLInputElement>(null);
const compositionStatusRef = useRef<boolean>(false);

Expand Down Expand Up @@ -274,6 +274,9 @@ const Selector: React.RefForwardingComponent<RefSelectorProps, SelectorProps> =
};

const ForwardSelector = React.forwardRef<RefSelectorProps, SelectorProps>(Selector);
ForwardSelector.displayName = 'Selector';

if (process.env.NODE_ENV !== 'production') {
ForwardSelector.displayName = 'Selector';
}

export default ForwardSelector;
27 changes: 6 additions & 21 deletions src/TransBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,20 @@ export interface TransBtnProps {
children?: React.ReactNode;
}

const TransBtn: React.FC<TransBtnProps> = ({
className,
customizeIcon,
customizeIconProps,
onMouseDown,
onClick,
children,
}) => {
let icon: React.ReactNode;
const TransBtn: React.FC<TransBtnProps> = (props) => {
const { className, customizeIcon, customizeIconProps, children, onMouseDown, onClick } = props;

if (typeof customizeIcon === 'function') {
icon = customizeIcon(customizeIconProps);
} else {
icon = customizeIcon;
}
const icon =
typeof customizeIcon === 'function' ? customizeIcon(customizeIconProps) : customizeIcon;

return (
<span
className={className}
onMouseDown={(event) => {
event.preventDefault();
if (onMouseDown) {
onMouseDown(event);
}
}}
style={{
userSelect: 'none',
WebkitUserSelect: 'none',
onMouseDown?.(event);
}}
style={{ userSelect: 'none', WebkitUserSelect: 'none' }}
unselectable="on"
onClick={onClick}
aria-hidden
Expand Down
86 changes: 43 additions & 43 deletions src/hooks/useAllowClear.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
import TransBtn from '../TransBtn';
import type { DisplayValueType, Mode } from '../interface';
import type { ReactNode } from 'react';
import type { DisplayValueType, Mode, RenderNode } from '../interface';
import React from 'react';

export function useAllowClear(
prefixCls,
onClearMouseDown,
displayValues: DisplayValueType[],
allowClear?: boolean | { clearIcon?: ReactNode },
clearIcon?: ReactNode,
disabled = false,
mergedSearchValue?: string,
mode?: Mode
) {
const mergedClearIcon = React.useMemo(() => {
if (typeof allowClear === "object") {
return allowClear.clearIcon;
}
if (!!clearIcon) return clearIcon;
}, [allowClear, clearIcon]);
export const useAllowClear = (
prefixCls: string,
onClearMouseDown: React.MouseEventHandler<HTMLSpanElement>,
displayValues: DisplayValueType[],
allowClear?: boolean | { clearIcon?: RenderNode },
clearIcon?: RenderNode,
disabled: boolean = false,
mergedSearchValue?: string,
mode?: Mode,
) => {
const mergedClearIcon = React.useMemo(() => {
if (typeof allowClear === 'object') {
return allowClear.clearIcon;
}
if (clearIcon) {
return clearIcon;
}
}, [allowClear, clearIcon]);

const mergedAllowClear = React.useMemo<boolean>(() => {
if (
!disabled &&
!!allowClear &&
(displayValues.length || mergedSearchValue) &&
!(mode === 'combobox' && mergedSearchValue === '')
) {
return true;
}
return false;
}, [allowClear, disabled, displayValues.length, mergedSearchValue, mode]);

const mergedAllowClear = React.useMemo(() => {
if (
!disabled &&
!!allowClear &&
(displayValues.length || mergedSearchValue) &&
!(mode === 'combobox' && mergedSearchValue === '')
) {
return true;
}
return false;
}, [allowClear, disabled, displayValues.length, mergedSearchValue, mode]);

return {
allowClear: mergedAllowClear,
clearIcon: (
<TransBtn
className={`${prefixCls}-clear`}
onMouseDown={onClearMouseDown}
customizeIcon={mergedClearIcon}
>
×
</TransBtn>
)
};
}
return {
allowClear: mergedAllowClear,
clearIcon: (
<TransBtn
className={`${prefixCls}-clear`}
onMouseDown={onClearMouseDown}
customizeIcon={mergedClearIcon}
>
×
</TransBtn>
),
};
};
3 changes: 1 addition & 2 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface DisplayValueType {
key?: React.Key;
value?: RawValueType;
label?: React.ReactNode;
title?: string | number;
title?: React.ReactNode;
disabled?: boolean;
}

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

export type DisplayInfoType = 'add' | 'remove' | 'clear';

0 comments on commit b759345

Please sign in to comment.