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

Commit 0798c13

Browse files
Merge pull request #603 from cagdas001/develop
feat(search-boxes): add clear button for inputs
2 parents 555312e + 503cc12 commit 0798c13

File tree

6 files changed

+139
-3
lines changed

6 files changed

+139
-3
lines changed

client/src/components/AddToGroupModal/index.jsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ export default function AddToGroupModal({ onCancel, updateUser, user }) {
155155
setCreatingGroup(false);
156156
};
157157

158+
const reset = () => {
159+
setFilter("");
160+
};
161+
158162
return (
159163
<Modal
160164
onCancel={onCancel}
@@ -175,6 +179,16 @@ export default function AddToGroupModal({ onCancel, updateUser, user }) {
175179
value={filter}
176180
disabled={loadingGroups}
177181
/>
182+
<span
183+
className={
184+
filter.length > 0
185+
? `${style.resetKeyword}`
186+
: `${style.resetKeyword} ${style.resetKeywordHidden}`
187+
}
188+
onClick={() => reset()}
189+
>
190+
&times;
191+
</span>
178192
<Button
179193
className={style.createButton}
180194
onClick={createGroup}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@
6363
&::placeholder {
6464
opacity: 0.5;
6565
}
66+
67+
&::-ms-clear {
68+
display: none;
69+
height: 0;
70+
width: 0;
71+
}
6672
}
6773

6874
.searchRow {
@@ -92,3 +98,24 @@
9298
font: 400 12pt/1.25 Inter;
9399
margin-left: 30px;
94100
}
101+
102+
.resetKeyword {
103+
position: absolute;
104+
left: 67.5%;
105+
top: 10px;
106+
appearance: none;
107+
border: none;
108+
color: $textColor;
109+
cursor: pointer;
110+
font-size: 24px;
111+
font-family: Arial;
112+
outline: none;
113+
114+
&:hover {
115+
color: $red;
116+
}
117+
118+
&.resetKeywordHidden {
119+
visibility: hidden;
120+
}
121+
}

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: 31 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,29 @@
9196
width: 20px;
9297
height: 20px;
9398
}
99+
100+
// firefox solution to vertically align .resetKeyword
101+
@supports (-moz-appearance: none) {
102+
.resetKeyword {
103+
align-self: center;
104+
}
105+
}
106+
107+
.resetKeyword {
108+
order: 2;
109+
appearance: none;
110+
border: none;
111+
color: $textColor;
112+
cursor: pointer;
113+
font-size: 24px;
114+
font-family: Arial;
115+
outline: none;
116+
117+
&:hover {
118+
color: $red;
119+
}
120+
121+
&.resetKeywordHidden {
122+
visibility: hidden;
123+
}
124+
}

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: 32 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,41 @@
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+
// firefox solution to vertically align .resetKeyword
65+
@supports (-moz-appearance: none) {
66+
.resetKeyword {
67+
align-self: center;
68+
}
69+
}
70+
71+
.resetKeyword {
72+
order: 2;
73+
appearance: none;
74+
border: none;
75+
color: $textColor;
76+
cursor: pointer;
77+
font-size: 24px;
78+
font-family: Arial;
79+
outline: none;
80+
81+
&:hover {
82+
color: $red;
83+
}
84+
85+
&.resetKeywordHidden {
86+
visibility: hidden;
87+
}
88+
}

0 commit comments

Comments
 (0)