mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 21:41:57 +00:00
feat(FE): implement options lazy loading by adding onLoadMore and isLoadingMore props
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import { Check, ChevronsUpDown, X } from 'lucide-react';
|
||||
import { Check, ChevronsUpDown, X, Loader2 } from 'lucide-react';
|
||||
import { cn } from '@/lib/helper';
|
||||
import { Button } from '@/figma-make/components/base/button';
|
||||
import {
|
||||
@@ -29,6 +29,8 @@ interface MultiSelectProps {
|
||||
selected: string[];
|
||||
onChange: (selected: string[]) => void;
|
||||
onSearchChange?: (value: string) => void;
|
||||
onLoadMore?: () => void;
|
||||
isLoadingMore?: boolean;
|
||||
placeholder?: string;
|
||||
className?: string;
|
||||
disabled?: boolean;
|
||||
@@ -39,6 +41,8 @@ export function MultiSelect({
|
||||
selected,
|
||||
onChange,
|
||||
onSearchChange,
|
||||
onLoadMore,
|
||||
isLoadingMore,
|
||||
placeholder = 'Select items...',
|
||||
className,
|
||||
disabled,
|
||||
@@ -115,7 +119,18 @@ export function MultiSelect({
|
||||
onValueChange={onSearchChange}
|
||||
/>
|
||||
<CommandEmpty>No item found.</CommandEmpty>
|
||||
<CommandList className='max-h-[300px] overflow-y-auto'>
|
||||
<CommandList
|
||||
className='max-h-[300px] overflow-y-auto'
|
||||
onScroll={(e) => {
|
||||
const target = e.currentTarget;
|
||||
if (
|
||||
target.scrollHeight - target.scrollTop <=
|
||||
target.clientHeight + 1
|
||||
) {
|
||||
onLoadMore?.();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<CommandGroup className='overflow-visible'>
|
||||
{options.map((option) => (
|
||||
<CommandItem
|
||||
@@ -134,6 +149,11 @@ export function MultiSelect({
|
||||
{option.label}
|
||||
</CommandItem>
|
||||
))}
|
||||
{isLoadingMore && (
|
||||
<div className='py-4 flex justify-center w-full'>
|
||||
<Loader2 className='h-4 w-4 animate-spin text-muted-foreground' />
|
||||
</div>
|
||||
)}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
|
||||
Reference in New Issue
Block a user