Skip to content

Commit b3e590a

Browse files
committed
feat: SelectPicker - add support for load more button in menu list
1 parent 6433a45 commit b3e590a

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

src/Shared/Components/SelectPicker/SelectPicker.component.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ const SelectPicker = <OptionValue, IsMulti extends boolean>({
214214
onCreateOption,
215215
closeMenuOnSelect = false,
216216
shouldShowNoOptionsMessage = true,
217-
formatCreateLabel,
218217
...props
219218
}: SelectPickerProps<OptionValue, IsMulti>) => {
220219
const { inputId, required, isDisabled, controlShouldRenderValue = true, value, options, getOptionValue } = props
@@ -408,7 +407,6 @@ const SelectPicker = <OptionValue, IsMulti extends boolean>({
408407
onInputChange={onInputChange}
409408
icon={icon}
410409
showSelectedOptionIcon={shouldShowSelectedOptionIcon}
411-
formatCreateLabel={formatCreateLabel}
412410
onKeyDown={handleKeyDown}
413411
/>
414412
</div>

src/Shared/Components/SelectPicker/common.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import { ReactSelectInputAction } from '@Common/Constants'
3838
import { isNullOrUndefined } from '@Shared/Helpers'
3939
import { Tooltip } from '@Common/Tooltip'
4040
import { TooltipProps } from '@Common/Tooltip/types'
41+
import { ComponentSizeType } from '@Shared/constants'
42+
import { Button, ButtonVariantType } from '../Button'
4143
import { SelectPickerGroupHeadingProps, SelectPickerOptionType, SelectPickerProps } from './type'
4244
import { getGroupCheckboxValue } from './utils'
4345

@@ -203,14 +205,40 @@ export const SelectPickerOption = <OptionValue, IsMulti extends boolean>({
203205
export const SelectPickerMenuList = <OptionValue,>(props: MenuListProps<SelectPickerOptionType<OptionValue>>) => {
204206
const {
205207
children,
206-
selectProps: { inputValue, renderMenuListFooter, shouldRenderCustomOptions, renderCustomOptions },
208+
selectProps: {
209+
inputValue,
210+
renderMenuListFooter,
211+
shouldRenderCustomOptions,
212+
renderCustomOptions,
213+
loadMoreButtonConfig,
214+
},
207215
} = props
208216

209217
return (
210218
<>
211219
{/* added key here to explicitly re-render the list on input change so that the top option is rendered */}
212220
<components.MenuList {...props} key={inputValue}>
213-
<div className="py-4 cursor">{shouldRenderCustomOptions ? renderCustomOptions() : children}</div>
221+
<div className="py-4 cursor">
222+
{shouldRenderCustomOptions ? (
223+
renderCustomOptions()
224+
) : (
225+
<>
226+
{children}
227+
{loadMoreButtonConfig?.show && (
228+
<div className="px-4">
229+
<Button
230+
{...loadMoreButtonConfig}
231+
dataTestId="load-more-previous-deployments"
232+
variant={ButtonVariantType.borderLess}
233+
text="Load more"
234+
size={ComponentSizeType.small}
235+
fullWidth
236+
/>
237+
</div>
238+
)}
239+
</>
240+
)}
241+
</div>
214242
{/* Added to the bottom of menu list to prevent from hiding when the menu is opened close to the bottom of the screen */}
215243
</components.MenuList>
216244
{!shouldRenderCustomOptions && renderMenuListFooter && (

src/Shared/Components/SelectPicker/type.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { CreatableProps } from 'react-select/creatable'
2323
// This import allows to extend the base interface in react-select module via module augmentation
2424
import type {} from 'react-select/base'
2525
import { TooltipProps } from '@Common/Tooltip/types'
26+
import { ButtonProps } from '../Button'
2627

2728
export interface SelectPickerOptionType<OptionValue = string | number> extends OptionType<OptionValue, ReactNode> {
2829
/**
@@ -84,6 +85,11 @@ declare module 'react-select/base' {
8485
* @default 'true'
8586
*/
8687
showSelectedOptionIcon?: boolean
88+
/** Renders "Load more" button at the end of the menu list. */
89+
loadMoreButtonConfig?: Pick<ButtonProps, 'isLoading' | 'disabled'> & {
90+
show?: boolean
91+
onClick?: () => void
92+
}
8793
}
8894
}
8995

@@ -131,6 +137,7 @@ export type SelectPickerProps<OptionValue = number | string, IsMulti extends boo
131137
| 'renderCustomOptions'
132138
| 'icon'
133139
| 'showSelectedOptionIcon'
140+
| 'loadMoreButtonConfig'
134141
>
135142
> &
136143
Required<Pick<SelectProps<OptionValue, IsMulti>, 'inputId'>> &

0 commit comments

Comments
 (0)