@thecb/components 6.0.0-beta.17 → 6.0.0-beta.18

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.17",
3
+ "version": "6.0.0-beta.18",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -190,6 +190,18 @@ const Dropdown = ({
190
190
  }
191
191
  };
192
192
 
193
+ const handleItemSelection = (evt, choice, i) => {
194
+ disabledValues.includes(choice.value)
195
+ ? evt => evt.preventDefault()
196
+ : () => {
197
+ setSelectedRef(optionRefs.current[i]);
198
+ onSelect(choice.value);
199
+ if (isOpen) {
200
+ onClick();
201
+ }
202
+ };
203
+ };
204
+
193
205
  useEffect(() => {
194
206
  if (isOpen && selectedRef !== undefined && selectedRef.current !== null) {
195
207
  // WAI-ARIA requires the selected option to receive focus
@@ -279,15 +291,20 @@ const Dropdown = ({
279
291
  minWidth="100%"
280
292
  name={autocompleteValue}
281
293
  onFocus={() => {
294
+ /*
282
295
  if (!isOpen) {
283
296
  onClick();
284
297
  }
298
+ */
285
299
  }}
286
300
  onChange={e => {
287
301
  console.log("current input value onChange", inputValue);
288
302
  console.log("input change event", e.target);
289
303
  console.log("input change event value", e.target.value);
290
- setInputValue(e.target.value);
304
+ // support autofill and copy/paste
305
+ if (e.tarvet.value !== inputValue) {
306
+ setInputValue(e.target.value);
307
+ }
291
308
  }}
292
309
  padding="12px"
293
310
  placeholder={getSelection()}
@@ -332,17 +349,12 @@ const Dropdown = ({
332
349
  key={choice.value}
333
350
  ref={optionRefs.current[i]}
334
351
  tabIndex={-1}
335
- onClick={
336
- disabledValues.includes(choice.value)
337
- ? evt => evt.preventDefault()
338
- : () => {
339
- setSelectedRef(optionRefs.current[i]);
340
- onSelect(choice.value);
341
- if (isOpen) {
342
- onClick();
343
- }
344
- }
345
- }
352
+ onClick={e => handleItemSelection(e, choice, i)}
353
+ onKeyDown={e => {
354
+ if (e.keyCode === 13) {
355
+ handleItemSelection(e, choice, i);
356
+ }
357
+ }}
346
358
  selected={choice.value === value}
347
359
  aria-selected={choice.value === value}
348
360
  disabled={disabledValues.includes(choice.value)}