@@ -23,6 +23,35 @@ const isKeyboardSelectionEvent = event => {
2323 return true ;
2424} ;
2525
26+ /**
27+ * @typedef MobileViewProps
28+ * @property {string } appElement
29+ * @property {string } id
30+ * @property {string } placeholder
31+ * @property {function } closeHandle
32+ * @property {function } clearInput
33+ * @property {array } suggestions
34+ * @property {function } onSelectedItemChange
35+ * @property {object } fontWeights
36+ * @property {function } clearOldSearches
37+ * @property {object } itemProps
38+ * @property {string } color
39+ * @property {string } accessiblePrimaryColor
40+ * @property {string } hoverColor
41+ * @property {string } lng
42+ * @property {object } ariaProps
43+ * @property {boolean } renderMobile
44+ * @property {string } clearButtonColor
45+ * @property {string } inputValue
46+ * @property {function } setInputValue
47+ * @property {string } inputClassName
48+ * @property {boolean } required
49+ * @property {string } [mobileLabel]
50+ * @property {boolean } [showScroll]
51+ *
52+ * @param {MobileViewProps } props
53+ * @returns {JSX.Element }
54+ */
2655const MobileView = ( {
2756 appElement,
2857 id,
@@ -51,12 +80,11 @@ const MobileView = ({
5180 const [ t ] = useTranslation ( ) ;
5281 const { lock, unlock } = hooks . useScrollLock ( ) ;
5382 const styles = showScroll ? mobileStyles : mobileNoScrollStyles ;
54-
5583 const inputId = `${ id } -input` ;
5684 const labelId = `${ id } -label` ;
57-
5885 const [ isDialogOpen , setDialogOpen ] = useState ( false ) ;
5986 const inputRef = React . useRef ( ) ;
87+
6088 useEffect ( ( ) => {
6189 ReactModal . setAppElement ( appElement ) ;
6290 } , [ ] ) ;
@@ -70,7 +98,7 @@ const MobileView = ({
7098 } , [ renderMobile ] ) ;
7199
72100 /**
73- * Downshift hooks do not support conditional rendering so we need independent hooks in mobile view.
101+ * independent hooks in mobile view.
74102 * inputValue and suggestion states are kept in the parent
75103 */
76104 const {
@@ -84,8 +112,9 @@ const MobileView = ({
84112 inputValue,
85113 onInputValueChange : ( { inputValue : newValue } ) => setInputValue ( newValue ) ,
86114 onSelectedItemChange,
87- defaultHighlightedIndex : 0 ,
115+ defaultHighlightedIndex : - 1 ,
88116 } ) ;
117+ // call to suppress ref errors from downshift, might need better solution
89118 getLabelProps ( { } , { suppressRefError : true } ) ;
90119 getMenuProps ( { } , { suppressRefError : true } ) ;
91120 getInputProps ( { } , { suppressRefError : true } ) ;
@@ -103,7 +132,6 @@ const MobileView = ({
103132 . concat ( SearchBarId )
104133 . concat ( ' ' )
105134 . concat ( ariaCurrentSuggestion ) ;
106-
107135 return (
108136 < ReactModal
109137 isOpen = { renderMobile }
@@ -138,7 +166,7 @@ const MobileView = ({
138166 id = { labelId }
139167 { ...getLabelProps ( ) }
140168 >
141- { mobileLabel || t ( id , { lng } ) }
169+ { mobileLabel }
142170 </ span >
143171 < Input
144172 placeholder = {
@@ -200,46 +228,35 @@ const MobileView = ({
200228} ;
201229
202230MobileView . propTypes = {
203- lng : PropTypes . string . isRequired ,
204- color : PropTypes . string ,
231+ appElement : PropTypes . string . isRequired ,
232+ id : PropTypes . string . isRequired ,
205233 clearInput : PropTypes . func . isRequired ,
234+ clearOldSearches : PropTypes . func . isRequired ,
235+ closeHandle : PropTypes . func . isRequired ,
236+ onSelectedItemChange : PropTypes . func . isRequired ,
237+ inputValue : PropTypes . string . isRequired ,
238+ setInputValue : PropTypes . func . isRequired ,
239+ color : PropTypes . string . isRequired ,
206240 accessiblePrimaryColor : PropTypes . string . isRequired ,
207- hoverColor : PropTypes . string ,
241+ clearButtonColor : PropTypes . string . isRequired ,
242+ hoverColor : PropTypes . string . isRequired ,
208243 fontWeights : PropTypes . shape ( {
209- normal : PropTypes . number ,
210- medium : PropTypes . number ,
211- bold : PropTypes . number ,
244+ medium : PropTypes . number . isRequired ,
212245 } ) . isRequired ,
213- appElement : PropTypes . string . isRequired ,
214- id : PropTypes . string . isRequired ,
215- mobileLabel : PropTypes . string ,
216- clearOldSearches : PropTypes . func . isRequired ,
217246 itemProps : PropTypes . shape ( { } ) . isRequired ,
218247 suggestions : PropTypes . arrayOf ( PropTypes . shape ( { } ) ) . isRequired ,
219- closeHandle : PropTypes . func . isRequired ,
220- showScroll : PropTypes . bool ,
221- focusInput : PropTypes . bool ,
222- clearButtonColor : PropTypes . string . isRequired ,
223- onSelectedItemChange : PropTypes . func . isRequired ,
224248 ariaProps : PropTypes . shape ( {
225249 ariaRequiredText : PropTypes . string . isRequired ,
226250 SearchBarId : PropTypes . string . isRequired ,
227251 ariaCurrentSuggestion : PropTypes . string . isRequired ,
228252 } ) . isRequired ,
229- placeholder : PropTypes . string . isRequired ,
230- inputValue : PropTypes . string . isRequired ,
231- setInputValue : PropTypes . func . isRequired ,
232- renderMobile : PropTypes . bool . isRequired ,
233253 inputClassName : PropTypes . string . isRequired ,
254+ placeholder : PropTypes . string . isRequired ,
255+ mobileLabel : PropTypes . string . isRequired ,
234256 required : PropTypes . bool . isRequired ,
235- } ;
236-
237- MobileView . defaultProps = {
238- mobileLabel : undefined ,
239- focusInput : false ,
240- color : undefined ,
241- hoverColor : undefined ,
242- showScroll : undefined ,
257+ renderMobile : PropTypes . bool . isRequired ,
258+ showScroll : PropTypes . bool . isRequired ,
259+ lng : PropTypes . string . isRequired ,
243260} ;
244261
245262export default MobileView ;
0 commit comments