You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

63 lines
2.1 KiB

  1. import {
  2. Autocomplete, TextField
  3. } from '@mui/material';
  4. import { useState } from 'react';
  5. export default function Combo ({valueName, disabled, form, dataList, filterOptions, getOptionLabel, isOptionEqualToValue, onInputChange, onChange, ...props}){
  6. const [value, setValue] = useState(form.values[valueName]);
  7. const [inputValue, setInputValue] = useState("");
  8. return (
  9. <Autocomplete
  10. {...props}
  11. disablePortal
  12. fullWidth
  13. id={valueName}
  14. name={valueName}
  15. disabled={disabled}
  16. value={value}
  17. inputValue={inputValue}
  18. filterOptions={filterOptions}
  19. options={dataList}
  20. getOptionLabel={getOptionLabel}
  21. isOptionEqualToValue={(option, newValue)=>{
  22. if(isOptionEqualToValue)
  23. isOptionEqualToValue(option,newValue, setValue,setInputValue )
  24. }}
  25. onInputChange={(event, newValue) => {
  26. if(onInputChange){
  27. onInputChange(event,newValue, setInputValue)
  28. } else {
  29. setInputValue(newValue);
  30. }
  31. }}
  32. onChange={(event, newValue) => {
  33. setValue(newValue);
  34. if (!onChange){
  35. form.setFieldValue(valueName, newValue);
  36. }else{
  37. onChange(event, newValue);
  38. }
  39. }}
  40. sx={{
  41. "& .MuiInputBase-root": {
  42. height: "41px",
  43. padding: "0px 0px 0px 8px"
  44. },
  45. "& .MuiAutocomplete-endAdornment": {
  46. top: "auto"
  47. },
  48. "& .MuiInputBase-input.Mui-disabled": {
  49. WebkitTextFillColor: "#000000",
  50. background: "#f8f8f8",
  51. },
  52. }}
  53. renderInput={(params) => <TextField {...params} sx={{
  54. "& .MuiInputBase-input.Mui-disabled": {
  55. WebkitTextFillColor: "#000000",
  56. background: "#f8f8f8",
  57. },
  58. }}/>}
  59. />
  60. );
  61. }