This repository was archived by the owner on Mar 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +82
-3
lines changed Expand file tree Collapse file tree 4 files changed +82
-3
lines changed Original file line number Diff line number Diff line change @@ -24,11 +24,22 @@ const renderSuggestion = (suggestion) => (
24
24
/**
25
25
* Styles the input field for the suggestion input
26
26
* @param {Object } inputProps The input props
27
+ * @param {Function } reset resets the input
27
28
*/
28
- const renderInputComponent = ( inputProps ) => (
29
+ const renderInputComponent = ( inputProps , reset ) => (
29
30
< div className = { style . searchbox } >
30
31
< i className = { style . searchboxIcon } > </ i >
31
32
< input { ...inputProps } />
33
+ < span
34
+ className = {
35
+ inputProps . value . length > 0
36
+ ? `${ style . resetKeyword } `
37
+ : `${ style . resetKeyword } ${ style . resetKeywordHidden } `
38
+ }
39
+ onClick = { ( ) => reset ( ) }
40
+ >
41
+ ×
42
+ </ span >
32
43
</ div >
33
44
) ;
34
45
@@ -120,6 +131,10 @@ export default function SuggestionBox({
120
131
onChange,
121
132
} ;
122
133
134
+ const reset = ( ) => {
135
+ setValue ( "" ) ;
136
+ } ;
137
+
123
138
return (
124
139
< Autosuggest
125
140
suggestions = { suggestions }
@@ -130,7 +145,9 @@ export default function SuggestionBox({
130
145
renderSuggestion = { renderSuggestion }
131
146
inputProps = { inputProps }
132
147
theme = { style }
133
- renderInputComponent = { renderInputComponent }
148
+ renderInputComponent = { ( inputProps ) =>
149
+ renderInputComponent ( inputProps , reset )
150
+ }
134
151
/>
135
152
) ;
136
153
}
Original file line number Diff line number Diff line change 19
19
margin-left : 12px ;
20
20
margin-top : 1px ;
21
21
width : 100% ;
22
+ & ::-ms-clear {
23
+ display : none ;
24
+ height : 0 ;
25
+ width : 0 ;
26
+ }
22
27
}
23
28
24
29
.inputOpen {
91
96
width : 20px ;
92
97
height : 20px ;
93
98
}
99
+
100
+ .resetKeyword {
101
+ order : 2 ;
102
+ appearance : none ;
103
+ border : none ;
104
+ color : $textColor ;
105
+ cursor : pointer ;
106
+ font-size : 24px ;
107
+ outline : none ;
108
+
109
+ & :hover {
110
+ color : $red ;
111
+ }
112
+
113
+ & .resetKeywordHidden {
114
+ visibility : hidden ;
115
+ }
116
+ }
Original file line number Diff line number Diff line change 1
1
import React , { useState } from "react" ;
2
2
import PT from "prop-types" ;
3
- import styles from "./searchBox.module.css " ;
3
+ import styles from "./searchBox.module.scss " ;
4
4
5
5
/**
6
6
* Searchbox
@@ -26,6 +26,11 @@ export default function SearchBox({
26
26
}
27
27
} ;
28
28
29
+ const reset = ( ) => {
30
+ setQuery ( "" ) ;
31
+ onChange && onChange ( "" ) ;
32
+ } ;
33
+
29
34
return (
30
35
< div className = { styles . searchbox } >
31
36
< div className = { styles . searchboxItems } >
@@ -38,6 +43,16 @@ export default function SearchBox({
38
43
onChange = { handleChange }
39
44
disabled = { disabled }
40
45
/>
46
+ < span
47
+ className = {
48
+ query . length > 0
49
+ ? `${ styles . resetKeyword } `
50
+ : `${ styles . resetKeyword } ${ styles . resetKeywordHidden } `
51
+ }
52
+ onClick = { ( ) => reset ( ) }
53
+ >
54
+ ×
55
+ </ span >
41
56
</ div >
42
57
</ div >
43
58
) ;
Original file line number Diff line number Diff line change 1
1
/* importing colors */
2
+ @import " ../../styles/mixins" ;
2
3
@value colors: "../../styles/colors.module .css";
3
4
@value lightGray from colors;
4
5
47
48
48
49
font-family : Helvetica ;
49
50
font-size : 16px ;
51
+ & ::-ms-clear {
52
+ display : none ;
53
+ height : 0 ;
54
+ width : 0 ;
55
+ }
50
56
}
51
57
52
58
.searchboxInput :focus ,
53
59
.searchboxInput :focus ,
54
60
.searchboxInput :focus {
55
61
outline : none ;
56
62
}
63
+
64
+ .resetKeyword {
65
+ order : 2 ;
66
+ appearance : none ;
67
+ border : none ;
68
+ color : $textColor ;
69
+ cursor : pointer ;
70
+ font-size : 24px ;
71
+ outline : none ;
72
+
73
+ & :hover {
74
+ color : $red ;
75
+ }
76
+
77
+ & .resetKeywordHidden {
78
+ visibility : hidden ;
79
+ }
80
+ }
You can’t perform that action at this time.
0 commit comments