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

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.11",
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;
@@ -170,6 +170,11 @@ const Dropdown = ({
170
170
  optionRefs?.current?.length ?? 0 - 1
171
171
  ].current.focus();
172
172
  break;
173
+ case "Escape":
174
+ if (isOpen) {
175
+ onClick();
176
+ }
177
+ break;
173
178
  }
174
179
  };
175
180
 
@@ -275,62 +280,67 @@ const Dropdown = ({
275
280
  value={inputValue}
276
281
  width="100%"
277
282
  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
- }
283
+ />
284
+ <IconWrapper open={isOpen}>
285
+ <DropdownIcon />
286
+ </IconWrapper>
287
+ </Stack>
288
+ <Fragment>
289
+ {isOpen ? (
290
+ <DropdownContentWrapper
291
+ maxHeight={maxHeight}
292
+ open={isOpen}
293
+ ref={dropdownRef}
294
+ widthFitOptions={widthFitOptions}
295
+ tabIndex={0}
296
+ role="listbox"
297
+ id={`${ariaLabelledby}_listbox`}
298
+ >
299
+ <Stack childGap="0" as="ul">
300
+ {filteredOptions.map((choice, i) => {
301
+ if (
302
+ choice.value === value &&
303
+ selectedRef !== optionRefs.current[i]
304
+ ) {
305
+ setSelectedRef(optionRefs.current[i]);
306
+ }
307
+ return (
308
+ <DropdownItemWrapper
309
+ id={
310
+ focusedRef === optionRefs.current[i]
311
+ ? "focused_option"
312
+ : choice.value
313
+ }
314
+ key={choice.value}
315
+ ref={optionRefs.current[i]}
316
+ tabIndex={-1}
317
+ onClick={
318
+ disabledValues.includes(choice.value)
319
+ ? evt => evt.preventDefault()
320
+ : () => {
321
+ setSelectedRef(optionRefs.current[i]);
322
+ onSelect(choice.value);
323
+ }
324
+ }
325
+ selected={choice.value === value}
326
+ aria-selected={choice.value === value}
327
+ disabled={disabledValues.includes(choice.value)}
328
+ data-qa={choice.text}
329
+ themeValues={themeValues}
330
+ title={hasTitles ? choice.text : null}
331
+ role="option"
332
+ onFocus={() => setFocusedRef(optionRefs.current[i])}
333
+ >
334
+ <Text
335
+ variant="p"
336
+ color={
337
+ choice.value === value
338
+ ? WHITE
339
+ : disabledValues.includes(choice.value)
340
+ ? STORM_GREY
341
+ : MINESHAFT_GREY
314
342
  }
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;
343
+ extraStyles={`padding-left: 16px;
334
344
  cursor: ${
335
345
  disabledValues.includes(choice.value)
336
346
  ? "default"
@@ -339,22 +349,18 @@ const Dropdown = ({
339
349
  white-space: nowrap;
340
350
  overflow: hidden;
341
351
  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>
352
+ >
353
+ {choice.text}
354
+ </Text>
355
+ </DropdownItemWrapper>
356
+ );
357
+ })}
358
+ </Stack>
359
+ </DropdownContentWrapper>
360
+ ) : (
361
+ <Fragment />
362
+ )}
363
+ </Fragment>
358
364
  </Fragment>
359
365
  );
360
366
  };