0 && lastPage !== 1 ? '265px' : '225px' }}
+ style={{ minHeight: options.length > 0 && lastPage !== 1 ? '250px' : '200px' }}
>
{!loading && options.length === 0 && (
)}
- {loading ? (
- <>
- {[...Array(pageSize)].map(() => (
-
- ))}
- >
- ) : (
-
{/* Pagination boutons */}
{options.length > 0 && lastPage !== 1 && (
diff --git a/resources/ts/back/Components/Inputs/MultiSelect.tsx b/resources/ts/back/Components/Inputs/MultiSelect.tsx
index 6015b18a..b14151f8 100644
--- a/resources/ts/back/Components/Inputs/MultiSelect.tsx
+++ b/resources/ts/back/Components/Inputs/MultiSelect.tsx
@@ -1,12 +1,30 @@
+// * Packages
+import { usePage } from "@inertiajs/react";
+import {
+ ButtonHTMLAttributes,
+ ComponentType,
+ CSSProperties,
+ forwardRef,
+ KeyboardEvent,
+ ReactNode,
+ useCallback,
+ useEffect,
+ useId,
+ useImperativeHandle,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
import { cva, type VariantProps } from "class-variance-authority";
import {
CheckIcon,
- XCircle,
- ChevronDown,
+ XCircleIcon,
XIcon,
- WandSparkles,
+ WandSparklesIcon,
+ SearchIcon,
+ ChevronsUpDownIcon,
} from "lucide-react";
-import { cn } from "@/lib/utils";
+// * Components shadcn
import { Separator } from "@/components/ui/separator";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
@@ -19,17 +37,17 @@ import {
Command,
CommandEmpty,
CommandGroup,
- CommandInput,
CommandItem,
CommandList,
- CommandSeparator,
} from "@/components/ui/command";
-import { Label } from "../../../components/ui/label";
+import { Label } from "@/components/ui/label";
+import { Input } from "@/components/ui/input";
+// * Other
+import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
+import InputError from "@/back/Components/InputError";
import useTrans from "@/hooks/use-translations";
import str from "@/hooks/use-string";
-import InputError from "@/back/Components/InputError";
-import { usePage } from "@inertiajs/react";
-import { ButtonHTMLAttributes, ComponentType, CSSProperties, forwardRef, KeyboardEvent, ReactNode, useCallback, useEffect, useId, useImperativeHandle, useMemo, useRef, useState } from "react";
+import { cn } from "@/lib/utils";
/**
* Animation types and configurations
@@ -51,10 +69,11 @@ export interface AnimationConfig {
* Variants for the multi-select component to handle different styles.
* Uses class-variance-authority (cva) to define different styles based on "variant" prop.
*/
-const multiSelectVariants = cva("m-1 transition-all duration-300 ease-in-out", {
+const multiSelectVariants = cva("transition-all duration-300 ease-in-out", {
variants: {
variant: {
- default: "border-foreground/10 text-foreground bg-card hover:bg-card/80",
+ default:
+ "border-foreground/10 text-foreground bg-card hover:bg-card/80",
secondary:
"border-foreground/10 bg-secondary text-secondary-foreground hover:bg-secondary/80",
destructive:
@@ -72,7 +91,7 @@ const multiSelectVariants = cva("m-1 transition-all duration-300 ease-in-out", {
},
defaultVariants: {
variant: "default",
- badgeAnimation: "bounce",
+ badgeAnimation: "none",
},
});
@@ -113,11 +132,8 @@ interface MultiSelectGroup {
* Props for MultiSelect component
*/
interface MultiSelectProps
- extends Omit<
- ButtonHTMLAttributes
,
- "animationConfig"
- >,
- VariantProps {
+ extends Omit, "animationConfig">,
+ VariantProps {
/**
* An array of option objects or groups to be displayed in the multi-select component.
*/
@@ -225,27 +241,27 @@ interface MultiSelectProps
* Can be boolean true for default responsive behavior or an object for custom configuration.
*/
responsive?:
- | boolean
- | {
- /** Configuration for mobile devices (< 640px) */
- mobile?: {
- maxCount?: number;
- hideIcons?: boolean;
- compactMode?: boolean;
- };
- /** Configuration for tablet devices (640px - 1024px) */
- tablet?: {
- maxCount?: number;
- hideIcons?: boolean;
- compactMode?: boolean;
- };
- /** Configuration for desktop devices (> 1024px) */
- desktop?: {
- maxCount?: number;
- hideIcons?: boolean;
- compactMode?: boolean;
- };
- };
+ | boolean
+ | {
+ /** Configuration for mobile devices (< 640px) */
+ mobile?: {
+ maxCount?: number;
+ hideIcons?: boolean;
+ compactMode?: boolean;
+ };
+ /** Configuration for tablet devices (640px - 1024px) */
+ tablet?: {
+ maxCount?: number;
+ hideIcons?: boolean;
+ compactMode?: boolean;
+ };
+ /** Configuration for desktop devices (> 1024px) */
+ desktop?: {
+ maxCount?: number;
+ hideIcons?: boolean;
+ compactMode?: boolean;
+ };
+ };
/**
* Minimum width for the component.
@@ -284,17 +300,17 @@ interface MultiSelectProps
/**
* The name of the field to complete
*/
- name: string
+ name: string;
/**
* Label of the field
*/
- label: string
+ label: string;
/**
- * Does the field required
- */
- required?: boolean
+ * Does the field required
+ */
+ required?: boolean;
/**
* The fonction to set the data in useForm inertia
@@ -302,9 +318,9 @@ interface MultiSelectProps
setData: (name: string, value: string[]) => void;
/**
- * Does the field required
- */
- multiple?: boolean
+ * Does the field required
+ */
+ multiple?: boolean;
/**
* Minimum number of selections required (only when multiple is true)
@@ -323,6 +339,12 @@ interface MultiSelectProps
* Optional, defaults to empty
*/
helper?: string;
+
+ /**
+ * Make the Close button visible
+ * Optional, defaults to empty
+ */
+ closeButtonVisible?: boolean;
}
/**
@@ -386,11 +408,13 @@ export const MultiSelect = forwardRef(
deduplicateOptions = false,
resetOnDefaultValueChange = true,
closeOnSelect = false,
+ closeButtonVisible = false,
...props
},
- ref
+ ref,
) => {
- const [selectedValues, setSelectedValues] = useState(defaultValue);
+ const [selectedValues, setSelectedValues] =
+ useState(defaultValue);
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const [isAnimating, setIsAnimating] = useState(false);
const [searchValue, setSearchValue] = useState("");
@@ -413,7 +437,7 @@ export const MultiSelect = forwardRef(
setTimeout(() => setPoliteMessage(""), 100);
}
},
- []
+ [],
);
const multiSelectId = useId();
@@ -421,26 +445,34 @@ export const MultiSelect = forwardRef(
const triggerDescriptionId = `${multiSelectId}-description`;
const selectedCountId = `${multiSelectId}-count`;
+ // Translations.
+ const transDelete = useTrans("crud.actions.delete");
+ const transClose = useTrans("back.close");
+ const transClear = useTrans("back.clear");
+ const transNoResults = useTrans("back.table_no_results");
+ const transSearchOptions = useTrans("back.multi_select.search_options");
+ const transSelectAll = useTrans("back.multi_select.select_all");
+ const transMore = useTrans("back.multi_select.more");
+ const transClosePopover = useTrans("back.multi_select.close_popover");
+ const transClearList = useTrans("back.multi_select.clear_list");
+
const prevDefaultValueRef = useRef(defaultValue);
const isGroupedOptions = useCallback(
(
- opts: MultiSelectOption[] | MultiSelectGroup[]
+ opts: MultiSelectOption[] | MultiSelectGroup[],
): opts is MultiSelectGroup[] => {
return opts.length > 0 && "heading" in opts[0];
},
- []
+ [],
);
- const arraysEqual = useCallback(
- (a: string[], b: string[]): boolean => {
- if (a.length !== b.length) return false;
- const sortedA = [...a].sort();
- const sortedB = [...b].sort();
- return sortedA.every((val, index) => val === sortedB[index]);
- },
- []
- );
+ const arraysEqual = useCallback((a: string[], b: string[]): boolean => {
+ if (a.length !== b.length) return false;
+ const sortedA = [...a].sort();
+ const sortedB = [...b].sort();
+ return sortedA.every((val, index) => val === sortedB[index]);
+ }, []);
const resetToDefault = useCallback(() => {
setSelectedValues(defaultValue);
@@ -477,19 +509,23 @@ export const MultiSelect = forwardRef(
if (buttonRef.current) {
buttonRef.current.focus();
const originalOutline = buttonRef.current.style.outline;
- const originalOutlineOffset = buttonRef.current.style.outlineOffset;
- buttonRef.current.style.outline = "2px solid hsl(var(--ring))";
+ const originalOutlineOffset =
+ buttonRef.current.style.outlineOffset;
+ buttonRef.current.style.outline =
+ "2px solid hsl(var(--ring))";
buttonRef.current.style.outlineOffset = "2px";
setTimeout(() => {
if (buttonRef.current) {
- buttonRef.current.style.outline = originalOutline;
- buttonRef.current.style.outlineOffset = originalOutlineOffset;
+ buttonRef.current.style.outline =
+ originalOutline;
+ buttonRef.current.style.outlineOffset =
+ originalOutlineOffset;
}
}, 1000);
}
},
}),
- [resetToDefault, selectedValues, onValueChange]
+ [resetToDefault, selectedValues, onValueChange],
);
const [screenSize, setScreenSize] = useState<
@@ -527,9 +563,21 @@ export const MultiSelect = forwardRef(
}
if (responsive === true) {
const defaultResponsive = {
- mobile: { maxCount: 2, hideIcons: false, compactMode: true },
- tablet: { maxCount: 4, hideIcons: false, compactMode: false },
- desktop: { maxCount: 6, hideIcons: false, compactMode: false },
+ mobile: {
+ maxCount: 2,
+ hideIcons: false,
+ compactMode: true,
+ },
+ tablet: {
+ maxCount: 4,
+ hideIcons: false,
+ compactMode: false,
+ },
+ desktop: {
+ maxCount: 6,
+ hideIcons: false,
+ compactMode: false,
+ },
};
const currentSettings = defaultResponsive[screenSize];
return {
@@ -614,18 +662,22 @@ export const MultiSelect = forwardRef(
uniqueOptions.push(option);
}
});
- if (process.env.NODE_ENV === "development" && duplicates.length > 0) {
+ if (
+ process.env.NODE_ENV === "development" &&
+ duplicates.length > 0
+ ) {
const action = deduplicateOptions
? "automatically removed"
: "detected";
console.warn(
`MultiSelect: Duplicate option values ${action}: ${duplicates.join(
- ", "
+ ", ",
)}. ` +
- `${deduplicateOptions
- ? "Duplicates have been removed automatically."
- : "This may cause unexpected behavior. Consider setting 'deduplicateOptions={true}' or ensure all option values are unique."
- }`
+ `${
+ deduplicateOptions
+ ? "Duplicates have been removed automatically."
+ : "This may cause unexpected behavior. Consider setting 'deduplicateOptions={true}' or ensure all option values are unique."
+ }`,
);
}
return deduplicateOptions ? uniqueOptions : allOptions;
@@ -633,15 +685,17 @@ export const MultiSelect = forwardRef(
const getOptionByValue = useCallback(
(value: string): MultiSelectOption | undefined => {
- const option = getAllOptions().find((option) => option.value === value);
+ const option = getAllOptions().find(
+ (option) => option.value === value,
+ );
if (!option && process.env.NODE_ENV === "development") {
console.warn(
- `MultiSelect: Option with value "${value}" not found in options list`
+ `MultiSelect: Option with value "${value}" not found in options list`,
);
}
return option;
},
- [getAllOptions]
+ [getAllOptions],
);
const filteredOptions = useMemo(() => {
@@ -656,24 +710,31 @@ export const MultiSelect = forwardRef(
option.label
.toLowerCase()
.includes(searchValue.toLowerCase()) ||
- option.value.toLowerCase().includes(searchValue.toLowerCase())
+ option.value
+ .toLowerCase()
+ .includes(searchValue.toLowerCase()),
),
}))
.filter((group) => group.options.length > 0);
}
return options.filter(
(option) =>
- option.label.toLowerCase().includes(searchValue.toLowerCase()) ||
- option.value.toLowerCase().includes(searchValue.toLowerCase())
+ option.label
+ .toLowerCase()
+ .includes(searchValue.toLowerCase()) ||
+ option.value
+ .toLowerCase()
+ .includes(searchValue.toLowerCase()),
);
}, [options, searchValue, searchable, isGroupedOptions]);
- const handleInputKeyDown = (
- event: KeyboardEvent
- ) => {
+ const handleInputKeyDown = (event: KeyboardEvent) => {
if (event.key === "Enter") {
setIsPopoverOpen(true);
- } else if (event.key === "Backspace" && !event.currentTarget.value) {
+ } else if (
+ event.key === "Backspace" &&
+ !event.currentTarget.value
+ ) {
const newSelectedValues = [...selectedValues];
newSelectedValues.pop();
setSelectedValues(newSelectedValues);
@@ -691,7 +752,9 @@ export const MultiSelect = forwardRef(
// MODE SINGLE SELECT
if (!multiple) {
- const newSelectedValues = selectedValues.includes(optionValue) ? [] : [optionValue];
+ const newSelectedValues = selectedValues.includes(optionValue)
+ ? []
+ : [optionValue];
setSelectedValues(newSelectedValues);
if (onValueChange) {
onValueChange(newSelectedValues);
@@ -708,10 +771,15 @@ export const MultiSelect = forwardRef(
if (isCurrentlySelected) {
if (minSelection && selectedValues.length <= minSelection) {
- announce(`Minimum ${minSelection} selection(s) required`, "assertive");
+ announce(
+ `Minimum ${minSelection} selection(s) required`,
+ "assertive",
+ );
return;
}
- const newSelectedValues = selectedValues.filter((value) => value !== optionValue);
+ const newSelectedValues = selectedValues.filter(
+ (value) => value !== optionValue,
+ );
setSelectedValues(newSelectedValues);
if (onValueChange) {
onValueChange(newSelectedValues);
@@ -719,7 +787,10 @@ export const MultiSelect = forwardRef(
setData(name, newSelectedValues);
} else {
if (maxSelection && selectedValues.length >= maxSelection) {
- announce(`Maximum ${maxSelection} selection(s) allowed`, "assertive");
+ announce(
+ `Maximum ${maxSelection} selection(s) allowed`,
+ "assertive",
+ );
return;
}
const newSelectedValues = [...selectedValues, optionValue];
@@ -738,7 +809,10 @@ export const MultiSelect = forwardRef(
const handleClear = () => {
if (disabled) return;
if (multiple && minSelection && minSelection > 0) {
- announce(`Minimum ${minSelection} selection(s) required`, "assertive");
+ announce(
+ `Minimum ${minSelection} selection(s) required`,
+ "assertive",
+ );
return;
}
setSelectedValues([]);
@@ -757,7 +831,7 @@ export const MultiSelect = forwardRef(
if (disabled) return;
const newSelectedValues = selectedValues.slice(
0,
- responsiveSettings.maxCount
+ responsiveSettings.maxCount,
);
setSelectedValues(newSelectedValues);
if (onValueChange) {
@@ -768,18 +842,26 @@ export const MultiSelect = forwardRef(
const toggleAll = () => {
if (disabled || !multiple) return;
- const allOptions = getAllOptions().filter((option) => !option.disabled);
+ const allOptions = getAllOptions().filter(
+ (option) => !option.disabled,
+ );
if (selectedValues.length === allOptions.length) {
if (minSelection && minSelection > 0) {
- announce(`Minimum ${minSelection} selection(s) required`, "assertive");
+ announce(
+ `Minimum ${minSelection} selection(s) required`,
+ "assertive",
+ );
return;
}
handleClear();
} else {
const allValues = allOptions.map((option) => option.value);
if (maxSelection && allValues.length > maxSelection) {
- announce(`Maximum ${maxSelection} selection(s) allowed`, "assertive");
+ announce(
+ `Maximum ${maxSelection} selection(s) allowed`,
+ "assertive",
+ );
return;
}
setSelectedValues(allValues);
@@ -803,7 +885,12 @@ export const MultiSelect = forwardRef(
}
prevDefaultValueRef.current = [...defaultValue];
}
- }, [defaultValue, selectedValues, arraysEqual, resetOnDefaultValueChange]);
+ }, [
+ defaultValue,
+ selectedValues,
+ arraysEqual,
+ resetOnDefaultValueChange,
+ ]);
const getWidthConstraints = () => {
const defaultMinWidth = screenSize === "mobile" ? "0px" : "200px";
@@ -827,29 +914,33 @@ export const MultiSelect = forwardRef(
useEffect(() => {
const selectedCount = selectedValues.length;
const allOptions = getAllOptions();
- const totalOptions = allOptions.filter((opt) => !opt.disabled).length;
+ const totalOptions = allOptions.filter(
+ (opt) => !opt.disabled,
+ ).length;
if (selectedCount !== prevSelectedCount.current) {
const diff = selectedCount - prevSelectedCount.current;
if (diff > 0) {
const addedItems = selectedValues.slice(-diff);
const addedLabels = addedItems
.map(
- (value) => allOptions.find((opt) => opt.value === value)?.label
+ (value) =>
+ allOptions.find((opt) => opt.value === value)
+ ?.label,
)
.filter(Boolean);
if (addedLabels.length === 1) {
announce(
- `${addedLabels[0]} selected. ${selectedCount} of ${totalOptions} options selected.`
+ `${addedLabels[0]} selected. ${selectedCount} of ${totalOptions} options selected.`,
);
} else {
announce(
- `${addedLabels.length} options selected. ${selectedCount} of ${totalOptions} total selected.`
+ `${addedLabels.length} options selected. ${selectedCount} of ${totalOptions} total selected.`,
);
}
} else if (diff < 0) {
announce(
- `Option removed. ${selectedCount} of ${totalOptions} options selected.`
+ `Option removed. ${selectedCount} of ${totalOptions} options selected.`,
);
}
prevSelectedCount.current = selectedCount;
@@ -858,7 +949,7 @@ export const MultiSelect = forwardRef(
if (isPopoverOpen !== prevIsOpen.current) {
if (isPopoverOpen) {
announce(
- `Dropdown opened. ${totalOptions} options available. Use arrow keys to navigate.`
+ `Dropdown opened. ${totalOptions} options available. Use arrow keys to navigate.`,
);
} else {
announce("Dropdown closed.");
@@ -873,31 +964,53 @@ export const MultiSelect = forwardRef(
if (searchValue && isPopoverOpen) {
const filteredCount = allOptions.filter(
(opt) =>
- opt.label.toLowerCase().includes(searchValue.toLowerCase()) ||
- opt.value.toLowerCase().includes(searchValue.toLowerCase())
+ opt.label
+ .toLowerCase()
+ .includes(searchValue.toLowerCase()) ||
+ opt.value
+ .toLowerCase()
+ .includes(searchValue.toLowerCase()),
).length;
announce(
- `${filteredCount} option${filteredCount === 1 ? "" : "s"
- } found for "${searchValue}"`
+ `${filteredCount} option${
+ filteredCount === 1 ? "" : "s"
+ } found for "${searchValue}"`,
);
}
prevSearchValue.current = searchValue;
}
- }, [selectedValues, isPopoverOpen, searchValue, announce, getAllOptions]);
+ }, [
+ selectedValues,
+ isPopoverOpen,
+ searchValue,
+ announce,
+ getAllOptions,
+ ]);
useEffect(() => {
- if (minSelection !== undefined && maxSelection !== undefined && minSelection > maxSelection) {
- console.error('MultiSelect: minSelection cannot be greater than maxSelection');
+ if (
+ minSelection !== undefined &&
+ maxSelection !== undefined &&
+ minSelection > maxSelection
+ ) {
+ console.error(
+ "MultiSelect: minSelection cannot be greater than maxSelection",
+ );
}
- if (!multiple && (minSelection !== undefined || maxSelection !== undefined)) {
- console.warn('MultiSelect: minSelection and maxSelection are ignored when multiple is false');
+ if (
+ !multiple &&
+ (minSelection !== undefined || maxSelection !== undefined)
+ ) {
+ console.warn(
+ "MultiSelect: minSelection and maxSelection are ignored when multiple is false",
+ );
}
if (minSelection !== undefined && minSelection < 0) {
- console.error('MultiSelect: minSelection cannot be negative');
+ console.error("MultiSelect: minSelection cannot be negative");
}
if (maxSelection !== undefined && maxSelection < 1) {
- console.error('MultiSelect: maxSelection must be at least 1');
+ console.error("MultiSelect: maxSelection must be at least 1");
}
}, [minSelection, maxSelection, multiple]);
@@ -915,21 +1028,28 @@ export const MultiSelect = forwardRef(
+ modal={modalPopover}
+ >
- Multi-select dropdown. Use arrow keys to navigate, Enter to select,
- and Escape to close.
+ Multi-select dropdown. Use arrow keys to navigate, Enter
+ to select, and Escape to close.
-
+
{selectedValues.length === 0
? "No options selected"
- : `${selectedValues.length} option${selectedValues.length === 1 ? "" : "s"
- } selected: ${selectedValues
- .map((value) => getOptionByValue(value)?.label)
- .filter(Boolean)
- .join(", ")}`}
+ : `${selectedValues.length} option${
+ selectedValues.length === 1 ? "" : "s"
+ } selected: ${selectedValues
+ .map(
+ (value) => getOptionByValue(value)?.label,
+ )
+ .filter(Boolean)
+ .join(", ")}`}
-
@@ -1137,74 +1303,111 @@ export const MultiSelect = forwardRef(
aria-multiselectable="true"
aria-label="Available options"
className={cn(
- "w-auto p-0",
+ "w-[var(--radix-popover-trigger-width)] p-0",
getPopoverAnimationClass(),
- screenSize === "mobile" && "w-[85vw] max-w-[280px]",
- screenSize === "tablet" && "w-[70vw] max-w-md",
- screenSize === "desktop" && "min-w-[300px]",
- popoverClassName
+ popoverClassName,
)}
style={{
animationDuration: `${animationConfig?.duration || animation}s`,
animationDelay: `${animationConfig?.delay || 0}s`,
maxWidth: `min(${widthConstraints.maxWidth}, 85vw)`,
- maxHeight: screenSize === "mobile" ? "70vh" : "60vh",
+ maxHeight:
+ screenSize === "mobile" ? "70vh" : "60vh",
touchAction: "manipulation",
}}
align="start"
- onEscapeKeyDown={() => setIsPopoverOpen(false)}>
-
+ onEscapeKeyDown={() => setIsPopoverOpen(false)}
+ >
+
{searchable && (
-
- )}
- {searchable && (
-
- Type to filter options. Use arrow keys to navigate results.
+
+
+
+
+
+ setSearchValue(e.target.value)
+ }
+ onKeyDown={handleInputKeyDown}
+ className="w-[calc(100%-2.5rem-40px)] border-0 mx-9"
+ />
+
}
+ tooltipContent={
+
+ {str(transDelete)
+ .ucFirst()
+ .value()}
+
+ }
+ type="button"
+ variant="ghost"
+ size="icon"
+ className="absolute top-1/2 right-0 transform -translate-y-1/2 text-muted-foreground"
+ onClick={() => setSearchValue("")}
+ disabled={
+ searchValue.length < 1 || disabled
+ }
+ />
)}
-
+ {searchable && (
+
+ Type to filter options. Use arrow keys to
+ navigate results.
+
+ )}
+
- {emptyIndicator || "No results found."}
- {" "}
+ {emptyIndicator || transNoResults}
+
+ {/* First option for select all items */}
{!hideSelectAll && !searchValue && multiple && (
-
+
!opt.disabled).length
+ getAllOptions().filter(
+ (opt) => !opt.disabled,
+ ).length
}
- aria-label={`Select all ${getAllOptions().length
- } options`}
- className="cursor-pointer">
+ aria-label={`Select all ${
+ getAllOptions().length
+ } options`}
+ className="cursor-pointer gap-1.5 px-4 py-2 w-full h-auto min-h-10"
+ >
!opt.disabled)
- .length
+ getAllOptions().filter(
+ (opt) =>
+ !opt.disabled,
+ ).length
? "bg-primary text-primary-foreground"
- : "opacity-50 [&_svg]:invisible"
+ : "opacity-50 [&_svg]:invisible",
)}
- aria-hidden="true">
+ aria-hidden="true"
+ >
- ({str(useTrans('back.multi_select.select_all')).ucFirst().value()}
+ (
+ {str(transSelectAll)
+ .ucFirst()
+ .value()}
{getAllOptions().length > 20
? ` - ${getAllOptions().length} options`
: ""}
@@ -1213,80 +1416,119 @@ export const MultiSelect = forwardRef(
)}
+ {/* List of items */}
{isGroupedOptions(filteredOptions) ? (
filteredOptions.map((group) => (
-
+
{group.options.map((option) => {
- const isSelected = selectedValues.includes(
- option.value
- );
+ const isSelected =
+ selectedValues.includes(
+ option.value,
+ );
return (
toggleOption(option.value)}
+ onSelect={() =>
+ toggleOption(
+ option.value,
+ )
+ }
role="option"
- aria-selected={isSelected}
- aria-disabled={option.disabled}
- aria-label={`${option.label}${isSelected ? ", selected" : ", not selected"
- }${option.disabled ? ", disabled" : ""}`}
+ aria-selected={
+ isSelected
+ }
+ aria-disabled={
+ option.disabled
+ }
+ aria-label={`${option.label}${
+ isSelected
+ ? ", selected"
+ : ", not selected"
+ }${option.disabled ? ", disabled" : ""}`}
className={cn(
- "cursor-pointer",
- option.disabled && "opacity-50 cursor-not-allowed"
+ "cursor-pointer gap-1.5 px-4 py-2 w-full h-auto min-h-10",
+ option.disabled &&
+ "opacity-50 cursor-not-allowed",
)}
- disabled={option.disabled}>
+ disabled={
+ option.disabled
+ }
+ >
+ aria-hidden="true"
+ >
{option.icon && (
)}
- {option.label}
+
+ {option.label}
+
);
})}
))
) : (
-
+
{filteredOptions.map((option) => {
- const isSelected = selectedValues.includes(option.value);
+ const isSelected =
+ selectedValues.includes(
+ option.value,
+ );
return (
toggleOption(option.value)}
+ onSelect={() =>
+ toggleOption(
+ option.value,
+ )
+ }
role="option"
aria-selected={isSelected}
- aria-disabled={option.disabled}
- aria-label={`${option.label}${isSelected ? ", selected" : ", not selected"
- }${option.disabled ? ", disabled" : ""}`}
+ aria-disabled={
+ option.disabled
+ }
+ aria-label={`${option.label}${
+ isSelected
+ ? ", selected"
+ : ", not selected"
+ }${option.disabled ? ", disabled" : ""}`}
className={cn(
- "cursor-pointer",
- option.disabled && "opacity-50 cursor-not-allowed"
+ "cursor-pointer gap-1.5 px-4 py-2 w-full h-auto min-h-10",
+ option.disabled &&
+ "opacity-50 cursor-not-allowed",
)}
- disabled={option.disabled}>
+ disabled={option.disabled}
+ >
+ aria-hidden="true"
+ >
{option.icon && (
)}
@@ -1296,47 +1538,82 @@ export const MultiSelect = forwardRef(
})}
)}
-
-
-
+
+ {(closeButtonVisible ||
+ selectedValues.length > 0) && (
+
+
{selectedValues.length > 0 && (
- <>
-
- {str(useTrans('back.clear')).ucFirst().value()}
-
+
+ {str(transClearList)
+ .ucFirst()
+ .value()}
+
+ }
+ className="w-full"
+ type="button"
+ variant="ghost"
+ size="default"
+ onClick={handleClear}
+ disabled={disabled}
+ />
+ )}
+ {closeButtonVisible &&
+ selectedValues.length > 0 && (
- >
+ )}
+ {closeButtonVisible && (
+
+ {str(transClosePopover)
+ .ucFirst()
+ .value()}
+
+ }
+ className="w-full"
+ type="button"
+ variant="ghost"
+ size="default"
+ onClick={() =>
+ setIsPopoverOpen(false)
+ }
+ disabled={disabled}
+ />
)}
- setIsPopoverOpen(false)}
- className="flex-1 justify-center cursor-pointer max-w-full">
- {str(useTrans('back.close')).ucFirst().value()}
-
-
+ )}
{animation > 0 && selectedValues.length > 0 && (
-
setIsAnimating(!isAnimating)}
/>
)}
- {helper && ({helper})}
+ {helper && (
+ {helper}
+ )}
);
- }
+ },
);
MultiSelect.displayName = "MultiSelect";
diff --git a/resources/ts/back/Pages/Document/Actions/Filters.tsx b/resources/ts/back/Pages/Document/Actions/Filters.tsx
index 8fd390e4..00f59069 100644
--- a/resources/ts/back/Pages/Document/Actions/Filters.tsx
+++ b/resources/ts/back/Pages/Document/Actions/Filters.tsx
@@ -31,7 +31,6 @@ export default function Filters() {
modelName={modelName}
label={str(useTrans('back.model_filters.has_no_link.label')).ucFirst().value()}
/>
-
-