Skip to content

Commit

Permalink
feat: add clear option to single select and increase dropdown height
Browse files Browse the repository at this point in the history
  • Loading branch information
maximgrs committed Nov 8, 2024
1 parent 8457fb1 commit a592061
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ export const BoemlySelect: React.FC<BoemlySelectProps> = ({
? prevSelectedOptions.filter((val) => val !== optionValue)
: [...prevSelectedOptions, optionValue];
} else {
newSelectedOptions = [optionValue];
const isOptionSelected = prevSelectedOptions.includes(optionValue);
newSelectedOptions = isOptionSelected ? [] : [optionValue]; // Deselect if selected, otherwise select
setIsOpen(false); // Close dropdown for single select
}

Expand Down Expand Up @@ -139,17 +140,18 @@ export const BoemlySelect: React.FC<BoemlySelectProps> = ({

// max height for the menu options, to show that there are more items to scroll
const dynamicMaxHeight = useMemo(() => {
if (isMultiple && isSearchable) {
return '52';
if ((isMultiple && isSearchable) || isSearchable) {
return '72';
} else if (isMultiple) {
return '48';
} else if (isSearchable) {
return '52';
return '80';
}

return '40';
return '60';
}, [isMultiple, isSearchable]);

//40 48 52 56 60 64 68 72 80 84 88 90 100
//80

return (
<Menu
isLazy
Expand Down Expand Up @@ -293,6 +295,7 @@ export const BoemlySelect: React.FC<BoemlySelectProps> = ({
filteredOptions.map(({ value, label, disabled = false }) => {
const searchIndex = label.toLowerCase().indexOf(searchTerm.toLowerCase());
const isMatch = searchIndex !== -1;
const isSelected = selectedOptions.includes(value);

let beforeMatch = label.slice(0, searchIndex);
let match = label.slice(searchIndex, searchIndex + searchTerm.length);
Expand All @@ -306,9 +309,14 @@ export const BoemlySelect: React.FC<BoemlySelectProps> = ({
borderRadius="md"
icon={null}
iconSpacing="0"
bg={isSelected ? 'primary.100' : 'transparent'}
>
<Flex justify="space-between" align="center" width="100%">
<Text fontSize={CustomizedSelect.sizes[size].fontSize}>
<Text
fontSize={CustomizedSelect.sizes[size].fontSize}
fontWeight={isSelected ? 'bold' : 'normal'}
color={isSelected ? 'black' : color}
>
{isMatch ? (
<>
{beforeMatch}
Expand All @@ -330,9 +338,7 @@ export const BoemlySelect: React.FC<BoemlySelectProps> = ({
tabIndex={-1}
/>
)}
{!isMultiple && selectedOptions.includes(value) && (
<Check color={primary500} size={16} />
)}
{!isMultiple && isSelected && <Check color={primary500} size={16} />}
</Flex>
</MenuItemOption>
);
Expand Down

0 comments on commit a592061

Please sign in to comment.