Skip to content

Commit a98902b

Browse files
committed
rerender on option update &options transition removed
1 parent 8cc7ff2 commit a98902b

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

src/Options.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import React from 'react'
22

3-
function Options({ opts, singleSelect, addValue, checkValueExist, value, largeData, menuOpen }) {
3+
function Options({
4+
opts,
5+
singleSelect,
6+
addValue,
7+
checkValueExist,
8+
value,
9+
largeData,
10+
menuOpen
11+
}) {
412
if (largeData && !menuOpen) return null
513
const optsArr = []
614
function addInArr(opts) {
@@ -49,7 +57,7 @@ function Options({ opts, singleSelect, addValue, checkValueExist, value, largeDa
4957
}
5058
}
5159
addInArr(opts)
52-
return optsArr
60+
return <div>{optsArr}</div>
5361
}
5462

5563
export default Options

src/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ function MultiSelect({
5656
const [value, setValue] = useState([])
5757
const [options, setOptions] = useState(userOptions || [])
5858
const [search, setSearch] = useState(null)
59-
const inputFld = useRef()
60-
59+
const inputFld = useRef(null)
6160
let stopPropagation = true
6261

6362
const preparDefaultValue = (defaultValue) => {
@@ -111,6 +110,10 @@ function MultiSelect({
111110
)
112111
}
113112

113+
useEffect(() => {
114+
setOptions(userOptions)
115+
}, [userOptions])
116+
114117
useEffect(() => {
115118
let preDefinedValue = []
116119
if (defaultValue !== '' || defaultValue.length > 0) {
@@ -351,7 +354,6 @@ function MultiSelect({
351354
setSearch(null)
352355
}
353356
}
354-
355357
return (
356358
<div
357359
{...attr}

src/styles.css

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
background: white;
9797
max-height: 0;
9898
overflow: auto;
99-
transition: max-height 100ms ease-in;
10099
}
101100
.msl-options::-webkit-scrollbar {
102101
width: 8px;
@@ -113,7 +112,7 @@
113112
.msl-options::-webkit-scrollbar-thumb:hover {
114113
background: rgb(0, 0, 0, 0.2);
115114
}
116-
.msl-options > .msl-option,
115+
.msl-options .msl-option,
117116
.msl-grp-title {
118117
font-size: var(--font-size);
119118
border-radius: calc(var(--border-radius) - 3px);
@@ -122,9 +121,13 @@
122121
margin: 4px 6px 4px;
123122
line-break: anywhere;
124123
line-height: 1.2;
124+
outline: none;
125125
white-space: break-spaces;
126126
transition: background 200ms;
127127
}
128+
.msl-option:focus-visible {
129+
outline: 2px solid rgb(0, 119, 255);
130+
}
128131

129132
.msl-grp-title {
130133
font-size: calc(var(--font-size) - 2px);
@@ -133,10 +136,10 @@
133136
opacity: 0.7;
134137
}
135138

136-
.msl-options > .msl-option:last-child {
139+
.msl-options .msl-option:last-child {
137140
margin-bottom: 5px;
138141
}
139-
.msl-options > .msl-option:hover,
142+
.msl-options .msl-option:hover,
140143
.msl-option:focus {
141144
background: var(--option-bg-hover);
142145
}

0 commit comments

Comments
 (0)