Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 0989a97

Browse files
committed
feat(search-boxes): add clear button for inputs
Add clear/reset button for the searchBox component input. Add clear/reset button for the SuggestionBox component input. Addresses #161
1 parent ceb0097 commit 0989a97

File tree

4 files changed

+82
-3
lines changed

4 files changed

+82
-3
lines changed

client/src/components/SuggestionBox/index.jsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,22 @@ const renderSuggestion = (suggestion) => (
2424
/**
2525
* Styles the input field for the suggestion input
2626
* @param {Object} inputProps The input props
27+
* @param {Function} reset resets the input
2728
*/
28-
const renderInputComponent = (inputProps) => (
29+
const renderInputComponent = (inputProps, reset) => (
2930
<div className={style.searchbox}>
3031
<i className={style.searchboxIcon}></i>
3132
<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+
&times;
42+
</span>
3243
</div>
3344
);
3445

@@ -120,6 +131,10 @@ export default function SuggestionBox({
120131
onChange,
121132
};
122133

134+
const reset = () => {
135+
setValue("");
136+
};
137+
123138
return (
124139
<Autosuggest
125140
suggestions={suggestions}
@@ -130,7 +145,9 @@ export default function SuggestionBox({
130145
renderSuggestion={renderSuggestion}
131146
inputProps={inputProps}
132147
theme={style}
133-
renderInputComponent={renderInputComponent}
148+
renderInputComponent={(inputProps) =>
149+
renderInputComponent(inputProps, reset)
150+
}
134151
/>
135152
);
136153
}

client/src/components/SuggestionBox/style.module.scss

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
margin-left: 12px;
2020
margin-top: 1px;
2121
width: 100%;
22+
&::-ms-clear {
23+
display: none;
24+
height: 0;
25+
width: 0;
26+
}
2227
}
2328

2429
.inputOpen {
@@ -91,3 +96,21 @@
9196
width: 20px;
9297
height: 20px;
9398
}
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+
}

client/src/components/searchBox/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from "react";
22
import PT from "prop-types";
3-
import styles from "./searchBox.module.css";
3+
import styles from "./searchBox.module.scss";
44

55
/**
66
* Searchbox
@@ -26,6 +26,11 @@ export default function SearchBox({
2626
}
2727
};
2828

29+
const reset = () => {
30+
setQuery("");
31+
onChange && onChange("");
32+
};
33+
2934
return (
3035
<div className={styles.searchbox}>
3136
<div className={styles.searchboxItems}>
@@ -38,6 +43,16 @@ export default function SearchBox({
3843
onChange={handleChange}
3944
disabled={disabled}
4045
/>
46+
<span
47+
className={
48+
query.length > 0
49+
? `${styles.resetKeyword}`
50+
: `${styles.resetKeyword} ${styles.resetKeywordHidden}`
51+
}
52+
onClick={() => reset()}
53+
>
54+
&times;
55+
</span>
4156
</div>
4257
</div>
4358
);

client/src/components/searchBox/searchBox.module.css renamed to client/src/components/searchBox/searchBox.module.scss

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* importing colors */
2+
@import "../../styles/mixins";
23
@value colors: "../../styles/colors.module.css";
34
@value lightGray from colors;
45

@@ -47,10 +48,33 @@
4748

4849
font-family: Helvetica;
4950
font-size: 16px;
51+
&::-ms-clear {
52+
display: none;
53+
height: 0;
54+
width: 0;
55+
}
5056
}
5157

5258
.searchboxInput:focus,
5359
.searchboxInput:focus,
5460
.searchboxInput:focus {
5561
outline: none;
5662
}
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+
}

0 commit comments

Comments
 (0)