@thecb/components 6.0.0-beta.2 → 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.2",
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);
@@ -175,6 +177,7 @@ const Dropdown = ({
175
177
  "option refs in isopen useffect",
176
178
  optionRefs.current[0].current
177
179
  );
180
+ console.log("selected refs in isopen useffect", selectedRef);
178
181
  console.log("value in isopen useffect", value);
179
182
  if (isOpen && optionRefs.current[0].current) {
180
183
  optionRefs.current[0].current.focus();
@@ -184,8 +187,10 @@ const Dropdown = ({
184
187
  }, [isOpen]);
185
188
 
186
189
  useEffect(() => {
187
- clearTimeout(timer);
188
- setTimer(setTimeout(() => setInputValue(""), 2000));
190
+ if (autoEraseTypeAhead) {
191
+ clearTimeout(timer);
192
+ setTimer(setTimeout(() => setInputValue(""), 2000));
193
+ }
189
194
  setFilteredOptions(
190
195
  options.filter(
191
196
  option =>
@@ -286,33 +291,37 @@ const Dropdown = ({
286
291
  tabIndex={0}
287
292
  >
288
293
  <Stack childGap="0">
289
- {filteredOptions.map((choice, i) => (
290
- <DropdownItemWrapper
291
- key={choice.value}
292
- ref={optionRefs.current[i]}
293
- as="button"
294
- tabIndex={-1}
295
- onClick={
296
- disabledValues.includes(choice.value)
297
- ? evt => evt.preventDefault()
298
- : () => onSelect(choice.value)
299
- }
300
- selected={choice.value === value}
301
- disabled={disabledValues.includes(choice.value)}
302
- data-qa={choice.text}
303
- themeValues={themeValues}
304
- title={hasTitles ? choice.text : null}
305
- >
306
- <Text
307
- variant="p"
308
- color={
309
- choice.value === value
310
- ? WHITE
311
- : disabledValues.includes(choice.value)
312
- ? STORM_GREY
313
- : 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)
314
308
  }
315
- 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;
316
325
  cursor: ${
317
326
  disabledValues.includes(choice.value)
318
327
  ? "default"
@@ -321,11 +330,12 @@ const Dropdown = ({
321
330
  white-space: nowrap;
322
331
  overflow: hidden;
323
332
  text-overflow: ellipsis;`}
324
- >
325
- {choice.text}
326
- </Text>
327
- </DropdownItemWrapper>
328
- ))}
333
+ >
334
+ {choice.text}
335
+ </Text>
336
+ </DropdownItemWrapper>
337
+ );
338
+ })}
329
339
  </Stack>
330
340
  </DropdownContentWrapper>
331
341
  ) : (