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.

62 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. setInputValue(newValue);
  27. if(onInputChange){
  28. onInputChange(event,newValue, setInputValue)
  29. }
  30. }}
  31. onChange={(event, newValue) => {
  32. setValue(newValue);
  33. if (!onChange){
  34. form.setFieldValue(valueName, newValue);
  35. }else{
  36. onChange(event, newValue);
  37. }
  38. }}
  39. sx={{
  40. "& .MuiInputBase-root": {
  41. height: "41px",
  42. padding: "0px 0px 0px 8px"
  43. },
  44. "& .MuiAutocomplete-endAdornment": {
  45. top: "auto"
  46. },
  47. "& .MuiInputBase-input.Mui-disabled": {
  48. WebkitTextFillColor: "#000000",
  49. background: "#f8f8f8",
  50. },
  51. }}
  52. renderInput={(params) => <TextField {...params} sx={{
  53. "& .MuiInputBase-input.Mui-disabled": {
  54. WebkitTextFillColor: "#000000",
  55. background: "#f8f8f8",
  56. },
  57. }}/>}
  58. />
  59. );
  60. }