1
1
import _ from 'lodash' ;
2
- import React from 'react' ;
2
+ import React , { useRef , useEffect } from 'react' ;
3
3
import { useIntl } from 'react-intl' ;
4
4
import { useSelector } from 'react-redux' ;
5
5
import styled , { withTheme } from 'styled-components' ;
6
+ import { useQueryParamState } from '../hooks/useQueryParamState' ;
6
7
7
8
import { MagnifyGlassIcon , MagnifyGlassIconWhite } from '../icons' ;
8
9
@@ -89,7 +90,10 @@ const ButtonSearchText = styled('p')`
89
90
align-items: center;
90
91
font-size: 1rem;
91
92
width: 3.125rem;
92
- color: ${ props => ( props . usePrimaryButton ? props . theme . colors . default . onButton : props . theme . colors . default . onSurface ) } ;
93
+ color: ${ props =>
94
+ props . usePrimaryButton
95
+ ? props . theme . colors . default . onButton
96
+ : props . theme . colors . default . onSurface } ;
93
97
box-sizing: border-box;
94
98
` ;
95
99
@@ -104,11 +108,23 @@ const SearchInput = withTheme(
104
108
disabled = false ,
105
109
} ) => {
106
110
const intl = useIntl ( ) ;
111
+ const ref = useRef ( ) ;
107
112
const appStore = useSelector ( state => state . app ) ;
113
+ const [ searchQuery ] = useQueryParamState ( 'search' ) ;
114
+
115
+ useEffect ( ( ) => {
116
+ onChange ( {
117
+ target : {
118
+ value : searchQuery ,
119
+ } ,
120
+ } ) ;
121
+ ref . current . value = searchQuery ;
122
+ } , [ searchQuery ] ) ;
108
123
109
124
return (
110
125
< SearchContainer usePrimaryButton = { usePrimaryButton } size = { size } >
111
126
< Input
127
+ ref = { ref }
112
128
type = "text"
113
129
selectedTheme = { appStore . theme }
114
130
placeholder = { intl . formatMessage ( { id : 'search' } ) }
@@ -124,7 +140,8 @@ const SearchInput = withTheme(
124
140
selectedTheme = { appStore . theme }
125
141
usePrimaryButton = { usePrimaryButton }
126
142
buttonText = { buttonText }
127
- disabled = { disabled } >
143
+ disabled = { disabled }
144
+ >
128
145
{ ( buttonText && (
129
146
< ButtonSearchText usePrimaryButton = { usePrimaryButton } >
130
147
{ buttonText }
0 commit comments