@thecb/components 6.0.0-beta.0 → 6.0.0-beta.3

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.0",
3
+ "version": "6.0.0-beta.3",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -93,12 +93,14 @@ const Dropdown = ({
93
93
  maxHeight,
94
94
  widthFitOptions = false,
95
95
  disabled,
96
- hasTitles = false
96
+ hasTitles = false,
97
+ autoEraseTypeAhead = true // legacy behavior as of 05/22
97
98
  }) => {
98
99
  const [inputValue, setInputValue] = useState("");
99
100
  const [optionsState, setOptionsState] = useState([]);
100
101
  const [filteredOptions, setFilteredOptions] = useState([]);
101
102
  const [optionsChanged, setOptionsChanged] = useState(true);
103
+ const [selectedRef, setSelectedRef] = useState(undefined);
102
104
 
103
105
  if (optionsState !== options) {
104
106
  setOptionsState(options);
@@ -120,6 +122,7 @@ const Dropdown = ({
120
122
  const onKeyDown = e => {
121
123
  const { key, keyCode } = e;
122
124
  const focus = document.activeElement;
125
+ console.log("dropdown value is", value);
123
126
  console.log("focus is", focus);
124
127
  console.log("option refs are", optionRefs.current);
125
128
  const optionEl = optionRefs.current.find(ref => ref.current === focus);
@@ -158,6 +161,8 @@ const Dropdown = ({
158
161
  break;
159
162
  case "Backspace" || "Delete":
160
163
  e.preventDefault();
164
+ console.log("input value is", inputValue);
165
+ console.log("new input value will be", inputValue.slice(0, -1));
161
166
  setInputValue(inputValue.slice(0, -1));
162
167
  break;
163
168
  }
@@ -168,6 +173,12 @@ const Dropdown = ({
168
173
  };
169
174
 
170
175
  useEffect(() => {
176
+ console.log(
177
+ "option refs in isopen useffect",
178
+ optionRefs.current[0].current
179
+ );
180
+ console.log("selected refs in isopen useffect", selectedRef);
181
+ console.log("value in isopen useffect", value);
171
182
  if (isOpen && optionRefs.current[0].current) {
172
183
  optionRefs.current[0].current.focus();
173
184
  }
@@ -176,8 +187,10 @@ const Dropdown = ({
176
187
  }, [isOpen]);
177
188
 
178
189
  useEffect(() => {
179
- clearTimeout(timer);
180
- setTimer(setTimeout(() => setInputValue(""), 2000));
190
+ if (autoEraseTypeAhead) {
191
+ clearTimeout(timer);
192
+ setTimer(setTimeout(() => setInputValue(""), 2000));
193
+ }
181
194
  setFilteredOptions(
182
195
  options.filter(
183
196
  option =>
@@ -278,33 +291,37 @@ const Dropdown = ({
278
291
  tabIndex={0}
279
292
  >
280
293
  <Stack childGap="0">
281
- {filteredOptions.map((choice, i) => (
282
- <DropdownItemWrapper
283
- key={choice.value}
284
- ref={optionRefs.current[i]}
285
- as="button"
286
- tabIndex={-1}
287
- onClick={
288
- disabledValues.includes(choice.value)
289
- ? evt => evt.preventDefault()
290
- : () => onSelect(choice.value)
291
- }
292
- selected={choice.value === value}
293
- disabled={disabledValues.includes(choice.value)}
294
- data-qa={choice.text}
295
- themeValues={themeValues}
296
- title={hasTitles ? choice.text : null}
297
- >
298
- <Text
299
- variant="p"
300
- color={
301
- choice.value === value
302
- ? WHITE
303
- : disabledValues.includes(choice.value)
304
- ? STORM_GREY
305
- : MINESHAFT_GREY
294
+ {filteredOptions.map((choice, i) => {
295
+ if (selectedRef === undefined && choice.value === value) {
296
+ setSelectedRef(optionRefs.current[i]);
297
+ }
298
+ return (
299
+ <DropdownItemWrapper
300
+ key={choice.value}
301
+ ref={optionRefs.current[i]}
302
+ as="button"
303
+ tabIndex={-1}
304
+ onClick={
305
+ disabledValues.includes(choice.value)
306
+ ? evt => evt.preventDefault()
307
+ : () => onSelect(choice.value)
306
308
  }
307
- extraStyles={`padding-left: 16px;
309
+ selected={choice.value === value}
310
+ disabled={disabledValues.includes(choice.value)}
311
+ data-qa={choice.text}
312
+ themeValues={themeValues}
313
+ title={hasTitles ? choice.text : null}
314
+ >
315
+ <Text
316
+ variant="p"
317
+ color={
318
+ choice.value === value
319
+ ? WHITE
320
+ : disabledValues.includes(choice.value)
321
+ ? STORM_GREY
322
+ : MINESHAFT_GREY
323
+ }
324
+ extraStyles={`padding-left: 16px;
308
325
  cursor: ${
309
326
  disabledValues.includes(choice.value)
310
327
  ? "default"
@@ -313,11 +330,12 @@ const Dropdown = ({
313
330
  white-space: nowrap;
314
331
  overflow: hidden;
315
332
  text-overflow: ellipsis;`}
316
- >
317
- {choice.text}
318
- </Text>
319
- </DropdownItemWrapper>
320
- ))}
333
+ >
334
+ {choice.text}
335
+ </Text>
336
+ </DropdownItemWrapper>
337
+ );
338
+ })}
321
339
  </Stack>
322
340
  </DropdownContentWrapper>
323
341
  ) : (