🐛 fix: no result not showing

This commit is contained in:
Wahyu Kurniawan 2024-02-24 14:02:23 +07:00
parent 54c2e8ec0b
commit d387229e80
No known key found for this signature in database
GPG Key ID: 040A1549143A8E33
2 changed files with 23 additions and 25 deletions

View File

@ -17,7 +17,7 @@ import {
} from 'components/shared/CustomIcon'; } from 'components/shared/CustomIcon';
import { cloneIcon } from 'utils/cloneIcon'; import { cloneIcon } from 'utils/cloneIcon';
import { cn } from 'utils/classnames'; import { cn } from 'utils/classnames';
import { SelectItem } from './SelectItem'; import { SelectItem, EmptySelectItem } from './SelectItem';
import { SelectValue } from './SelectValue'; import { SelectValue } from './SelectValue';
export type SelectOption = { export type SelectOption = {
@ -300,7 +300,7 @@ export const Select = ({
} }
return placeholderProp; return placeholderProp;
}, [hideValues, multiple, selectedItems.length, placeholderProp]); }, [hideValues, multiple, selectedItems.length, placeholderProp]);
console.log('filteredItems', filteredItems.length === 0);
return ( return (
<div className={theme.container()}> <div className={theme.container()}>
{/* Label & description */} {/* Label & description */}
@ -372,8 +372,7 @@ export const Select = ({
'bottom-[65%]': dropdownPosition === 'top' && label && description, 'bottom-[65%]': dropdownPosition === 'top' && label && description,
})} })}
> >
{isOpen && {isOpen && filteredItems.length !== 0 ? (
filteredItems.length !== 0 &&
filteredItems.map((item, index) => ( filteredItems.map((item, index) => (
<SelectItem <SelectItem
{...getItemProps({ item, index })} {...getItemProps({ item, index })}
@ -382,10 +381,12 @@ export const Select = ({
option={item} option={item}
hovered={highlightedIndex === index} hovered={highlightedIndex === index}
orientation={orientation} orientation={orientation}
empty={filteredItems.length === 0}
variant={variant} variant={variant}
/> />
))} ))
) : (
<EmptySelectItem />
)}
</ul> </ul>
</div> </div>
); );

View File

@ -26,21 +26,11 @@ export interface SelectItemProps
option: SelectOption; option: SelectOption;
orientation?: SelectOrientation; orientation?: SelectOrientation;
hovered?: boolean; hovered?: boolean;
empty?: boolean;
} }
const SelectItem = forwardRef<HTMLLIElement, SelectItemProps>( const SelectItem = forwardRef<HTMLLIElement, SelectItemProps>(
( (
{ { className, selected, orientation, hovered, variant, option, ...props },
className,
selected,
option,
orientation,
hovered,
empty,
variant,
...props
},
ref, ref,
) => { ) => {
const theme = selectItemTheme({ active: hovered, orientation, variant }); const theme = selectItemTheme({ active: hovered, orientation, variant });
@ -60,14 +50,6 @@ const SelectItem = forwardRef<HTMLLIElement, SelectItemProps>(
return null; return null;
}, [rightIcon]); }, [rightIcon]);
if (empty) {
return (
<li {...props} className={theme.wrapper()}>
No results found
</li>
);
}
return ( return (
<li <li
{...props} {...props}
@ -95,4 +77,19 @@ const SelectItem = forwardRef<HTMLLIElement, SelectItemProps>(
SelectItem.displayName = 'SelectItem'; SelectItem.displayName = 'SelectItem';
/**
* Represents an empty select item.
* @returns {JSX.Element} - A JSX element representing the empty select item.
*/
export const EmptySelectItem = () => {
const theme = selectItemTheme();
return (
<li className={theme.wrapper()}>
<p className={theme.label({ class: 'text-elements-disabled' })}>
No results found
</p>
</li>
);
};
export { SelectItem }; export { SelectItem };