@thecb/components 6.0.0-beta.10 → 6.0.0-beta.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "6.0.0-beta.10",
3
+ "version": "6.0.0-beta.13",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -41,7 +41,7 @@ const DropdownContentWrapper = styled.div`
41
41
  }
42
42
  `;
43
43
 
44
- const DropdownItemWrapper = styled.div`
44
+ const DropdownItemWrapper = styled.li`
45
45
  background-color: ${({ selected, themeValues }) =>
46
46
  selected ? themeValues.selectedColor : WHITE};
47
47
  text-align: start;
@@ -51,6 +51,7 @@ const DropdownItemWrapper = styled.div`
51
51
  padding: 1rem;
52
52
  box-sizing: border-box;
53
53
  width: 100%;
54
+ list-style: none;
54
55
  cursor: ${({ disabled }) => (disabled ? "default" : "pointer")};
55
56
 
56
57
  &:hover {
@@ -170,6 +171,11 @@ const Dropdown = ({
170
171
  optionRefs?.current?.length ?? 0 - 1
171
172
  ].current.focus();
172
173
  break;
174
+ case "Escape":
175
+ if (isOpen) {
176
+ onClick();
177
+ }
178
+ break;
173
179
  }
174
180
  };
175
181
 
@@ -225,8 +231,13 @@ const Dropdown = ({
225
231
  }, [filteredOptions]);
226
232
 
227
233
  return (
228
- <Fragment>
229
- <Stack direction="row" bottomItem={2} extraStyles={`position: relative;`}>
234
+ <Box
235
+ padding="0"
236
+ extraStyles={`position: relative;`}
237
+ minWidth="100%"
238
+ width="100%"
239
+ >
240
+ <Stack direction="row" bottomItem={2}>
230
241
  <Box
231
242
  as="input"
232
243
  aria-multiline="false"
@@ -256,6 +267,7 @@ const Dropdown = ({
256
267
  }
257
268
  hoverStyles={`background-color: ${themeValues.hoverColor};`}
258
269
  isOpen={isOpen}
270
+ minWidth="85%"
259
271
  name={autocompleteValue}
260
272
  onKeyDown={onKeyDown}
261
273
  onClick={onClick}
@@ -273,64 +285,69 @@ const Dropdown = ({
273
285
  type="text"
274
286
  tabIndex={-1}
275
287
  value={inputValue}
276
- width="100%"
288
+ width="85%"
277
289
  dataQa={placeholder}
278
- >
279
- {isOpen ? (
280
- <DropdownContentWrapper
281
- maxHeight={maxHeight}
282
- open={isOpen}
283
- ref={dropdownRef}
284
- widthFitOptions={widthFitOptions}
285
- tabIndex={0}
286
- role="listbox"
287
- id={`${ariaLabelledby}_listbox`}
288
- >
289
- <Stack childGap="0">
290
- {filteredOptions.map((choice, i) => {
291
- if (
292
- choice.value === value &&
293
- selectedRef !== optionRefs.current[i]
294
- ) {
295
- setSelectedRef(optionRefs.current[i]);
296
- }
297
- return (
298
- <DropdownItemWrapper
299
- id={
300
- focusedRef === optionRefs.current[i]
301
- ? "focused_option"
302
- : choice.value
303
- }
304
- key={choice.value}
305
- ref={optionRefs.current[i]}
306
- tabIndex={-1}
307
- onClick={
308
- disabledValues.includes(choice.value)
309
- ? evt => evt.preventDefault()
310
- : () => {
311
- setSelectedRef(optionRefs.current[i]);
312
- onSelect(choice.value);
313
- }
290
+ />
291
+ <IconWrapper open={isOpen}>
292
+ <DropdownIcon />
293
+ </IconWrapper>
294
+ </Stack>
295
+ <Fragment>
296
+ {isOpen ? (
297
+ <DropdownContentWrapper
298
+ maxHeight={maxHeight}
299
+ open={isOpen}
300
+ ref={dropdownRef}
301
+ widthFitOptions={widthFitOptions}
302
+ tabIndex={0}
303
+ role="listbox"
304
+ id={`${ariaLabelledby}_listbox`}
305
+ >
306
+ <Stack childGap="0" as="ul">
307
+ {filteredOptions.map((choice, i) => {
308
+ if (
309
+ choice.value === value &&
310
+ selectedRef !== optionRefs.current[i]
311
+ ) {
312
+ setSelectedRef(optionRefs.current[i]);
313
+ }
314
+ return (
315
+ <DropdownItemWrapper
316
+ id={
317
+ focusedRef === optionRefs.current[i]
318
+ ? "focused_option"
319
+ : choice.value
320
+ }
321
+ key={choice.value}
322
+ ref={optionRefs.current[i]}
323
+ tabIndex={-1}
324
+ onClick={
325
+ disabledValues.includes(choice.value)
326
+ ? evt => evt.preventDefault()
327
+ : () => {
328
+ setSelectedRef(optionRefs.current[i]);
329
+ onSelect(choice.value);
330
+ }
331
+ }
332
+ selected={choice.value === value}
333
+ aria-selected={choice.value === value}
334
+ disabled={disabledValues.includes(choice.value)}
335
+ data-qa={choice.text}
336
+ themeValues={themeValues}
337
+ title={hasTitles ? choice.text : null}
338
+ role="option"
339
+ onFocus={() => setFocusedRef(optionRefs.current[i])}
340
+ >
341
+ <Text
342
+ variant="p"
343
+ color={
344
+ choice.value === value
345
+ ? WHITE
346
+ : disabledValues.includes(choice.value)
347
+ ? STORM_GREY
348
+ : MINESHAFT_GREY
314
349
  }
315
- selected={choice.value === value}
316
- aria-selected={choice.value === value}
317
- disabled={disabledValues.includes(choice.value)}
318
- data-qa={choice.text}
319
- themeValues={themeValues}
320
- title={hasTitles ? choice.text : null}
321
- role="option"
322
- onFocus={() => setFocusedRef(optionRefs.current[i])}
323
- >
324
- <Text
325
- variant="p"
326
- color={
327
- choice.value === value
328
- ? WHITE
329
- : disabledValues.includes(choice.value)
330
- ? STORM_GREY
331
- : MINESHAFT_GREY
332
- }
333
- extraStyles={`padding-left: 16px;
350
+ extraStyles={`padding-left: 16px;
334
351
  cursor: ${
335
352
  disabledValues.includes(choice.value)
336
353
  ? "default"
@@ -339,23 +356,19 @@ const Dropdown = ({
339
356
  white-space: nowrap;
340
357
  overflow: hidden;
341
358
  text-overflow: ellipsis;`}
342
- >
343
- {choice.text}
344
- </Text>
345
- </DropdownItemWrapper>
346
- );
347
- })}
348
- </Stack>
349
- </DropdownContentWrapper>
350
- ) : (
351
- <Fragment />
352
- )}
353
- </Box>
354
- <IconWrapper open={isOpen}>
355
- <DropdownIcon />
356
- </IconWrapper>
357
- </Stack>
358
- </Fragment>
359
+ >
360
+ {choice.text}
361
+ </Text>
362
+ </DropdownItemWrapper>
363
+ );
364
+ })}
365
+ </Stack>
366
+ </DropdownContentWrapper>
367
+ ) : (
368
+ <Fragment />
369
+ )}
370
+ </Fragment>
371
+ </Box>
359
372
  );
360
373
  };
361
374
 
@@ -80,7 +80,7 @@ const Box = ({
80
80
  onTouchEnd={onTouchEnd}
81
81
  {...rest}
82
82
  >
83
- {safeChildren(children, <Fragment />)}
83
+ {children && safeChildren(children, <Fragment />)}
84
84
  </BoxWrapper>
85
85
  );
86
86