Skip to content

Commit a8d598c

Browse files
committed
chore: clean up
1 parent 250d0c8 commit a8d598c

File tree

2 files changed

+18
-161
lines changed

2 files changed

+18
-161
lines changed

src/BaseSelect/index.tsx

Lines changed: 16 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type { AlignType, BuildInPlacements } from '@rc-component/trigger/lib/interface';
22
import { clsx } from 'clsx';
3-
import isMobile from '@rc-component/util/lib/isMobile';
4-
import { useComposeRef } from '@rc-component/util/lib/ref';
53
import { getDOM } from '@rc-component/util/lib/Dom/findDOMNode';
64
import type { ScrollConfig, ScrollTo } from 'rc-virtual-list/lib/List';
75
import * as React from 'react';
@@ -19,7 +17,6 @@ import type {
1917
RenderDOMFunc,
2018
RenderNode,
2119
} from '../interface';
22-
import type { RefSelectorProps } from '../Selector';
2320
import type { RefTriggerProps } from '../SelectTrigger';
2421
import SelectTrigger from '../SelectTrigger';
2522
import { getSeparatedContent, isValidCount } from '../utils/valueUtil';
@@ -190,7 +187,7 @@ export interface BaseSelectProps extends BaseSelectPrivateProps, React.AriaAttri
190187
// >>> Icons
191188
allowClear?: boolean | { clearIcon?: React.ReactNode };
192189
prefix?: React.ReactNode;
193-
suffix?: React.ReactNode;
190+
suffix?: RenderNode;
194191
/**
195192
* Clear all icon
196193
* @deprecated Please use `allowClear` instead
@@ -337,20 +334,10 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
337334
delete domProps[propName];
338335
});
339336

340-
// ============================= Mobile =============================
341-
const [mobile, setMobile] = React.useState(false);
342-
React.useEffect(() => {
343-
// Only update on the client side
344-
setMobile(isMobile());
345-
}, []);
346-
347337
// ============================== Refs ==============================
348338
const containerRef = React.useRef<SelectInputRef>(null);
349339
const triggerRef = React.useRef<RefTriggerProps>(null);
350-
// const selectorRef = React.useRef<RefSelectorProps>(null);
351340
const listRef = React.useRef<RefOptionListProps>(null);
352-
// const blurRef = React.useRef<boolean>(false);
353-
const customDomRef = React.useRef<HTMLElement>(null);
354341

355342
/** Used for component focused management */
356343
const [focused, setFocused] = React.useState(false);
@@ -382,15 +369,6 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
382369
const customizeInputElement: React.ReactElement =
383370
(mode === 'combobox' && typeof getInputElement === 'function' && getInputElement()) || null;
384371

385-
// Used for customize replacement for `rc-cascader`
386-
const customizeRawInputElement: React.ReactElement =
387-
typeof getRawInputElement === 'function' && getRawInputElement();
388-
389-
const customizeRawInputRef = useComposeRef<HTMLElement>(
390-
customDomRef,
391-
customizeRawInputElement?.props?.ref,
392-
);
393-
394372
// ============================== Open ==============================
395373
// Not trigger `open` when `notFoundContent` is empty
396374
const emptyListContent = !notFoundContent && emptyOptions;
@@ -717,28 +695,19 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
717695
// == Render ==
718696
// ==================================================================
719697

720-
// ============================= Arrow ==============================
721-
// const showSuffixIcon = !!suffixIcon || loading;
722-
// let arrowNode: React.ReactNode;
723-
724-
// if (showSuffixIcon) {
725-
// arrowNode = (
726-
// <TransBtn
727-
// className={clsx(`${prefixCls}-arrow`, classNames?.suffix, {
728-
// [`${prefixCls}-arrow-loading`]: loading,
729-
// })}
730-
// style={styles?.suffix}
731-
// customizeIcon={suffixIcon}
732-
// customizeIconProps={{
733-
// loading,
734-
// searchValue: mergedSearchValue,
735-
// open: mergedOpen,
736-
// focused: mockFocused,
737-
// showSearch: mergedShowSearch,
738-
// }}
739-
// />
740-
// );
741-
// }
698+
// ============================= Suffix =============================
699+
const suffixIcon: React.ReactNode = React.useMemo(() => {
700+
if (typeof suffix === 'function') {
701+
return suffix({
702+
searchValue: mergedSearchValue,
703+
open: mergedOpen,
704+
focused,
705+
showSearch,
706+
loading,
707+
});
708+
}
709+
return suffix;
710+
}, [suffix, mergedSearchValue, mergedOpen, focused, showSearch, loading]);
742711

743712
// ============================= Clear ==============================
744713
const onClearMouseDown: React.MouseEventHandler<HTMLSpanElement> = () => {
@@ -772,94 +741,14 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
772741
[`${prefixCls}-multiple`]: multiple,
773742
[`${prefixCls}-single`]: !multiple,
774743
[`${prefixCls}-allow-clear`]: mergedAllowClear,
775-
// [`${prefixCls}-show-arrow`]: showSuffixIcon,
744+
[`${prefixCls}-show-arrow`]: suffixIcon !== undefined && suffixIcon !== null,
776745
[`${prefixCls}-disabled`]: disabled,
777746
[`${prefixCls}-loading`]: loading,
778747
[`${prefixCls}-open`]: mergedOpen,
779748
[`${prefixCls}-customize-input`]: customizeInputElement,
780749
[`${prefixCls}-show-search`]: showSearch,
781750
});
782751

