@thecb/components 6.0.0-beta.20 → 6.0.0-beta.23

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.20",
3
+ "version": "6.0.0-beta.23",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -96,7 +96,7 @@ const Dropdown = ({
96
96
  widthFitOptions = false,
97
97
  disabled,
98
98
  hasTitles = false,
99
- autoEraseTypeAhead = true, // legacy behavior as of 05/22
99
+ autoEraseTypeAhead = true,
100
100
  ariaLabelledby,
101
101
  autocompleteValue = "" // autofill item for browsers, like country-name or address-level1 for state
102
102
  }) => {
@@ -106,6 +106,7 @@ const Dropdown = ({
106
106
  const [optionsChanged, setOptionsChanged] = useState(true);
107
107
  const [selectedRef, setSelectedRef] = useState(undefined);
108
108
  const [focusedRef, setFocusedRef] = useState(undefined);
109
+ const [inputChangedByAutofill, setInputChangedByAutofill] = useState(false);
109
110
 
110
111
  if (optionsState !== options) {
111
112
  setOptionsState(options);
@@ -231,12 +232,21 @@ const Dropdown = ({
231
232
 
232
233
  useEffect(() => {
233
234
  if (
234
- !isOpen &&
235
+ /*
236
+ Either user has typed a value into input that matches a non-disabled option
237
+ or
238
+ user has autofilled or pasted into input a string matching a valid option
239
+ */
240
+ (!isOpen || inputChangedByAutofill) &&
235
241
  filteredOptions[0] &&
236
242
  !disabledValues.includes(filteredOptions[0].value) &&
237
243
  filteredOptions[0].text != placeholder
238
244
  ) {
245
+ setInputChangedByAutofill(false);
239
246
  onSelect(filteredOptions[0].value);
247
+ if (isOpen) {
248
+ onClick();
249
+ }
240
250
  }
241
251
  if (optionRefs.current[0].current) {
242
252
  optionRefs.current[0].current.focus();
@@ -291,20 +301,14 @@ const Dropdown = ({
291
301
  minHeight="48px"
292
302
  minWidth="100%"
293
303
  name={autocompleteValue}
294
- onFocus={() => {
295
- /*
296
- if (!isOpen) {
297
- onClick();
298
- }
299
- */
300
- }}
301
304
  onChange={e => {
302
305
  console.log("current input value onChange", inputValue);
303
306
  console.log("input change event", e.target);
304
307
  console.log("input change event value", e.target.value);
305
308
  // support autofill and copy/paste
306
- if (e.tarvet.value !== inputValue) {
309
+ if (e.target.value !== inputValue) {
307
310
  setInputValue(e.target.value);
311
+ setInputChangedByAutofill(true);
308
312
  }
309
313
  }}
310
314
  padding="12px"