@thecb/components 6.0.0-beta.14 → 6.0.0-beta.17
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 +23 -26
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +23 -26
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/atoms/dropdown/Dropdown.js +71 -82
package/package.json
CHANGED
|
@@ -16,11 +16,14 @@ import { fallbackValues } from "./Dropdown.theme";
|
|
|
16
16
|
import { themeComponent } from "../../../util/themeUtils";
|
|
17
17
|
|
|
18
18
|
const IconWrapper = styled.div`
|
|
19
|
+
position: absolute;
|
|
19
20
|
display: flex;
|
|
20
21
|
flex-direction: column;
|
|
21
22
|
justify-content: center;
|
|
22
23
|
transition: transform 0.3s ease;
|
|
23
|
-
${({ open }) => (open ? "transform: rotate(-180deg)" : "")}
|
|
24
|
+
${({ open }) => (open ? "transform: rotate(-180deg)" : "")};
|
|
25
|
+
top: 20px;
|
|
26
|
+
right: 12px;
|
|
24
27
|
`;
|
|
25
28
|
|
|
26
29
|
const DropdownContentWrapper = styled.div`
|
|
@@ -120,18 +123,17 @@ const Dropdown = ({
|
|
|
120
123
|
value ? options.find(option => option.value === value)?.text : placeholder;
|
|
121
124
|
|
|
122
125
|
const onKeyDown = e => {
|
|
123
|
-
console.log("
|
|
124
|
-
console.log("key down event value is", e.target.value);
|
|
126
|
+
console.log("current input value top of keyDown", inputValue);
|
|
125
127
|
const { key, keyCode } = e;
|
|
126
128
|
const focus = document.activeElement;
|
|
127
129
|
console.log("dropdown value is", value);
|
|
128
|
-
console.log("focus is", focus);
|
|
129
|
-
console.log("option refs are", optionRefs.current);
|
|
130
130
|
const optionEl = optionRefs.current.find(ref => ref.current === focus);
|
|
131
|
-
console.log("option el is", optionEl);
|
|
132
131
|
switch (key) {
|
|
133
132
|
case "ArrowDown":
|
|
134
133
|
e.preventDefault();
|
|
134
|
+
if (!isOpen) {
|
|
135
|
+
onClick();
|
|
136
|
+
}
|
|
135
137
|
if (optionEl) {
|
|
136
138
|
if (optionEl.current.nextElementSibling) {
|
|
137
139
|
optionEl.current.nextElementSibling.focus();
|
|
@@ -181,16 +183,14 @@ const Dropdown = ({
|
|
|
181
183
|
}
|
|
182
184
|
break;
|
|
183
185
|
}
|
|
186
|
+
if ((keyCode > 64 && keyCode < 91) || keyCode == 32 || keyCode == 189) {
|
|
187
|
+
e.preventDefault();
|
|
188
|
+
console.log("current input value inside keydown if", inputValue);
|
|
189
|
+
setInputValue(inputValue + key);
|
|
190
|
+
}
|
|
184
191
|
};
|
|
185
192
|
|
|
186
193
|
useEffect(() => {
|
|
187
|
-
console.log("option refs in isopen useffect", optionRefs);
|
|
188
|
-
console.log(
|
|
189
|
-
"option ref current in isopen useffect",
|
|
190
|
-
optionRefs.current[0].current
|
|
191
|
-
);
|
|
192
|
-
console.log("selected refs in isopen useffect", selectedRef);
|
|
193
|
-
console.log("value in isopen useffect", value);
|
|
194
194
|
if (isOpen && selectedRef !== undefined && selectedRef.current !== null) {
|
|
195
195
|
// WAI-ARIA requires the selected option to receive focus
|
|
196
196
|
selectedRef.current.focus();
|
|
@@ -223,8 +223,6 @@ const Dropdown = ({
|
|
|
223
223
|
!disabledValues.includes(filteredOptions[0].value) &&
|
|
224
224
|
filteredOptions[0].text != placeholder
|
|
225
225
|
) {
|
|
226
|
-
console.log("filtered options are", filteredOptions);
|
|
227
|
-
console.log("option refs are", optionRefs);
|
|
228
226
|
onSelect(filteredOptions[0].value);
|
|
229
227
|
}
|
|
230
228
|
if (optionRefs.current[0].current) {
|
|
@@ -238,16 +236,6 @@ const Dropdown = ({
|
|
|
238
236
|
<Box
|
|
239
237
|
padding="0"
|
|
240
238
|
background={isOpen ? themeValues.hoverColor : WHITE}
|
|
241
|
-
borderSize="1px"
|
|
242
|
-
borderColor={
|
|
243
|
-
isError
|
|
244
|
-
? ERROR_COLOR
|
|
245
|
-
: isOpen
|
|
246
|
-
? themeValues.selectedColor
|
|
247
|
-
: GREY_CHATEAU
|
|
248
|
-
}
|
|
249
|
-
borderRadius="2px"
|
|
250
|
-
borderWidthOverride="0px 1px 0px 0px"
|
|
251
239
|
extraStyles={`position: relative;`}
|
|
252
240
|
minWidth="100%"
|
|
253
241
|
onClick={() => {
|
|
@@ -255,68 +243,66 @@ const Dropdown = ({
|
|
|
255
243
|
onClick();
|
|
256
244
|
}
|
|
257
245
|
}}
|
|
246
|
+
onKeyDown={onKeyDown}
|
|
258
247
|
width="100%"
|
|
259
248
|
>
|
|
260
|
-
<
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
disabled &&
|
|
285
|
-
`color: #6e727e;
|
|
249
|
+
<Box
|
|
250
|
+
as="input"
|
|
251
|
+
aria-multiline="false"
|
|
252
|
+
aria-autocomplete="list"
|
|
253
|
+
aria-controls={`${ariaLabelledby}_listbox`}
|
|
254
|
+
aria-activedescendant="focused_option"
|
|
255
|
+
aria-owns={`${ariaLabelledby}_listbox`}
|
|
256
|
+
aria-haspopup="listbox"
|
|
257
|
+
aria-labelledby={ariaLabelledby}
|
|
258
|
+
aria-expanded={isOpen}
|
|
259
|
+
autocomplete={autocompleteValue}
|
|
260
|
+
background={isOpen ? themeValues.hoverColor : WHITE}
|
|
261
|
+
borderRadius="2px"
|
|
262
|
+
borderSize="1px"
|
|
263
|
+
borderColor={
|
|
264
|
+
isError
|
|
265
|
+
? ERROR_COLOR
|
|
266
|
+
: isOpen
|
|
267
|
+
? themeValues.selectedColor
|
|
268
|
+
: GREY_CHATEAU
|
|
269
|
+
}
|
|
270
|
+
extraStyles={
|
|
271
|
+
disabled &&
|
|
272
|
+
`color: #6e727e;
|
|
286
273
|
background-color: #f7f7f7;
|
|
287
274
|
pointer-events: none;`
|
|
275
|
+
}
|
|
276
|
+
hoverStyles={`background-color: ${themeValues.hoverColor};`}
|
|
277
|
+
isOpen={isOpen}
|
|
278
|
+
minHeight="48px"
|
|
279
|
+
minWidth="100%"
|
|
280
|
+
name={autocompleteValue}
|
|
281
|
+
onFocus={() => {
|
|
282
|
+
if (!isOpen) {
|
|
283
|
+
onClick();
|
|
288
284
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
type="text"
|
|
311
|
-
tabIndex={0}
|
|
312
|
-
value={inputValue}
|
|
313
|
-
width="85%"
|
|
314
|
-
dataQa={placeholder}
|
|
315
|
-
/>
|
|
316
|
-
<IconWrapper open={isOpen}>
|
|
317
|
-
<DropdownIcon />
|
|
318
|
-
</IconWrapper>
|
|
319
|
-
</Stack>
|
|
285
|
+
}}
|
|
286
|
+
onChange={e => {
|
|
287
|
+
console.log("current input value onChange", inputValue);
|
|
288
|
+
console.log("input change event", e.target);
|
|
289
|
+
console.log("input change event value", e.target.value);
|
|
290
|
+
setInputValue(e.target.value);
|
|
291
|
+
}}
|
|
292
|
+
padding="12px"
|
|
293
|
+
placeholder={getSelection()}
|
|
294
|
+
role="combobox"
|
|
295
|
+
themeValues={themeValues}
|
|
296
|
+
title={hasTitles ? getSelection() : null}
|
|
297
|
+
type="text"
|
|
298
|
+
tabIndex={0}
|
|
299
|
+
value={inputValue}
|
|
300
|
+
width="100%"
|
|
301
|
+
dataQa={placeholder}
|
|
302
|
+
/>
|
|
303
|
+
<IconWrapper open={isOpen} onClick={onClick}>
|
|
304
|
+
<DropdownIcon />
|
|
305
|
+
</IconWrapper>
|
|
320
306
|
<Fragment>
|
|
321
307
|
{isOpen ? (
|
|
322
308
|
<DropdownContentWrapper
|
|
@@ -352,6 +338,9 @@ const Dropdown = ({
|
|
|
352
338
|
: () => {
|
|
353
339
|
setSelectedRef(optionRefs.current[i]);
|
|
354
340
|
onSelect(choice.value);
|
|
341
|
+
if (isOpen) {
|
|
342
|
+
onClick();
|
|
343
|
+
}
|
|
355
344
|
}
|
|
356
345
|
}
|
|
357
346
|
selected={choice.value === value}
|