import { Autocomplete, TextField } from "@mui/material"; function AutoCompleteSearch({ data, noneBg, clearText, inputValue, placeholder, handleSearch, setInputValue, setSelectedOption, onEnter, }) { const clearIndicatorProps = clearText ? { clearIndicator: { onClick: () => { clearText(); }, }, } : {}; return ( typeof option === "string" ? option : (option?.name ?? "") } inputValue={inputValue} className="!w-full" onInputChange={(_, newInputValue) => { setInputValue && setInputValue(newInputValue); handleSearch(newInputValue); }} onChange={(_, newValue) => { setSelectedOption && setSelectedOption(newValue); // freeSolo: مقدار تأییدشده می‌تواند رشتهٔ تایپ‌شده باشد، نه گزینهٔ لیست. handleSearch( typeof newValue === "string" ? newValue : (newValue?.name ?? "") ); }} componentsProps={clearIndicatorProps} renderOption={(props, option) => (
  • {option.name}
  • )} sx={{ "& .MuiAutocomplete-input": { background: noneBg ? "" : "#ffffff !important", }, }} renderInput={(params) => ( { if (e.key !== "Enter" || e.nativeEvent.isComposing) return; e.preventDefault(); onEnter && onEnter(e.target.value ?? ""); }} InputProps={{ ...params.InputProps, disableUnderline: true, style: { height: "100%" }, }} sx={{ background: "transparent !important", "& .MuiInputBase-input": { background: "#FAFAFA", color: "#6C757D", padding: "0 16px", fontSize: "14px", fontFamily: "inherit", }, }} className="!shadow-none !w-full !px-5 !h-full !text-[14px] md:!text-[16px] !min-w-[50%] !rounded-0 !font-normal" /> )} /> ); } export default AutoCompleteSearch;