1
- import { Autocomplete , CircularProgress , TextField } from '@mui/material' ;
1
+ import {
2
+ Autocomplete ,
3
+ CircularProgress ,
4
+ TextField ,
5
+ Tooltip ,
6
+ } from '@mui/material' ;
2
7
import { kebabize } from '@percona/utils' ;
3
8
import { Controller , useFormContext } from 'react-hook-form' ;
4
9
import { AutoCompleteInputProps } from './auto-complete.types' ;
@@ -14,59 +19,63 @@ function AutoCompleteInput<T>({
14
19
loading = false ,
15
20
isRequired = false ,
16
21
disabled = false ,
22
+ tooltipText,
17
23
onChange,
18
24
} : AutoCompleteInputProps < T > ) {
19
25
const { control : contextControl } = useFormContext ( ) ;
20
26
const { helperText, ...restTextFieldProps } = textFieldProps ;
21
27
const { sx, ...restAutocompleteProps } = autoCompleteProps ;
28
+
22
29
return (
23
30
< Controller
24
31
name = { name }
25
32
control = { control ?? contextControl }
26
33
render = { ( { field, fieldState : { error } } ) => (
27
- < Autocomplete
28
- { ...field }
29
- sx = { { mt : 3 , ...sx } }
30
- options = { options }
31
- forcePopupIcon
32
- disabled = { disabled }
33
- onChange = { ( _ , newValue ) => {
34
- field . onChange ( newValue ) ;
35
- if ( onChange ) {
36
- onChange ( ) ;
37
- }
38
- } }
39
- data-testid = { `${ kebabize ( name ) } -autocomplete` }
40
- // We might generalize this in the future, if we think renderInput should be defined from the outside
41
- renderInput = { ( params ) => (
42
- < TextField
43
- { ...params }
44
- error = { ! ! error }
45
- label = { label }
46
- helperText = { error ? error . message : helperText }
47
- inputProps = { {
48
- 'data-testid' : `text-input-${ kebabize ( name ) } ` ,
49
- ...params . inputProps ,
50
- ...textFieldProps ?. inputProps ,
51
- } }
52
- InputProps = { {
53
- ...params . InputProps ,
54
- endAdornment : (
55
- < >
56
- { loading ? (
57
- < CircularProgress color = "inherit" size = { 20 } />
58
- ) : null }
59
- { params . InputProps . endAdornment }
60
- </ >
61
- ) ,
62
- } }
63
- size = "small"
64
- required = { isRequired }
65
- { ...restTextFieldProps }
66
- />
67
- ) }
68
- { ...restAutocompleteProps }
69
- />
34
+ < Tooltip title = { tooltipText } placement = "top" arrow >
35
+ < Autocomplete
36
+ { ...field }
37
+ sx = { { mt : 3 , ...sx } }
38
+ options = { options }
39
+ forcePopupIcon
40
+ disabled = { disabled }
41
+ onChange = { ( _ , newValue ) => {
42
+ field . onChange ( newValue ) ;
43
+ if ( onChange ) {
44
+ onChange ( ) ;
45
+ }
46
+ } }
47
+ data-testid = { `${ kebabize ( name ) } -autocomplete` }
48
+ // We might generalize this in the future, if we think renderInput should be defined from the outside
49
+ renderInput = { ( params ) => (
50
+ < TextField
51
+ { ...params }
52
+ error = { ! ! error }
53
+ label = { label }
54
+ helperText = { error ? error . message : helperText }
55
+ inputProps = { {
56
+ 'data-testid' : `text-input-${ kebabize ( name ) } ` ,
57
+ ...params . inputProps ,
58
+ ...textFieldProps ?. inputProps ,
59
+ } }
60
+ InputProps = { {
61
+ ...params . InputProps ,
62
+ endAdornment : (
63
+ < >
64
+ { loading ? (
65
+ < CircularProgress color = "inherit" size = { 20 } />
66
+ ) : null }
67
+ { params . InputProps . endAdornment }
68
+ </ >
69
+ ) ,
70
+ } }
71
+ size = "small"
72
+ required = { isRequired }
73
+ { ...restTextFieldProps }
74
+ />
75
+ ) }
76
+ { ...restAutocompleteProps }
77
+ />
78
+ </ Tooltip >
70
79
) }
71
80
{ ...controllerProps }
72
81
/>
0 commit comments