Skip to content

Commit 458521e

Browse files
committed
Add button resetAll and open/close icon
1 parent 4a32689 commit 458521e

File tree

6 files changed

+101
-33
lines changed

6 files changed

+101
-33
lines changed

example/MultiSelect/MultiSelect.css

+52-6
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,35 @@
1414
min-width: 400px;
1515
max-width: 700px;
1616
padding: 2px 5px;
17+
background-color: #fff;
18+
}
19+
20+
.inner-wrapper {
21+
position: relative;
22+
width: 100%;
23+
padding-right: 40px;
1724
display: flex;
1825
flex-wrap: wrap;
19-
background-color: #fff;
26+
}
27+
28+
.inner-wrapper::before {
29+
content: '';
30+
position: absolute;
31+
top: 50%;
32+
right: 0;
33+
transform: translate(0, -50%) rotate(0deg);
34+
display: block;
35+
width: 16px;
36+
height: 16px;
37+
background-image: url('./img/chevron-down.svg');
38+
background-size: cover;
39+
background-position: center;
40+
background-repeat: no-repeat;
41+
transition: 0.3s ease-in-out;
42+
}
43+
44+
.inner-wrapper-open::before {
45+
transform: translate(0, -50%) rotate(180deg);
2046
}
2147

2248
.input {
@@ -43,21 +69,21 @@
4369
}
4470

4571
.item.selected::after {
46-
content: "";
72+
content: '';
4773
position: absolute;
4874
top: 5px;
4975
right: 5px;
5076
width: 10px;
5177
height: 10px;
52-
background-image: url("./check.svg");
78+
background-image: url('./img/check.svg');
5379
background-repeat: no-repeat;
5480
}
5581

5682
.multivalue {
5783
display: flex;
5884
justify-content: space-between;
5985
margin: 2px;
60-
padding: 5px 10px;
86+
padding: 2px 10px;
6187
padding-right: 5px;
6288
border: 1px solid #413d51;
6389
border-radius: 15px;
@@ -72,13 +98,33 @@
7298
border: none;
7399
border-radius: 50%;
74100
background-color: transparent;
75-
background-image: url("./close.svg");
101+
background-image: url('./img/close.svg');
76102
background-size: 10px 10px;
77-
background-position: center center;
103+
background-position: center;
78104
background-repeat: no-repeat;
79105
}
80106

81107
.remove:hover {
82108
outline: 1px solid #413d51;
83109
cursor: pointer;
84110
}
111+
112+
.reset {
113+
position: absolute;
114+
top: 50%;
115+
right: 20px;
116+
width: 16px;
117+
height: 16px;
118+
border: none;
119+
cursor: pointer;
120+
background-image: url('./img/x-circle.svg');
121+
background-position: center center;
122+
background-repeat: no-repeat;
123+
background-color: transparent;
124+
transform: translate(0, -50%);
125+
}
126+
127+
.reset:hover,
128+
.reset:focus {
129+
opacity: 0.5;
130+
}

example/MultiSelect/MultiSelect.tsx

+43-27
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ export const Dropdown: React.FC<Props> = ({ onSelect, values }) => {
103103
}
104104
};
105105

106+
const handleResetClick = (event) => {
107+
event.stopPropagation();
108+
onSelect([]);
109+
};
110+
106111
const handleRemoveClick = (item: Item) => (event) => {
107112
event.stopPropagation();
108113
const newArr = values.filter((el) => el.value !== item.value);
@@ -126,33 +131,44 @@ export const Dropdown: React.FC<Props> = ({ onSelect, values }) => {
126131
onFocus={handleFocus}
127132
onBlur={handleBlur}
128133
>
129-
{values.length === 0
130-
? null
131-
: values.map((item: Item) => {
132-
return (
133-
<div className="multivalue" key={item.value}>
134-
<span className="multivalue-name">{item.name}</span>
135-
<button
136-
type="button"
137-
className="remove"
138-
onClick={handleRemoveClick(item)}
139-
tabIndex={isFocused ? 0 : -1}
140-
aria-label={`Remove value ${item.name}`}
141-
></button>
142-
</div>
143-
);
144-
})}
145-
146-
<input
147-
className="input"
148-
type="text"
149-
id="input"
150-
{...getInputProps()}
151-
placeholder="Select city"
152-
value={inputValue}
153-
onChange={handleChange}
154-
autoComplete="off"
155-
/>
134+
<div className={classNames('inner-wrapper', { 'inner-wrapper-open': isOpen })}>
135+
{values.length === 0
136+
? null
137+
: values.map((item: Item) => {
138+
return (
139+
<div className="multivalue" key={item.value}>
140+
<span className="multivalue-name">{item.name}</span>
141+
<button
142+
type="button"
143+
className="remove"
144+
onClick={handleRemoveClick(item)}
145+
tabIndex={isFocused ? 0 : -1}
146+
aria-label={`Remove value ${item.name}`}
147+
></button>
148+
</div>
149+
);
150+
})}
151+
152+
<input
153+
className="input"
154+
type="text"
155+
id="input"
156+
{...getInputProps()}
157+
placeholder="Select city"
158+
value={inputValue}
159+
onChange={handleChange}
160+
autoComplete="off"
161+
/>
162+
163+
{values.length === 0 ? null : (
164+
<button
165+
className="reset"
166+
onClick={handleResetClick}
167+
type="button"
168+
aria-label="Clear all values"
169+
></button>
170+
)}
171+
</div>
156172

157173
{isOpen && (
158174
<ul className="menu" {...(getMenuProps() as any)}>
File renamed without changes.
+3
Loading
File renamed without changes.

example/MultiSelect/img/x-circle.svg

+3
Loading

0 commit comments

Comments
 (0)