Skip to content

Commit 23a7d1a

Browse files
authored
fix(multiselect): update multiselect design and fix minor bugs (#296)
* fix(multiselect): update option height and icon #287 * fix(multiselect): fix chip design and update icon * fix(multiselect): bug fix on selecting items * refactor(multiselect): remove dead code * fix(multiselect): update multiselect design * fix(multiselect): update selected chip animation
1 parent 99500c8 commit 23a7d1a

File tree

3 files changed

+46
-84
lines changed

3 files changed

+46
-84
lines changed

lib/globals/animations.module.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@
1313
}
1414
}
1515

16+
@mixin zoomIn() {
17+
-o-animation-name: animateZoom;
18+
-moz-animation-name: animateZoom;
19+
-webkit-animation-name: animateZoom;
20+
animation-name: animateZoom;
21+
@keyframes animateZoom {
22+
0% {
23+
transform: scale(0.1);
24+
}
25+
100% {
26+
transform: scale(1);
27+
}
28+
}
29+
}
30+
1631
@mixin sectionEntry($duration) {
1732
visibility: hidden;
1833
opacity: 0;

lib/multiselect/index.js

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import ReactDOM from 'react-dom';
33
import PropTypes from 'prop-types';
44
import cx from 'classnames';
55
import { themr } from 'react-css-themr';
6+
import { FaChevronDown } from 'react-icons/fa';
7+
import { MdClose } from 'react-icons/md';
68
import defaultTheme from './theme.module.scss';
79

810
const { findDOMNode: findNode } = ReactDOM;
@@ -17,7 +19,6 @@ class MultiSelect extends Component {
1719
*/
1820
selected: [],
1921
open: false,
20-
input: '',
2122
};
2223

2324
this.listRef = null;
@@ -31,12 +32,6 @@ class MultiSelect extends Component {
3132
return { threshold, focusedItem };
3233
};
3334

34-
handleInput = ({ target }) => {
35-
this.setState({
36-
input: target.value,
37-
});
38-
};
39-
4035
// Handle the click event when user selects / clicks on an option from the dropdown.
4136
handleSelect = (selectedOption) => {
4237
const { onSelect } = this.props;
@@ -65,12 +60,7 @@ class MultiSelect extends Component {
6560
handleKeyPress = (e) => {
6661
e.preventDefault();
6762
const { options } = this.props;
68-
const { input, selected, focus } = this.state;
69-
const isValid = options
70-
.filter(opt => opt
71-
.label
72-
.toLowerCase()
73-
.indexOf(input.toLowerCase()) !== -1);
63+
const { focus } = this.state;
7464
switch (e.key) {
7565
case 'ArrowDown':
7666
this.setState(
@@ -118,22 +108,7 @@ class MultiSelect extends Component {
118108
);
119109
break;
120110
case 'Enter':
121-
if (focus) {
122-
this.handleSelect(options[focus]);
123-
break;
124-
}
125-
if (isValid.length) {
126-
if (
127-
!selected.filter(item => item.label === isValid[0].label).length
128-
) {
129-
this.setState({
130-
selected: [...selected, isValid[0]],
131-
});
132-
}
133-
}
134-
this.setState({
135-
input: '',
136-
});
111+
this.handleSelect(options[focus]);
137112
break;
138113
default:
139114
break;
@@ -204,18 +179,8 @@ class MultiSelect extends Component {
204179
// Helper function to render options inside the dropdown.
205180
renderOptions = (options) => {
206181
const { theme } = this.props;
207-
const { selected, input, focus } = this.state;
208-
let filteredOptions;
209-
if (input.length) {
210-
filteredOptions = options
211-
.filter(opt => opt
212-
.label
213-
.toLowerCase()
214-
.indexOf(input.toLowerCase()) !== -1);
215-
} else {
216-
filteredOptions = options;
217-
}
218-
return filteredOptions.map((option, index) => {
182+
const { selected, focus } = this.state;
183+
return options.map((option, index) => {
219184
/* eslint-disable jsx-a11y/click-events-have-key-events */
220185
/* eslint-disable jsx-a11y/no-static-element-interactions */
221186
const itemtheme = cx(
@@ -259,7 +224,7 @@ class MultiSelect extends Component {
259224
>
260225
<div>
261226
<span>{option.label}</span>
262-
<div
227+
<MdClose
263228
className={theme.close}
264229
onClick={e => this.removeOption(e, option)}
265230
/>
@@ -290,7 +255,7 @@ class MultiSelect extends Component {
290255
<div id="selected-options" className={theme.selectedInput}>
291256
{this.renderSelected()}
292257
</div>
293-
<div className={cx(theme.arrow, open ? theme.up : theme.down)} />
258+
<FaChevronDown className={cx(theme.arrow, open ? theme.up : theme.down)} />
294259
</div>
295260
{open && (
296261
<div

lib/multiselect/theme.module.scss

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@
3535
display: inline-flex;
3636
box-sizing: border-box;
3737
width: 100%;
38-
padding: 2% 5% 0%;
38+
padding: 5%;
3939
cursor: pointer;
4040
outline: none;
4141
min-height: fit-content;
4242
min-height: -moz-fit-content;
4343
&:hover {
44-
background: rgba(71, 233, 243, 0.2);
44+
background: #c4dfe6;
45+
color: #6c757d;
4546
}
4647
&>span {
4748
white-space: nowrap;
@@ -51,7 +52,8 @@
5152
}
5253

5354
:local(.item-hover) {
54-
background: rgba(71, 233, 243, 0.2);
55+
background: #c4dfe6 !important;
56+
color: #6c757d !important;
5557
}
5658

5759
:local(.show) {
@@ -77,27 +79,9 @@
7779
}
7880

7981
:local(.close) {
80-
height: 20px;
81-
width: 20px;
82-
display: flex;
83-
align-self: center;
84-
justify-content: center;
85-
align-items: center;
8682
cursor: pointer;
87-
&:before,
88-
&:after {
89-
position: absolute;
90-
content: "";
91-
z-index: 2;
92-
border-left: 2px solid #aaa;
93-
height: 10px;
94-
}
95-
&:before {
96-
transform: rotate(45deg);
97-
}
98-
&:after {
99-
transform: rotate(-45deg);
100-
}
83+
align-self: center;
84+
padding-left: 0.25em;
10185
}
10286

10387
:local(.selectInputWrapper) {
@@ -111,18 +95,20 @@
11195
}
11296

11397
:local(.selected) {
114-
min-width: fit-content;
115-
padding: 2px;
11698
box-sizing: border-box;
99+
flex-grow: 1;
100+
padding: 0.2em;
101+
max-width: fit-content;
102+
animation-duration: 0.15s;
103+
@include zoomIn();
117104
div {
118105
flex-direction: row !important;
119106
display: flex;
120107
justify-items: space-between;
121-
padding: 0 5% 0 10%;
108+
padding: 0.38em;
122109
background: #eee;
123110
border-radius: 5px;
124111
min-width: fit-content;
125-
padding: 2px;
126112
position: relative;
127113
box-sizing: border-box;
128114
div {
@@ -138,27 +124,23 @@
138124
}
139125

140126
:local(.selected-option) {
141-
background-color: rgba(71, 233, 243, 0.2);
127+
background-color: #66a5ad;
128+
color: white;
142129
}
143130

144131
:local(.arrow) {
145-
align-self: flex-start;
146-
border: none;
147-
border-right: 2px solid #1a237e;
148-
border-bottom: 2px solid #1a237e;
149-
height: 5px;
150-
width: 5px;
151-
margin-right: -5px;
132+
align-self: center;
152133
transition: 0.3s ease;
153-
margin-top: 5%;
134+
cursor: pointer;
135+
will-change: transform;
154136
}
155137

156-
:local(.down) {
157-
transform: rotate(45deg);
138+
:local(.up) {
139+
transform: rotate(-180deg);
158140
}
159141

160-
:local(.up) {
161-
transform: rotate(-135deg);
142+
:local(.down) {
143+
transform: rotate(0deg);
162144
}
163145

164146
:local(.border-animation) {
@@ -167,7 +149,7 @@
167149
position: absolute;
168150
bottom: -2px;
169151
left: 0px;
170-
background-color: $primary-input-active-border !important;
152+
background-color: #c4dfe6 !important;
171153
height: 2px;
172154
@include inputFocus();
173155
animation-duration: 0.5s;

0 commit comments

Comments
 (0)