@@ -3,14 +3,14 @@ import Fade from "@material-ui/core/Fade"
3
3
import InputAdornment from "@material-ui/core/InputAdornment"
4
4
import Menu from "@material-ui/core/Menu"
5
5
import MenuItem from "@material-ui/core/MenuItem"
6
+ import OutlinedInput from "@material-ui/core/OutlinedInput"
6
7
import { makeStyles } from "@material-ui/core/styles"
7
- import TextField from "@material-ui/core/TextField "
8
+ import { Theme } from "@material-ui/core/styles/createMuiTheme "
8
9
import SearchIcon from "@material-ui/icons/Search"
9
10
import { FormikErrors , useFormik } from "formik"
10
11
import debounce from "just-debounce-it"
11
12
import { useCallback , useEffect , useState } from "react"
12
13
import { getValidationErrorMessage } from "../../api/errors"
13
- import { getFormHelpers } from "../../util/formUtils"
14
14
import { CloseDropdown , OpenDropdown } from "../DropdownArrows/DropdownArrows"
15
15
import { Stack } from "../Stack/Stack"
16
16
@@ -42,7 +42,7 @@ export const SearchBarWithFilter: React.FC<SearchBarWithFilterProps> = ({
42
42
presetFilters,
43
43
error,
44
44
} ) => {
45
- const styles = useStyles ( )
45
+ const styles = useStyles ( { error } )
46
46
47
47
const form = useFormik < FilterFormValues > ( {
48
48
enableReinitialize : true ,
@@ -71,8 +71,6 @@ export const SearchBarWithFilter: React.FC<SearchBarWithFilterProps> = ({
71
71
return ( ) => debouncedOnFilter . cancel ( )
72
72
} , [ debouncedOnFilter , form . values . query ] )
73
73
74
- const getFieldHelpers = getFormHelpers < FilterFormValues > ( form )
75
-
76
74
const [ anchorEl , setAnchorEl ] = useState < null | HTMLElement > ( null )
77
75
78
76
const handleClick = ( event : React . MouseEvent < HTMLButtonElement > ) => {
@@ -93,7 +91,7 @@ export const SearchBarWithFilter: React.FC<SearchBarWithFilterProps> = ({
93
91
94
92
return (
95
93
< Stack spacing = { 1 } className = { styles . root } >
96
- < Stack direction = "row" spacing = { 0 } className = { styles . filterContainer } >
94
+ < Stack direction = "row" spacing = { 0 } >
97
95
{ presetFilters && presetFilters . length > 0 && (
98
96
< Button
99
97
aria-controls = "filter-menu"
@@ -106,19 +104,18 @@ export const SearchBarWithFilter: React.FC<SearchBarWithFilterProps> = ({
106
104
) }
107
105
108
106
< form onSubmit = { form . handleSubmit } className = { styles . filterForm } >
109
- < TextField
110
- { ...getFieldHelpers ( "query" ) }
111
- className = { styles . textFieldRoot }
107
+ < OutlinedInput
108
+ id = "query"
109
+ name = "query"
110
+ value = { form . values . query }
111
+ error = { ! ! error }
112
+ className = { styles . inputStyles }
112
113
onChange = { form . handleChange }
113
- fullWidth
114
- variant = "outlined"
115
- InputProps = { {
116
- startAdornment : (
117
- < InputAdornment position = "start" >
118
- < SearchIcon fontSize = "small" />
119
- </ InputAdornment >
120
- ) ,
121
- } }
114
+ startAdornment = {
115
+ < InputAdornment position = "start" >
116
+ < SearchIcon fontSize = "small" />
117
+ </ InputAdornment >
118
+ }
122
119
/>
123
120
</ form >
124
121
@@ -152,29 +149,39 @@ export const SearchBarWithFilter: React.FC<SearchBarWithFilterProps> = ({
152
149
)
153
150
}
154
151
155
- const useStyles = makeStyles ( ( theme ) => ( {
152
+ interface StyleProps {
153
+ error ?: unknown
154
+ }
155
+
156
+ const useStyles = makeStyles < Theme , StyleProps > ( ( theme ) => ( {
156
157
root : {
157
158
marginBottom : theme . spacing ( 2 ) ,
158
159
} ,
159
- filterContainer : {
160
- border : `1px solid ${ theme . palette . divider } ` ,
161
- borderRadius : theme . shape . borderRadius ,
162
- } ,
160
+ // necessary to expand the textField
161
+ // the length of the page (within the bordered filterContainer)
163
162
filterForm : {
164
163
width : "100%" ,
165
164
} ,
166
165
buttonRoot : {
167
- border : "none" ,
168
- borderRight : `1px solid ${ theme . palette . divider } ` ,
166
+ border : `1px solid ${ theme . palette . divider } ` ,
167
+ borderRight : "0px" ,
169
168
borderRadius : `${ theme . shape . borderRadius } px 0px 0px ${ theme . shape . borderRadius } px` ,
170
169
} ,
171
- textFieldRoot : {
172
- margin : "0px" ,
173
- "& fieldset" : {
174
- border : "none" ,
175
- } ,
176
- } ,
177
170
errorRoot : {
178
171
color : theme . palette . error . dark ,
179
172
} ,
173
+ inputStyles : {
174
+ height : "100%" ,
175
+ width : "100%" ,
176
+ borderRadius : `0px ${ theme . shape . borderRadius } px ${ theme . shape . borderRadius } px 0px` ,
177
+ color : theme . palette . primary . contrastText ,
178
+ backgroundColor : theme . palette . background . paper ,
179
+
180
+ "& fieldset" : {
181
+ borderColor : theme . palette . divider ,
182
+ "&MuiOutlinedInput-root:hover, &MuiOutlinedInput-notchedOutline" : {
183
+ borderColor : ( props ) => props . error && theme . palette . error . contrastText ,
184
+ } ,
185
+ } ,
186
+ } ,
180
187
} ) )
0 commit comments