@thecb/components 6.0.0-beta.2 → 6.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +24 -9
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +24 -9
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/atoms/dropdown/Dropdown.js +44 -34
package/package.json
CHANGED
|
@@ -93,12 +93,14 @@ const Dropdown = ({
|
|
|
93
93
|
maxHeight,
|
|
94
94
|
widthFitOptions = false,
|
|
95
95
|
disabled,
|
|
96
|
-
hasTitles = false
|
|
96
|
+
hasTitles = false,
|
|
97
|
+
autoEraseTypeAhead = true // legacy behavior as of 05/22
|
|
97
98
|
}) => {
|
|
98
99
|
const [inputValue, setInputValue] = useState("");
|
|
99
100
|
const [optionsState, setOptionsState] = useState([]);
|
|
100
101
|
const [filteredOptions, setFilteredOptions] = useState([]);
|
|
101
102
|
const [optionsChanged, setOptionsChanged] = useState(true);
|
|
103
|
+
const [selectedRef, setSelectedRef] = useState(undefined);
|
|
102
104
|
|
|
103
105
|
if (optionsState !== options) {
|
|
104
106
|
setOptionsState(options);
|
|
@@ -175,6 +177,7 @@ const Dropdown = ({
|
|
|
175
177
|
"option refs in isopen useffect",
|
|
176
178
|
optionRefs.current[0].current
|
|
177
179
|
);
|
|
180
|
+
console.log("selected refs in isopen useffect", selectedRef);
|
|
178
181
|
console.log("value in isopen useffect", value);
|
|
179
182
|
if (isOpen && optionRefs.current[0].current) {
|
|
180
183
|
optionRefs.current[0].current.focus();
|
|
@@ -184,8 +187,10 @@ const Dropdown = ({
|
|
|
184
187
|
}, [isOpen]);
|
|
185
188
|
|
|
186
189
|
useEffect(() => {
|
|
187
|
-
|
|
188
|
-
|
|
190
|
+
if (autoEraseTypeAhead) {
|
|
191
|
+
clearTimeout(timer);
|
|
192
|
+
setTimer(setTimeout(() => setInputValue(""), 2000));
|
|
193
|
+
}
|
|
189
194
|
setFilteredOptions(
|
|
190
195
|
options.filter(
|
|
191
196
|
option =>
|
|
@@ -286,33 +291,37 @@ const Dropdown = ({
|
|
|
286
291
|
tabIndex={0}
|
|
287
292
|
>
|
|
288
293
|
<Stack childGap="0">
|
|
289
|
-
{filteredOptions.map((choice, i) =>
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
themeValues={themeValues}
|
|
304
|
-
title={hasTitles ? choice.text : null}
|
|
305
|
-
>
|
|
306
|
-
<Text
|
|
307
|
-
variant="p"
|
|
308
|
-
color={
|
|
309
|
-
choice.value === value
|
|
310
|
-
? WHITE
|
|
311
|
-
: disabledValues.includes(choice.value)
|
|
312
|
-
? STORM_GREY
|
|
313
|
-
: MINESHAFT_GREY
|
|
294
|
+
{filteredOptions.map((choice, i) => {
|
|
295
|
+
if (selectedRef === undefined && choice.value === value) {
|
|
296
|
+
setSelectedRef(optionRefs.current[i]);
|
|
297
|
+
}
|
|
298
|
+
return (
|
|
299
|
+
<DropdownItemWrapper
|
|
300
|
+
key={choice.value}
|
|
301
|
+
ref={optionRefs.current[i]}
|
|
302
|
+
as="button"
|
|
303
|
+
tabIndex={-1}
|
|
304
|
+
onClick={
|
|
305
|
+
disabledValues.includes(choice.value)
|
|
306
|
+
? evt => evt.preventDefault()
|
|
307
|
+
: () => onSelect(choice.value)
|
|
314
308
|
}
|
|
315
|
-
|
|
309
|
+
selected={choice.value === value}
|
|
310
|
+
disabled={disabledValues.includes(choice.value)}
|
|
311
|
+
data-qa={choice.text}
|
|
312
|
+
themeValues={themeValues}
|
|
313
|
+
title={hasTitles ? choice.text : null}
|
|
314
|
+
>
|
|
315
|
+
<Text
|
|
316
|
+
variant="p"
|
|
317
|
+
color={
|
|
318
|
+
choice.value === value
|
|
319
|
+
? WHITE
|
|
320
|
+
: disabledValues.includes(choice.value)
|
|
321
|
+
? STORM_GREY
|
|
322
|
+
: MINESHAFT_GREY
|
|
323
|
+
}
|
|
324
|
+
extraStyles={`padding-left: 16px;
|
|
316
325
|
cursor: ${
|
|
317
326
|
disabledValues.includes(choice.value)
|
|
318
327
|
? "default"
|
|
@@ -321,11 +330,12 @@ const Dropdown = ({
|
|
|
321
330
|
white-space: nowrap;
|
|
322
331
|
overflow: hidden;
|
|
323
332
|
text-overflow: ellipsis;`}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
333
|
+
>
|
|
334
|
+
{choice.text}
|
|
335
|
+
</Text>
|
|
336
|
+
</DropdownItemWrapper>
|
|
337
|
+
);
|
|
338
|
+
})}
|
|
329
339
|
</Stack>
|
|
330
340
|
</DropdownContentWrapper>
|
|
331
341
|
) : (
|