diff --git a/src/components/Select/Select.tsx b/src/components/Select/Select.tsx index b08dca0a5c..143864e487 100644 --- a/src/components/Select/Select.tsx +++ b/src/components/Select/Select.tsx @@ -13,7 +13,7 @@ import {DEFAULT_VIRTUALIZATION_THRESHOLD, selectBlock} from './constants'; import {useQuickSearch} from './hooks'; import {initialState, reducer} from './store'; import {Option, OptionGroup} from './tech-components'; -import type {SelectProps} from './types'; +import type {SelectProps, SelectRenderPopup} from './types'; import type {SelectFilterRef} from './types-misc'; import { activateFirstClickableItem, @@ -34,6 +34,15 @@ type SelectComponent = (( p: SelectProps & {ref?: React.Ref}, ) => React.ReactElement) & {Option: typeof Option} & {OptionGroup: typeof OptionGroup}; +export const DEFAULT_RENDER_POPUP: SelectRenderPopup = ({renderFilter, renderList}) => { + return ( + + {renderFilter()} + {renderList()} + + ); +}; + export const Select = React.forwardRef(function Select( props: SelectProps, ref: React.Ref, @@ -48,6 +57,7 @@ export const Select = React.forwardRef(function renderOptionGroup, renderSelectedOption, renderEmptyOptions, + renderPopup = DEFAULT_RENDER_POPUP, getOptionHeight, getOptionGroupHeight, filterOption, @@ -245,6 +255,51 @@ export const Select = React.forwardRef(function ), }); + const _renderFilter = () => { + if (filterable) { + return ( + + ); + } + + return null; + }; + + const _renderList = () => { + if (filteredFlattenOptions.length || props.loading) { + return ( + + ); + } + + return ; + }; + return (
(function id={`select-popup-${selectId}`} placement={popupPlacement} > - {filterable && ( - - )} - {filteredFlattenOptions.length || props.loading ? ( - - ) : ( - - )} + {renderPopup({renderFilter: _renderFilter, renderList: _renderList})} {mode === Mode.VIEW ? ( - {children} ) : ( @@ -414,6 +410,30 @@ export const SelectShowcase = (props: SelectProps) => {
+ + { + return ( + +
{'---- Before Filter ----'}
+ {renderFilter()} +
{'---- After Filter, Before List ----'}
+ {renderList()} +
{'---- After List ----'}
+
+ ); + }, + }} + > + + + + +
); }; diff --git a/src/components/Select/types.ts b/src/components/Select/types.ts index 85710fcf5e..e568b030c9 100644 --- a/src/components/Select/types.ts +++ b/src/components/Select/types.ts @@ -44,6 +44,11 @@ export type SelectRenderOptionGroup = ( options: SelectRenderOptionViewParams, ) => React.ReactElement; +export type SelectRenderPopup = (popupItems: { + renderFilter: () => React.JSX.Element | null; + renderList: () => React.JSX.Element; +}) => React.ReactElement; + export type SelectSize = InputControlSize; export type SelectProps = QAProps & @@ -63,6 +68,7 @@ export type SelectProps = QAProps & renderOptionGroup?: SelectRenderOptionGroup; renderSelectedOption?: (option: SelectOption, index: number) => React.ReactElement; renderEmptyOptions?: ({filter}: {filter: string}) => React.ReactElement; + renderPopup?: SelectRenderPopup; getOptionHeight?: (option: SelectOption, index: number) => number; getOptionGroupHeight?: (option: SelectOptionGroup, index: number) => number; filterOption?: (option: SelectOption, filter: string) => boolean;