@thecb/components 6.0.0-beta.15 → 6.0.0-beta.18
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 +47 -18
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +47 -18
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/atoms/dropdown/Dropdown.js +90 -68
package/package.json
CHANGED
|
@@ -16,12 +16,12 @@ 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
|
-
position: absolute;
|
|
24
|
+
${({ open }) => (open ? "transform: rotate(-180deg)" : "")};
|
|
25
25
|
top: 20px;
|
|
26
26
|
right: 12px;
|
|
27
27
|
`;
|
|
@@ -123,7 +123,7 @@ const Dropdown = ({
|
|
|
123
123
|
value ? options.find(option => option.value === value)?.text : placeholder;
|
|
124
124
|
|
|
125
125
|
const onKeyDown = e => {
|
|
126
|
-
console.log("current input value", inputValue);
|
|
126
|
+
console.log("current input value top of keyDown", inputValue);
|
|
127
127
|
const { key, keyCode } = e;
|
|
128
128
|
const focus = document.activeElement;
|
|
129
129
|
console.log("dropdown value is", value);
|
|
@@ -131,6 +131,9 @@ const Dropdown = ({
|
|
|
131
131
|
switch (key) {
|
|
132
132
|
case "ArrowDown":
|
|
133
133
|
e.preventDefault();
|
|
134
|
+
if (!isOpen) {
|
|
135
|
+
onClick();
|
|
136
|
+
}
|
|
134
137
|
if (optionEl) {
|
|
135
138
|
if (optionEl.current.nextElementSibling) {
|
|
136
139
|
optionEl.current.nextElementSibling.focus();
|
|
@@ -180,6 +183,23 @@ const Dropdown = ({
|
|
|
180
183
|
}
|
|
181
184
|
break;
|
|
182
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
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const handleItemSelection = (evt, choice, i) => {
|
|
194
|
+
disabledValues.includes(choice.value)
|
|
195
|
+
? evt => evt.preventDefault()
|
|
196
|
+
: () => {
|
|
197
|
+
setSelectedRef(optionRefs.current[i]);
|
|
198
|
+
onSelect(choice.value);
|
|
199
|
+
if (isOpen) {
|
|
200
|
+
onClick();
|
|
201
|
+
}
|
|
202
|
+
};
|
|
183
203
|
};
|
|
184
204
|
|
|
185
205
|
useEffect(() => {
|
|
@@ -231,71 +251,75 @@ const Dropdown = ({
|
|
|
231
251
|
extraStyles={`position: relative;`}
|
|
232
252
|
minWidth="100%"
|
|
233
253
|
onClick={() => {
|
|
234
|
-
|
|
254
|
+
if (!isOpen) {
|
|
255
|
+
onClick();
|
|
256
|
+
}
|
|
235
257
|
}}
|
|
236
258
|
onKeyDown={onKeyDown}
|
|
237
259
|
width="100%"
|
|
238
260
|
>
|
|
239
|
-
<
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
disabled &&
|
|
264
|
-
`color: #6e727e;
|
|
261
|
+
<Box
|
|
262
|
+
as="input"
|
|
263
|
+
aria-multiline="false"
|
|
264
|
+
aria-autocomplete="list"
|
|
265
|
+
aria-controls={`${ariaLabelledby}_listbox`}
|
|
266
|
+
aria-activedescendant="focused_option"
|
|
267
|
+
aria-owns={`${ariaLabelledby}_listbox`}
|
|
268
|
+
aria-haspopup="listbox"
|
|
269
|
+
aria-labelledby={ariaLabelledby}
|
|
270
|
+
aria-expanded={isOpen}
|
|
271
|
+
autocomplete={autocompleteValue}
|
|
272
|
+
background={isOpen ? themeValues.hoverColor : WHITE}
|
|
273
|
+
borderRadius="2px"
|
|
274
|
+
borderSize="1px"
|
|
275
|
+
borderColor={
|
|
276
|
+
isError
|
|
277
|
+
? ERROR_COLOR
|
|
278
|
+
: isOpen
|
|
279
|
+
? themeValues.selectedColor
|
|
280
|
+
: GREY_CHATEAU
|
|
281
|
+
}
|
|
282
|
+
extraStyles={
|
|
283
|
+
disabled &&
|
|
284
|
+
`color: #6e727e;
|
|
265
285
|
background-color: #f7f7f7;
|
|
266
286
|
pointer-events: none;`
|
|
287
|
+
}
|
|
288
|
+
hoverStyles={`background-color: ${themeValues.hoverColor};`}
|
|
289
|
+
isOpen={isOpen}
|
|
290
|
+
minHeight="48px"
|
|
291
|
+
minWidth="100%"
|
|
292
|
+
name={autocompleteValue}
|
|
293
|
+
onFocus={() => {
|
|
294
|
+
/*
|
|
295
|
+
if (!isOpen) {
|
|
296
|
+
onClick();
|
|
267
297
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
}}
|
|
278
|
-
onChange={e => {
|
|
279
|
-
console.log("current input value", inputValue);
|
|
280
|
-
console.log("input change event", e.target);
|
|
281
|
-
console.log("input change event value", e.target.value);
|
|
298
|
+
*/
|
|
299
|
+
}}
|
|
300
|
+
onChange={e => {
|
|
301
|
+
console.log("current input value onChange", inputValue);
|
|
302
|
+
console.log("input change event", e.target);
|
|
303
|
+
console.log("input change event value", e.target.value);
|
|
304
|
+
// support autofill and copy/paste
|
|
305
|
+
if (e.tarvet.value !== inputValue) {
|
|
282
306
|
setInputValue(e.target.value);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
</
|
|
307
|
+
}
|
|
308
|
+
}}
|
|
309
|
+
padding="12px"
|
|
310
|
+
placeholder={getSelection()}
|
|
311
|
+
role="combobox"
|
|
312
|
+
themeValues={themeValues}
|
|
313
|
+
title={hasTitles ? getSelection() : null}
|
|
314
|
+
type="text"
|
|
315
|
+
tabIndex={0}
|
|
316
|
+
value={inputValue}
|
|
317
|
+
width="100%"
|
|
318
|
+
dataQa={placeholder}
|
|
319
|
+
/>
|
|
320
|
+
<IconWrapper open={isOpen} onClick={onClick}>
|
|
321
|
+
<DropdownIcon />
|
|
322
|
+
</IconWrapper>
|
|
299
323
|
<Fragment>
|
|
300
324
|
{isOpen ? (
|
|
301
325
|
<DropdownContentWrapper
|
|
@@ -325,14 +349,12 @@ const Dropdown = ({
|
|
|
325
349
|
key={choice.value}
|
|
326
350
|
ref={optionRefs.current[i]}
|
|
327
351
|
tabIndex={-1}
|
|
328
|
-
onClick={
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
}
|
|
352
|
+
onClick={e => handleItemSelection(e, choice, i)}
|
|
353
|
+
onKeyDown={e => {
|
|
354
|
+
if (e.keyCode === 13) {
|
|
355
|
+
handleItemSelection(e, choice, i);
|
|
356
|
+
}
|
|
357
|
+
}}
|
|
336
358
|
selected={choice.value === value}
|
|
337
359
|
aria-selected={choice.value === value}
|
|
338
360
|
disabled={disabledValues.includes(choice.value)}
|