diff --git a/src/components/Attendees/PeopleSearch.tsx b/src/components/Attendees/PeopleSearch.tsx index 87f1f4a..50c3905 100644 --- a/src/components/Attendees/PeopleSearch.tsx +++ b/src/components/Attendees/PeopleSearch.tsx @@ -7,7 +7,13 @@ import ListItem from "@mui/material/ListItem"; import ListItemAvatar from "@mui/material/ListItemAvatar"; import ListItemText from "@mui/material/ListItemText"; import TextField from "@mui/material/TextField"; -import { type ReactNode, useCallback, useEffect, useState } from "react"; +import { + type ReactNode, + useCallback, + useEffect, + useState, + HTMLAttributes, +} from "react"; import { searchUsers } from "../../features/User/userAPI"; import PeopleOutlineOutlinedIcon from "@mui/icons-material/PeopleOutlineOutlined"; import Chip from "@mui/material/Chip"; @@ -15,6 +21,7 @@ import { useTheme } from "@mui/material/styles"; import { getAccessiblePair } from "../Calendar/utils/calendarColorsUtils"; import { useI18n } from "twake-i18n"; import { SnackbarAlert } from "../Loading/SnackBarAlert"; +import { PopperProps, PaperProps } from "@mui/material"; export interface User { email: string; @@ -42,6 +49,7 @@ export function PeopleSearch({ placeholder, inputSlot, customRenderInput, + customSlotProps, }: { selectedUsers: User[]; onChange: (event: any, users: User[]) => void; @@ -58,6 +66,11 @@ export function PeopleSearch({ query: string, setQuery: (value: string) => void ) => ReactNode; + customSlotProps?: { + popper?: Partial; + paper?: Partial; + listbox?: Partial>; + }; }) { const { t } = useI18n(); const [query, setQuery] = useState(""); @@ -119,53 +132,87 @@ export function PeopleSearch({ }, [objectTypes, query, t]); const defaultRenderInput = useCallback( - (params: AutocompleteRenderInputParams) => ( - <> - - { - if (e.key === "Enter" && onToggleEventPreview) { - e.preventDefault(); - onToggleEventPreview(); - } - }} - slotProps={{ - input: { - ...params.InputProps, - autoComplete: "off", - startAdornment: ( - <> - - {params.InputProps.startAdornment} - - ), - endAdornment: ( - <> - {loading ? ( - - ) : null} - {params.InputProps.endAdornment} - - ), - }, - }} - /> - - ), - [inputError, t, onToggleEventPreview, loading] + (params: AutocompleteRenderInputParams) => { + const inputProps = { + ...params.InputProps, + startAdornment: ( + <> + + {params.InputProps.startAdornment} + + ), + endAdornment: ( + <> + {loading ? : null} + {params.InputProps.endAdornment} + + ), + }; + + const enhancedParamsWithInputProps = { + ...params, + InputProps: inputProps, + inputProps: { + ...params.inputProps, + autoComplete: "off", + }, + }; + + const { InputProps, ...enhancedParams } = enhancedParamsWithInputProps; + + const handleEnterKey = (e: React.KeyboardEvent) => { + if (e.key === "Enter" && onToggleEventPreview) { + e.preventDefault(); + onToggleEventPreview(); + } + }; + + const defaultTextFieldProps = { + error: !!inputError, + helperText: inputError, + placeholder: searchPlaceholder, + label: "", + onKeyDown: handleEnterKey, + slotProps: { + input: { + ...inputProps, + }, + }, + }; + + if (inputSlot) { + return ( + <> + + {inputSlot({ + ...enhancedParamsWithInputProps, + error: !!inputError, + helperText: inputError, + placeholder: searchPlaceholder, + label: "", + onKeyDown: handleEnterKey, + })} + + ); + } + + return ( + <> + + + + ); + }, + [inputError, t, onToggleEventPreview, loading, searchPlaceholder] ); return ( @@ -225,6 +272,7 @@ export function PeopleSearch({ ); onChange(event, mapped); }} + slotProps={customSlotProps} renderInput={(params) => customRenderInput ? customRenderInput(params, query, setQuery) diff --git a/src/components/Menubar/EventSearchBar.tsx b/src/components/Menubar/EventSearchBar.tsx index 4dbc9c0..f8c4bf7 100644 --- a/src/components/Menubar/EventSearchBar.tsx +++ b/src/components/Menubar/EventSearchBar.tsx @@ -233,6 +233,26 @@ export default function SearchBar() { }} objectTypes={["user", "contact"]} onToggleEventPreview={() => {}} + customSlotProps={{ + popper: { + anchorEl: containerRef.current, + placement: "bottom-start", + sx: { + minWidth: searchWidth, + "& .MuiPaper-root": { + width: "100%", + }, + }, + modifiers: [ + { + name: "offset", + options: { + offset: [0, 8], + }, + }, + ], + }, + }} customRenderInput={( params: AutocompleteRenderInputParams, query: string,