783-
// >>> Selector
784-
// const selectorNode = (
785-
// <SelectTrigger
786-
// ref={triggerRef}
787-
// disabled={disabled}
788-
// prefixCls={prefixCls}
789-
// visible={mergedOpen}
790-
// popupElement={optionList}
791-
// animation={animation}
792-
// transitionName={transitionName}
793-
// popupStyle={popupStyle}
794-
// popupClassName={popupClassName}
795-
// direction={direction}
796-
// popupMatchSelectWidth={popupMatchSelectWidth}
797-
// popupRender={popupRender}
798-
// popupAlign={popupAlign}
799-
// placement={placement}
800-
// builtinPlacements={builtinPlacements}
801-
// getPopupContainer={getPopupContainer}
802-
// empty={emptyOptions}
803-
// onPopupVisibleChange={onTriggerVisibleChange}
804-
// onPopupMouseEnter={onPopupMouseEnter}
805-
// >
806-
// {customizeRawInputElement ? (
807-
// React.cloneElement(customizeRawInputElement, {
808-
// ref: customizeRawInputRef,
809-
// })
810-
// ) : (
811-
// <Selector
812-
// {...props}
813-
// prefixClassName={classNames?.prefix}
814-
// prefixStyle={styles?.prefix}
815-
// prefixCls={prefixCls}
816-
// inputElement={customizeInputElement}
817-
// ref={selectorRef}
818-
// id={id}
819-
// prefix={prefix}
820-
// showSearch={mergedShowSearch}
821-
// autoClearSearchValue={autoClearSearchValue}
822-
// mode={mode}
823-
// activeDescendantId={activeDescendantId}
824-
// tagRender={tagRender}
825-
// values={displayValues}
826-
// open={mergedOpen}
827-
// onToggleOpen={onToggleOpen}
828-
// activeValue={activeValue}
829-
// searchValue={mergedSearchValue}
830-
// onSearch={onInternalSearch}
831-
// onSearchSubmit={onInternalSearchSubmit}
832-
// onRemove={onSelectorRemove}
833-
// tokenWithEnter={tokenWithEnter}
834-
// onInputBlur={onInputBlur}
835-
// />
836-
// )}
837-
// </SelectTrigger>
838-
// );
839-
840-
// Render raw
841-
// if (customizeRawInputElement) {
842-
// renderNode = selectorNode;
843-
// } else {
844-
// renderNode = (
845-
// <div
846-
// className={mergedClassName}
847-
// {...domProps}
848-
// ref={containerRef}
849-
// onMouseDown={onInternalMouseDown}
850-
// onKeyDown={onInternalKeyDown}
851-
// onKeyUp={onInternalKeyUp}
852-
// onFocus={onContainerFocus}
853-
// onBlur={onContainerBlur}
854-
// >
855-
// <Polite visible={mockFocused && !mergedOpen} values={displayValues} />
856-
// {selectorNode}
857-
// {arrowNode}
858-
// {mergedAllowClear && clearNode}
859-
// </div>
860-
// );
861-
// }
862-
863752
// >>> Render
864753
let renderNode: React.ReactElement = (
865754
<SelectInput
@@ -873,7 +762,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
873762
focused={focused}
874763
// UI
875764
prefix={prefix}
876-
suffix={suffix}
765+
suffix={suffixIcon}
877766
clearIcon={clearNode}
878767
// Type or mode
879768
multiple={multiple}
@@ -901,39 +790,6 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
901790
/>
902791
);
903792

904-
// const renderSelectTrigger = (childrenNode?: React.ReactElement) => (
905-
// <SelectTrigger
906-
// ref={triggerRef}
907-
// disabled={disabled}
908-
// prefixCls={prefixCls}
909-
// visible={mergedOpen}
910-
// popupElement={optionList}
911-
// animation={animation}
912-
// transitionName={transitionName}
913-
// popupStyle={popupStyle}
914-
// popupClassName={popupClassName}
915-
// direction={direction}
916-
// popupMatchSelectWidth={popupMatchSelectWidth}
917-
// popupRender={popupRender}
918-
// popupAlign={popupAlign}
919-
// placement={placement}
920-
// builtinPlacements={builtinPlacements}
921-
// getPopupContainer={getPopupContainer}
922-
// empty={emptyOptions}
923-
// // onPopupVisibleChange={onTriggerVisibleChange}
924-
// onPopupMouseEnter={onPopupMouseEnter}
925-
// >
926-
// {childrenNode}
927-
// </SelectTrigger>
928-
// );
929-
930-
// if (components.root) {
931-
// renderNode = renderSelectTrigger(renderSelectInput());
932-
// } else {
933-
// // renderNode = renderSelectInput(renderSelectTrigger());
934-
// renderNode = renderSelectInput(renderSelectTrigger(<a />));
935-
// }
936-
937793
renderNode = (
938794
<SelectTrigger
939795
ref={triggerRef}

src/SelectInput/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import Affix from './Affix';
33
import SelectContent from './Content';
44
import SelectInputContext from './context';
5-
import type { DisplayValueType, Mode } from '../interface';
5+
import type { DisplayValueType, Mode, RenderNode } from '../interface';
66
import useBaseProps from '../hooks/useBaseProps';
77
import { omit, useEvent } from '@rc-component/util';
88
import KeyCode from '@rc-component/util/lib/KeyCode';
@@ -23,6 +23,7 @@ export interface SelectInputProps extends Omit<React.HTMLAttributes<HTMLDivEleme
2323
prefix?: React.ReactNode;
2424
suffix?: React.ReactNode;
2525
clearIcon?: React.ReactNode;
26+
removeIcon?: RenderNode;
2627
multiple?: boolean;
2728
displayValues: DisplayValueType[];
2829
placeholder?: React.ReactNode;

0 commit comments

Comments
 (0)