From 8d7adbbd27b4948ad86c842c5fd7f74d873ef723 Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Wed, 14 Jan 2026 10:35:51 +0700 Subject: [PATCH] feat: implement lazy loading in SelectInput --- src/components/input/SelectInput.tsx | 136 ++++++++++++++++++++++----- 1 file changed, 115 insertions(+), 21 deletions(-) diff --git a/src/components/input/SelectInput.tsx b/src/components/input/SelectInput.tsx index d35e7589..74e23bc4 100644 --- a/src/components/input/SelectInput.tsx +++ b/src/components/input/SelectInput.tsx @@ -9,15 +9,20 @@ import Select, { SingleValue, components as ReactSelectComponents, ControlProps, + MenuListProps, } from 'react-select'; import CreatableSelect from 'react-select/creatable'; import makeAnimated from 'react-select/animated'; import { useDebounce } from 'use-debounce'; import { cn, getByPath } from '@/lib/helper'; -import useSWR from 'swr'; +import useSWRInfinite from 'swr/infinite'; import { httpClientFetcher } from '@/services/http/client'; -import { BaseApiResponse } from '@/types/api/api-general'; -import { isResponseSuccess } from '@/lib/api-helper'; +import { + BaseApiResponse, + ErrorApiResponse, + SuccessApiResponse, +} from '@/types/api/api-general'; +import { isResponseError, isResponseSuccess } from '@/lib/api-helper'; export interface OptionType { value: string | number; @@ -56,6 +61,7 @@ interface SelectInputBaseProps { onInputChange?: (search: string) => void; startAdornment?: ReactNode; menuPortalTarget?: HTMLElement | null; + onMenuScrollToBottom?: ((event: WheelEvent | TouchEvent) => void) | undefined; } interface SelectInputProps extends SelectInputBaseProps { @@ -93,6 +99,29 @@ const CustomControl = < ); }; +const CustomMenuList = < + Option, + IsMulti extends boolean, + Group extends GroupBase