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

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.13",
3
+ "version": "6.0.0-beta.16",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -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
24
  ${({ open }) => (open ? "transform: rotate(-180deg)" : "")}
25
+ top: 20px;
26
+ right: 12px;
24
27
  `;
25
28
 
26
29
  const DropdownContentWrapper = styled.div`
@@ -39,6 +42,10 @@ const DropdownContentWrapper = styled.div`
39
42
  &:focus {
40
43
  outline: none;
41
44
  }
45
+
46
+ ul {
47
+ padding-left: 0;
48
+ }
42
49
  `;
43
50
 
44
51
  const DropdownItemWrapper = styled.li`
@@ -116,18 +123,17 @@ const Dropdown = ({
116
123
  value ? options.find(option => option.value === value)?.text : placeholder;
117
124
 
118
125
  const onKeyDown = e => {
119
- console.log("key down event is", e.target);
120
- console.log("key down event value is", e.target.value);
126
+ console.log("current input value", inputValue);
121
127
  const { key, keyCode } = e;
122
128
  const focus = document.activeElement;
123
129
  console.log("dropdown value is", value);
124
- console.log("focus is", focus);
125
- console.log("option refs are", optionRefs.current);
126
130
  const optionEl = optionRefs.current.find(ref => ref.current === focus);
127
- console.log("option el is", optionEl);
128
131
  switch (key) {
129
132
  case "ArrowDown":
130
133
  e.preventDefault();
134
+ if (!isOpen) {
135
+ onClick();
136
+ }
131
137
  if (optionEl) {
132
138
  if (optionEl.current.nextElementSibling) {
133
139
  optionEl.current.nextElementSibling.focus();
@@ -177,16 +183,13 @@ const Dropdown = ({
177
183
  }
178
184
  break;
179
185
  }
186
+ if ((keyCode > 64 && keyCode < 91) || keyCode == 32 || keyCode == 189) {
187
+ e.preventDefault();
188
+ setInputValue(inputValue + key);
189
+ }
180
190
  };
181
191
 
182
192
  useEffect(() => {
183
- console.log("option refs in isopen useffect", optionRefs);
184
- console.log(
185
- "option ref current in isopen useffect",
186
- optionRefs.current[0].current
187
- );
188
- console.log("selected refs in isopen useffect", selectedRef);
189
- console.log("value in isopen useffect", value);
190
193
  if (isOpen && selectedRef !== undefined && selectedRef.current !== null) {
191
194
  // WAI-ARIA requires the selected option to receive focus
192
195
  selectedRef.current.focus();
@@ -219,8 +222,6 @@ const Dropdown = ({
219
222
  !disabledValues.includes(filteredOptions[0].value) &&
220
223
  filteredOptions[0].text != placeholder
221
224
  ) {
222
- console.log("filtered options are", filteredOptions);
223
- console.log("option refs are", optionRefs);
224
225
  onSelect(filteredOptions[0].value);
225
226
  }
226
227
  if (optionRefs.current[0].current) {
@@ -233,65 +234,74 @@ const Dropdown = ({
233
234
  return (
234
235
  <Box
235
236
  padding="0"
237
+ background={isOpen ? themeValues.hoverColor : WHITE}
236
238
  extraStyles={`position: relative;`}
237
239
  minWidth="100%"
240
+ onClick={() => {
241
+ if (!isOpen) {
242
+ onClick();
243
+ }
244
+ }}
245
+ onKeyDown={onKeyDown}
238
246
  width="100%"
239
247
  >
240
- <Stack direction="row" bottomItem={2}>
241
- <Box
242
- as="input"
243
- aria-multiline="false"
244
- aria-autocomplete="list"
245
- aria-controls={`${ariaLabelledby}_listbox`}
246
- aria-activedescendant="focused_option"
247
- aria-owns={`${ariaLabelledby}_listbox`}
248
- aria-haspopup="listbox"
249
- aria-labelledby={ariaLabelledby}
250
- aria-expanded={isOpen}
251
- autocomplete={autocompleteValue}
252
- background={isOpen ? themeValues.hoverColor : WHITE}
253
- borderRadius="2px"
254
- borderSize="1px"
255
- borderColor={
256
- isError
257
- ? ERROR_COLOR
258
- : isOpen
259
- ? themeValues.selectedColor
260
- : GREY_CHATEAU
261
- }
262
- extraStyles={
263
- disabled &&
264
- `color: #6e727e;
248
+ <Box
249
+ as="input"
250
+ aria-multiline="false"
251
+ aria-autocomplete="list"
252
+ aria-controls={`${ariaLabelledby}_listbox`}
253
+ aria-activedescendant="focused_option"
254
+ aria-owns={`${ariaLabelledby}_listbox`}
255
+ aria-haspopup="listbox"
256
+ aria-labelledby={ariaLabelledby}
257
+ aria-expanded={isOpen}
258
+ autocomplete={autocompleteValue}
259
+ background={isOpen ? themeValues.hoverColor : WHITE}
260
+ borderRadius="2px"
261
+ borderSize="1px"
262
+ borderColor={
263
+ isError
264
+ ? ERROR_COLOR
265
+ : isOpen
266
+ ? themeValues.selectedColor
267
+ : GREY_CHATEAU
268
+ }
269
+ extraStyles={
270
+ disabled &&
271
+ `color: #6e727e;
265
272
  background-color: #f7f7f7;
266
273
  pointer-events: none;`
274
+ }
275
+ hoverStyles={`background-color: ${themeValues.hoverColor};`}
276
+ isOpen={isOpen}
277
+ minHeight="48px"
278
+ minWidth="100%"
279
+ name={autocompleteValue}
280
+ onFocus={() => {
281
+ if (!isOpen) {
282
+ onClick();
267
283
  }
268
- hoverStyles={`background-color: ${themeValues.hoverColor};`}
269
- isOpen={isOpen}
270
- minWidth="85%"
271
- name={autocompleteValue}
272
- onKeyDown={onKeyDown}
273
- onClick={onClick}
274
- onFocus={onClick}
275
- onChange={e => {
276
- console.log("input change event", e.target);
277
- console.log("input change event value", e.target.value);
278
- setInputValue(e.target.value);
279
- }}
280
- padding="12px"
281
- placeholder={getSelection()}
282
- role="combobox"
283
- themeValues={themeValues}
284
- title={hasTitles ? getSelection() : null}
285
- type="text"
286
- tabIndex={-1}
287
- value={inputValue}
288
- width="85%"
289
- dataQa={placeholder}
290
- />
291
- <IconWrapper open={isOpen}>
292
- <DropdownIcon />
293
- </IconWrapper>
294
- </Stack>
284
+ }}
285
+ onChange={e => {
286
+ console.log("current input value", inputValue);
287
+ console.log("input change event", e.target);
288
+ console.log("input change event value", e.target.value);
289
+ setInputValue(e.target.value);
290
+ }}
291
+ padding="12px"
292
+ placeholder={getSelection()}
293
+ role="combobox"
294
+ themeValues={themeValues}
295
+ title={hasTitles ? getSelection() : null}
296
+ type="text"
297
+ tabIndex={0}
298
+ value={inputValue}
299
+ width="100%"
300
+ dataQa={placeholder}
301
+ />
302
+ <IconWrapper open={isOpen} onClick={onClick}>
303
+ <DropdownIcon />
304
+ </IconWrapper>
295
305
  <Fragment>
296
306
  {isOpen ? (
297
307
  <DropdownContentWrapper