@economic/taco 1.1.5-alpha.102 → 1.1.5-alpha.127

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.
Files changed (162) hide show
  1. package/dist/components/Accordion/Accordion.stories.d.ts +26 -0
  2. package/dist/components/Backdrop/Backdrop.stories.d.ts +7 -0
  3. package/dist/components/Badge/Badge.stories.d.ts +15 -0
  4. package/dist/components/Banner/Banner.stories.d.ts +23 -0
  5. package/dist/components/Button/Button.stories.d.ts +69 -0
  6. package/dist/components/Calendar/Calendar.d.ts +3 -1
  7. package/dist/components/Calendar/Calendar.stories.d.ts +13 -0
  8. package/dist/components/Card/Card.stories.d.ts +12 -0
  9. package/dist/components/Datepicker/Datepicker.stories.d.ts +43 -0
  10. package/dist/components/Dialog/Dialog.d.ts +1 -1
  11. package/dist/components/Dialog/Dialog.stories.d.ts +54 -0
  12. package/dist/components/Field/Field.stories.d.ts +14 -0
  13. package/dist/components/Form/Form.stories.d.ts +14 -0
  14. package/dist/components/Group/Group.d.ts +11 -1
  15. package/dist/components/Group/Group.stories.d.ts +23 -0
  16. package/dist/components/Hanger/Hanger.stories.d.ts +11 -0
  17. package/dist/components/HoverCard/HoverCard.stories.d.ts +28 -0
  18. package/dist/components/Icon/Icon.stories.d.ts +24 -0
  19. package/dist/components/Icon/components/ChevronLeftSolid.d.ts +3 -0
  20. package/dist/components/Icon/components/ChevronRightSolid.d.ts +3 -0
  21. package/dist/components/Icon/components/index.d.ts +1 -1
  22. package/dist/components/IconButton/IconButton.stories.d.ts +45 -0
  23. package/dist/components/Input/Input.d.ts +1 -1
  24. package/dist/components/Input/Input.stories.d.ts +43 -0
  25. package/dist/components/Listbox/Listbox.stories.d.ts +44 -0
  26. package/dist/components/Menu/Menu.d.ts +2 -2
  27. package/dist/components/Menu/Menu.stories.d.ts +93 -0
  28. package/dist/components/Menu/components/Item.d.ts +1 -1
  29. package/dist/components/Menu/components/Link.d.ts +1 -1
  30. package/dist/components/Navigation/Navigation.stories.d.ts +7 -0
  31. package/dist/components/Pagination/Pagination.stories.d.ts +28 -0
  32. package/dist/components/Popover/Popover.stories.d.ts +14 -0
  33. package/dist/components/Progress/Progress.stories.d.ts +8 -0
  34. package/dist/components/RadioGroup/RadioGroup.stories.d.ts +49 -0
  35. package/dist/components/SearchInput/SearchInput.stories.d.ts +41 -0
  36. package/dist/components/Select/Select.stories.d.ts +35 -0
  37. package/dist/components/Spinner/Spinner.stories.d.ts +15 -0
  38. package/dist/components/Table/Table.stories.d.ts +32 -0
  39. package/dist/components/Table/util/rowIndexPath.d.ts +2 -2
  40. package/dist/components/Tabs/Tabs.stories.d.ts +19 -0
  41. package/dist/components/Textarea/Textarea.stories.d.ts +40 -0
  42. package/dist/components/Toast/Toast.d.ts +2 -2
  43. package/dist/components/Toast/Toast.stories.d.ts +12 -0
  44. package/dist/components/Toast/Toaster.d.ts +2 -2
  45. package/dist/components/Tooltip/Tooltip.stories.d.ts +25 -0
  46. package/dist/components/Tour/Tour.stories.d.ts +11 -0
  47. package/dist/css/Typography.stories.d.ts +6 -0
  48. package/dist/esm/components/Badge/Badge.js +1 -1
  49. package/dist/esm/components/Badge/Badge.js.map +1 -1
  50. package/dist/esm/components/Calendar/Calendar.js +4 -11
  51. package/dist/esm/components/Calendar/Calendar.js.map +1 -1
  52. package/dist/esm/components/Checkbox/Checkbox.js.map +1 -1
  53. package/dist/esm/components/Combobox/Combobox.js.map +1 -1
  54. package/dist/esm/components/Combobox/useCombobox.js +12 -13
  55. package/dist/esm/components/Combobox/useCombobox.js.map +1 -1
  56. package/dist/esm/components/Datepicker/Datepicker.js.map +1 -1
  57. package/dist/esm/components/Dialog/Dialog.js +39 -58
  58. package/dist/esm/components/Dialog/Dialog.js.map +1 -1
  59. package/dist/esm/components/Dialog/components/Content.js.map +1 -1
  60. package/dist/esm/components/Dialog/components/Drawer.js.map +1 -1
  61. package/dist/esm/components/Field/Field.js +10 -12
  62. package/dist/esm/components/Field/Field.js.map +1 -1
  63. package/dist/esm/components/Form/Form.js +6 -8
  64. package/dist/esm/components/Form/Form.js.map +1 -1
  65. package/dist/esm/components/Group/Group.js +9 -8
  66. package/dist/esm/components/Group/Group.js.map +1 -1
  67. package/dist/esm/components/Hanger/Hanger.js +27 -35
  68. package/dist/esm/components/Hanger/Hanger.js.map +1 -1
  69. package/dist/esm/components/HoverCard/HoverCard.js +8 -9
  70. package/dist/esm/components/HoverCard/HoverCard.js.map +1 -1
  71. package/dist/esm/components/Icon/Icon.js +7 -8
  72. package/dist/esm/components/Icon/Icon.js.map +1 -1
  73. package/dist/esm/components/Icon/components/ChevronLeftSolid.js +20 -0
  74. package/dist/esm/components/Icon/components/ChevronLeftSolid.js.map +1 -0
  75. package/dist/esm/components/Icon/components/ChevronRightSolid.js +20 -0
  76. package/dist/esm/components/Icon/components/ChevronRightSolid.js.map +1 -0
  77. package/dist/esm/components/Icon/components/index.js +4 -0
  78. package/dist/esm/components/Icon/components/index.js.map +1 -1
  79. package/dist/esm/components/IconButton/IconButton.js +9 -11
  80. package/dist/esm/components/IconButton/IconButton.js.map +1 -1
  81. package/dist/esm/components/Input/Input.js +25 -25
  82. package/dist/esm/components/Input/Input.js.map +1 -1
  83. package/dist/esm/components/Listbox/Listbox.js +24 -25
  84. package/dist/esm/components/Listbox/Listbox.js.map +1 -1
  85. package/dist/esm/components/Listbox/ScrollableList.js +2 -2
  86. package/dist/esm/components/Listbox/ScrollableList.js.map +1 -1
  87. package/dist/esm/components/Listbox/useListbox.js +3 -2
  88. package/dist/esm/components/Listbox/useListbox.js.map +1 -1
  89. package/dist/esm/components/Listbox/useMultiListbox.js +7 -7
  90. package/dist/esm/components/Listbox/useMultiListbox.js.map +1 -1
  91. package/dist/esm/components/Menu/Menu.js +16 -34
  92. package/dist/esm/components/Menu/Menu.js.map +1 -1
  93. package/dist/esm/components/Menu/components/Content.js.map +1 -1
  94. package/dist/esm/components/Menu/components/RadioGroup.js.map +1 -1
  95. package/dist/esm/components/Navigation/Navigation.js +36 -44
  96. package/dist/esm/components/Navigation/Navigation.js.map +1 -1
  97. package/dist/esm/components/Pagination/PageNumbers.js.map +1 -1
  98. package/dist/esm/components/Pagination/Pagination.js +39 -56
  99. package/dist/esm/components/Pagination/Pagination.js.map +1 -1
  100. package/dist/esm/components/Pagination/usePaginationShortcuts.js +4 -5
  101. package/dist/esm/components/Pagination/usePaginationShortcuts.js.map +1 -1
  102. package/dist/esm/components/Popover/Popover.js +29 -34
  103. package/dist/esm/components/Popover/Popover.js.map +1 -1
  104. package/dist/esm/components/Popover/Primitives.js.map +1 -1
  105. package/dist/esm/components/Progress/Progress.js +11 -15
  106. package/dist/esm/components/Progress/Progress.js.map +1 -1
  107. package/dist/esm/components/Provider/Provider.js +13 -18
  108. package/dist/esm/components/Provider/Provider.js.map +1 -1
  109. package/dist/esm/components/RadioGroup/RadioGroup.js +45 -57
  110. package/dist/esm/components/RadioGroup/RadioGroup.js.map +1 -1
  111. package/dist/esm/components/SearchInput/SearchInput.js +10 -12
  112. package/dist/esm/components/SearchInput/SearchInput.js.map +1 -1
  113. package/dist/esm/components/Select/Select.js +30 -31
  114. package/dist/esm/components/Select/Select.js.map +1 -1
  115. package/dist/esm/components/Select/useSelect.js +6 -7
  116. package/dist/esm/components/Select/useSelect.js.map +1 -1
  117. package/dist/esm/components/Spinner/Spinner.js +12 -19
  118. package/dist/esm/components/Spinner/Spinner.js.map +1 -1
  119. package/dist/esm/components/Switch/Switch.js +9 -10
  120. package/dist/esm/components/Switch/Switch.js.map +1 -1
  121. package/dist/esm/components/Table/components/BaseTable.js.map +1 -1
  122. package/dist/esm/components/Table/components/WindowedTable.js.map +1 -1
  123. package/dist/esm/components/Table/hooks/plugins/useRowActions.js +2 -3
  124. package/dist/esm/components/Table/hooks/plugins/useRowActions.js.map +1 -1
  125. package/dist/esm/components/Table/hooks/useTable.js +5 -1
  126. package/dist/esm/components/Table/hooks/useTable.js.map +1 -1
  127. package/dist/esm/components/Table/hooks/useTableKeyboardNavigation.js +18 -13
  128. package/dist/esm/components/Table/hooks/useTableKeyboardNavigation.js.map +1 -1
  129. package/dist/esm/components/Table/util/rowIndexPath.js.map +1 -1
  130. package/dist/esm/components/Tabs/Tabs.js +25 -27
  131. package/dist/esm/components/Tabs/Tabs.js.map +1 -1
  132. package/dist/esm/components/Textarea/Textarea.js +11 -9
  133. package/dist/esm/components/Textarea/Textarea.js.map +1 -1
  134. package/dist/esm/components/Toast/Toast.js +6 -1
  135. package/dist/esm/components/Toast/Toast.js.map +1 -1
  136. package/dist/esm/components/Toast/Toaster.js +88 -118
  137. package/dist/esm/components/Toast/Toaster.js.map +1 -1
  138. package/dist/esm/components/Toast/util.js.map +1 -1
  139. package/dist/esm/components/Tooltip/Tooltip.js +7 -8
  140. package/dist/esm/components/Tooltip/Tooltip.js.map +1 -1
  141. package/dist/esm/components/Tour/Tour.js +46 -53
  142. package/dist/esm/components/Tour/Tour.js.map +1 -1
  143. package/dist/esm/components/Treeview/Treeview.js +26 -36
  144. package/dist/esm/components/Treeview/Treeview.js.map +1 -1
  145. package/dist/esm/components/VisuallyHidden/VisuallyHidden.js +1 -1
  146. package/dist/esm/components/VisuallyHidden/VisuallyHidden.js.map +1 -1
  147. package/dist/esm/index.css +623 -635
  148. package/dist/esm/index.js +1 -1
  149. package/dist/esm/primitives/Button.js.map +1 -1
  150. package/dist/esm/utils/hooks/useListKeyboardNavigation.js +10 -11
  151. package/dist/esm/utils/hooks/useListKeyboardNavigation.js.map +1 -1
  152. package/dist/esm/utils/input.js +1 -1
  153. package/dist/esm/utils/input.js.map +1 -1
  154. package/dist/index.css +623 -635
  155. package/dist/primitives/Button.d.ts +2 -1
  156. package/dist/taco.cjs.development.js +709 -783
  157. package/dist/taco.cjs.development.js.map +1 -1
  158. package/dist/taco.cjs.production.min.js +1 -1
  159. package/dist/taco.cjs.production.min.js.map +1 -1
  160. package/dist/utils/hooks/useListKeyboardNavigation.d.ts +1 -1
  161. package/package.json +5 -6
  162. package/types.json +18 -4
@@ -1,25 +1,25 @@
1
- import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose } from '../../_virtual/_rollupPluginBabelHelpers.js';
2
1
  import { forwardRef, useEffect, createElement, cloneElement } from 'react';
3
2
  import cn from 'classnames';
4
3
  import { Icon } from '../Icon/Icon.js';
5
4
  import { useProxiedRef } from '../../utils/hooks/useProxiedRef.js';
6
5
  import { getInputClasses, getButtonStateClasses } from './util.js';
7
6
 
8
- var _excluded = ["button", "icon", "highlighted", "invalid", "onKeyDown", "autoFocus"];
9
- var Input = /*#__PURE__*/forwardRef(function Input(props, ref) {
10
- var button = props.button,
11
- icon = props.icon,
12
- invalid = props.invalid,
13
- onKeyDown = props.onKeyDown,
14
- autoFocus = props.autoFocus,
15
- otherProps = _objectWithoutPropertiesLoose(props, _excluded);
16
-
17
- var inputRef = useProxiedRef(ref);
18
- var hasContainer = button || icon;
19
- var className = cn(getInputClasses(props), 'min-h-[theme(spacing.8)] pointer-events-all', {
7
+ const Input = /*#__PURE__*/forwardRef(function Input(props, ref) {
8
+ const {
9
+ button,
10
+ icon,
11
+ highlighted,
12
+ invalid,
13
+ onKeyDown,
14
+ autoFocus,
15
+ ...otherProps
16
+ } = props;
17
+ const inputRef = useProxiedRef(ref);
18
+ const hasContainer = button || icon;
19
+ const className = cn(getInputClasses(props), 'min-h-[theme(spacing.8)] pointer-events-all', {
20
20
  'pr-8': !!hasContainer
21
21
  }, !hasContainer && otherProps.className);
22
- useEffect(function () {
22
+ useEffect(() => {
23
23
  if (autoFocus && inputRef.current) {
24
24
  inputRef.current.focus();
25
25
  }
@@ -27,10 +27,10 @@ var Input = /*#__PURE__*/forwardRef(function Input(props, ref) {
27
27
  // if it has scroll height then the browser reverts to native scrolling behaviour only
28
28
  // so we manually override it to ensure _our_ desired behaviour remains intact
29
29
 
30
- var handleKeyDown = function handleKeyDown(event) {
30
+ const handleKeyDown = event => {
31
31
  if (!event.shiftKey && (event.key === 'Home' || event.key === 'End')) {
32
32
  event.preventDefault();
33
- var position = event.key === 'End' ? event.currentTarget.value.length : 0;
33
+ const position = event.key === 'End' ? event.currentTarget.value.length : 0;
34
34
  event.currentTarget.setSelectionRange(position, position);
35
35
  }
36
36
 
@@ -39,7 +39,7 @@ var Input = /*#__PURE__*/forwardRef(function Input(props, ref) {
39
39
  }
40
40
  };
41
41
 
42
- var input = createElement("input", Object.assign({}, otherProps, {
42
+ const input = createElement("input", Object.assign({}, otherProps, {
43
43
  className: className,
44
44
  "data-taco": "input",
45
45
  onKeyDown: handleKeyDown,
@@ -47,19 +47,19 @@ var Input = /*#__PURE__*/forwardRef(function Input(props, ref) {
47
47
  }));
48
48
 
49
49
  if (hasContainer) {
50
- var extra;
50
+ let extra;
51
51
 
52
52
  if (button) {
53
- var _cn;
54
-
55
- var disabled = button.props.disabled || otherProps.disabled;
56
- var buttonClassName = cn('items-center flex justify-center border absolute rounded-l-none rounded-r right-0 h-full focus:rounded focus:outline-none', (_cn = {}, _cn[getButtonStateClasses(invalid)] = !props.disabled, _cn), button.props.className);
53
+ const disabled = button.props.disabled || otherProps.disabled;
54
+ const buttonClassName = cn('items-center flex justify-center border absolute rounded-l-none rounded-r right-0 h-full focus:rounded focus:outline-none', {
55
+ [getButtonStateClasses(invalid)]: !props.disabled
56
+ }, button.props.className);
57
57
  extra = cloneElement(button, {
58
58
  className: buttonClassName,
59
- disabled: disabled
59
+ disabled
60
60
  });
61
61
  } else if (icon) {
62
- var iconClassName = cn('items-center flex justify-center absolute pointer-events-none mr-1 p-px right-0 w-5 top-1/2 -translate-y-1/2', {
62
+ const iconClassName = cn('items-center flex justify-center absolute pointer-events-none mr-1 p-px right-0 w-5 top-1/2 -translate-y-1/2', {
63
63
  'text-grey-dark': props.disabled,
64
64
  'text-grey-darkest': !props.disabled
65
65
  });
@@ -71,7 +71,7 @@ var Input = /*#__PURE__*/forwardRef(function Input(props, ref) {
71
71
  });
72
72
  }
73
73
 
74
- var containerClassName = cn('bg-white inline-flex relative rounded w-full', otherProps.className);
74
+ const containerClassName = cn('bg-white inline-flex relative rounded w-full', otherProps.className);
75
75
  return createElement("div", {
76
76
  className: containerClassName,
77
77
  "data-taco": "input-container"
@@ -1 +1 @@
1
- {"version":3,"file":"Input.js","sources":["../../../../src/components/Input/Input.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport { Icon, IconName } from '../Icon/Icon';\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\nimport { getButtonStateClasses, getInputClasses } from './util';\n\nexport type InputProps = React.InputHTMLAttributes<HTMLInputElement> & {\n /** Shows a button within the input field */\n button?: React.ReactElement;\n /** Shows an icon within the input field */\n icon?: IconName | JSX.Element;\n /** Draws attention to the input by changing its style and making it visually prominent */\n highlighted?: boolean;\n /* Whether the input is in an invalid state */\n invalid?: boolean;\n};\n\nexport const Input = React.forwardRef(function Input(props: InputProps, ref: React.Ref<HTMLInputElement>) {\n const { button, icon, highlighted, invalid, onKeyDown, autoFocus, ...otherProps } = props;\n const inputRef = useProxiedRef<HTMLInputElement>(ref);\n const hasContainer = button || icon;\n const className = cn(\n getInputClasses(props),\n 'min-h-[theme(spacing.8)] pointer-events-all',\n {\n 'pr-8': !!hasContainer,\n },\n !hasContainer && otherProps.className\n );\n\n React.useEffect(() => {\n if (autoFocus && inputRef.current) {\n inputRef.current.focus();\n }\n }, []);\n\n // home and end keys only navigate to the start/end of input value if the input container does not scroll\n // if it has scroll height then the browser reverts to native scrolling behaviour only\n // so we manually override it to ensure _our_ desired behaviour remains intact\n const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n if (!event.shiftKey && (event.key === 'Home' || event.key === 'End')) {\n event.preventDefault();\n const position = event.key === 'End' ? event.currentTarget.value.length : 0;\n event.currentTarget.setSelectionRange(position, position);\n }\n\n if (onKeyDown) {\n onKeyDown(event);\n }\n };\n\n const input = <input {...otherProps} className={className} data-taco=\"input\" onKeyDown={handleKeyDown} ref={inputRef} />;\n\n if (hasContainer) {\n let extra: any;\n\n if (button) {\n const disabled = button.props.disabled || otherProps.disabled;\n const buttonClassName = cn(\n 'items-center flex justify-center border absolute rounded-l-none rounded-r right-0 h-full focus:rounded focus:outline-none',\n {\n [getButtonStateClasses(invalid)]: !props.disabled,\n },\n button.props.className\n );\n extra = React.cloneElement(button, {\n className: buttonClassName,\n disabled,\n });\n } else if (icon) {\n const iconClassName = cn(\n 'items-center flex justify-center absolute pointer-events-none mr-1 p-px right-0 w-5 top-1/2 -translate-y-1/2',\n {\n 'text-grey-dark': props.disabled,\n 'text-grey-darkest': !props.disabled,\n }\n );\n extra =\n typeof icon === 'string' ? (\n <Icon className={iconClassName} name={icon} />\n ) : (\n React.cloneElement(icon, { className: cn(iconClassName, icon.props.className) })\n );\n }\n\n const containerClassName = cn('bg-white inline-flex relative rounded w-full', otherProps.className);\n\n return (\n <div className={containerClassName} data-taco=\"input-container\">\n {input}\n {extra}\n </div>\n );\n }\n\n return input;\n});\n"],"names":["Input","React","props","ref","button","icon","invalid","onKeyDown","autoFocus","otherProps","inputRef","useProxiedRef","hasContainer","className","cn","getInputClasses","current","focus","handleKeyDown","event","shiftKey","key","preventDefault","position","currentTarget","value","length","setSelectionRange","input","extra","disabled","buttonClassName","getButtonStateClasses","iconClassName","Icon","name","containerClassName"],"mappings":";;;;;;;;IAiBaA,KAAK,gBAAGC,UAAA,CAAiB,SAASD,KAAT,CAAeE,KAAf,EAAkCC,GAAlC;MAC1BC,MAAR,GAAoFF,KAApF,CAAQE,MAAR;MAAgBC,IAAhB,GAAoFH,KAApF,CAAgBG,IAAhB;MAAmCC,OAAnC,GAAoFJ,KAApF,CAAmCI,OAAnC;MAA4CC,SAA5C,GAAoFL,KAApF,CAA4CK,SAA5C;MAAuDC,SAAvD,GAAoFN,KAApF,CAAuDM,SAAvD;MAAqEC,UAArE,iCAAoFP,KAApF;;EACA,IAAMQ,QAAQ,GAAGC,aAAa,CAAmBR,GAAnB,CAA9B;EACA,IAAMS,YAAY,GAAGR,MAAM,IAAIC,IAA/B;EACA,IAAMQ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AaW,SALS,CAA1B;MAOAgB,KAAK,GAAG5B,YAAA,CAAmBG,MAAnB,EAA2B;QAC/BS,SAAS,EAAEkB,eADoB;QAE/BD,QAAQ,EAARA;OAFI,CAAR;KATJ,MAaO,IAAIzB,IAAJ,EAAU;MACb,IAAM4B,aAAa,GAAGnB,EAAE,CACpB,8GADoB,EAEpB;QACI,kBAAkBZ,KAAK,CAAC4B,QAD5B;QAEI,qBAAqB,CAAC5B,KAAK,CAAC4B;OAJZ,CAAxB;MAOAD,KAAK,GACD,OAAOxB,IAAP,KAAgB,QAAhB,GACIJ,aAAA,CAACiC,IAAD;QAAMrB,SAAS,EAAEoB;QAAeE,IAAI,EAAE9B;OAAtC,CADJ,GAGIJ,YAAA,CAAmBI,IAAnB,EAAyB;QAAEQ,SAAS,EAAEC,EAAE,CAACmB,aAAD,EAAgB5B,IAAI,CAACH,KAAL,CAAWW,SAA3B;OAAxC,CAJR;;;IAQJ,IAAMuB,kBAAkB,GAAGtB,EAAE,CAAC,8CAAD,EAAiDL,UAAU,CAACI,SAA5D,CAA7B;IAEA,OACIZ,aAAA,MAAA;MAAKY,SAAS,EAAEuB;mBAA8B;KAA9C,EACKR,KADL,EAEKC,KAFL,CADJ;;;EAQJ,OAAOD,KAAP;AACH,CA/EoB;;;;"}
1
+ {"version":3,"file":"Input.js","sources":["../../../../src/components/Input/Input.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport { Icon, IconName } from '../Icon/Icon';\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\nimport { getButtonStateClasses, getInputClasses } from './util';\n\nexport type InputProps = React.InputHTMLAttributes<HTMLInputElement> & {\n /** Shows a button within the input field */\n button?: React.ReactElement;\n /** Shows an icon within the input field */\n icon?: IconName | JSX.Element;\n /** Draws attention to the input by changing its style and making it visually prominent */\n highlighted?: boolean;\n /* Whether the input is in an invalid state */\n invalid?: boolean;\n};\n\nexport const Input = React.forwardRef(function Input(props: InputProps, ref: React.Ref<HTMLInputElement>) {\n const { button, icon, highlighted, invalid, onKeyDown, autoFocus, ...otherProps } = props;\n const inputRef = useProxiedRef<HTMLInputElement>(ref);\n const hasContainer = button || icon;\n const className = cn(\n getInputClasses(props),\n 'min-h-[theme(spacing.8)] pointer-events-all',\n {\n 'pr-8': !!hasContainer,\n },\n !hasContainer && otherProps.className\n );\n\n React.useEffect(() => {\n if (autoFocus && inputRef.current) {\n inputRef.current.focus();\n }\n }, []);\n\n // home and end keys only navigate to the start/end of input value if the input container does not scroll\n // if it has scroll height then the browser reverts to native scrolling behaviour only\n // so we manually override it to ensure _our_ desired behaviour remains intact\n const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n if (!event.shiftKey && (event.key === 'Home' || event.key === 'End')) {\n event.preventDefault();\n const position = event.key === 'End' ? event.currentTarget.value.length : 0;\n event.currentTarget.setSelectionRange(position, position);\n }\n\n if (onKeyDown) {\n onKeyDown(event);\n }\n };\n\n const input = <input {...otherProps} className={className} data-taco=\"input\" onKeyDown={handleKeyDown} ref={inputRef} />;\n\n if (hasContainer) {\n let extra: any;\n\n if (button) {\n const disabled = button.props.disabled || otherProps.disabled;\n const buttonClassName = cn(\n 'items-center flex justify-center border absolute rounded-l-none rounded-r right-0 h-full focus:rounded focus:outline-none',\n {\n [getButtonStateClasses(invalid)]: !props.disabled,\n },\n button.props.className\n );\n extra = React.cloneElement(button, {\n className: buttonClassName,\n disabled,\n });\n } else if (icon) {\n const iconClassName = cn(\n 'items-center flex justify-center absolute pointer-events-none mr-1 p-px right-0 w-5 top-1/2 -translate-y-1/2',\n {\n 'text-grey-dark': props.disabled,\n 'text-grey-darkest': !props.disabled,\n }\n );\n extra =\n typeof icon === 'string' ? (\n <Icon className={iconClassName} name={icon} />\n ) : (\n React.cloneElement(icon, { className: cn(iconClassName, icon.props.className) })\n );\n }\n\n const containerClassName = cn('bg-white inline-flex relative rounded w-full', otherProps.className);\n\n return (\n <div className={containerClassName} data-taco=\"input-container\">\n {input}\n {extra}\n </div>\n );\n }\n\n return input;\n});\n"],"names":["Input","React","props","ref","button","icon","highlighted","invalid","onKeyDown","autoFocus","otherProps","inputRef","useProxiedRef","hasContainer","className","cn","getInputClasses","current","focus","handleKeyDown","event","shiftKey","key","preventDefault","position","currentTarget","value","length","setSelectionRange","input","extra","disabled","buttonClassName","getButtonStateClasses","iconClassName","Icon","name","containerClassName"],"mappings":";;;;;;MAiBaA,KAAK,gBAAGC,UAAA,CAAiB,SAASD,KAAT,CAAeE,KAAf,EAAkCC,GAAlC;EAClC,MAAM;IAAEC,MAAF;IAAUC,IAAV;IAAgBC,WAAhB;IAA6BC,OAA7B;IAAsCC,SAAtC;IAAiDC,SAAjD;IAA4D,GAAGC;MAAeR,KAApF;EACA,MAAMS,QAAQ,GAAGC,aAAa,CAAmBT,GAAnB,CAA9B;EACA,MAAMU,YAAY,GAAGT,MAAM,IAAIC,IAA/B;EACA,MAAMS,SAAS,GAAGC,EAAE,CAChBC,eAAe,CAACd,KAAD,CADC,EAEhB,6CAFgB,EAGhB;IACI,QAAQ,CAAC,CAACW;GAJE,EAMhB,CAACA,YAAD,IAAiBH,UAAU,CAACI,SANZ,CAApB;EASAb,SAAA,CAAgB;IACZ,IAAIQ,SAAS,IAAIE,QAAQ,CAACM,OAA1B,EAAmC;MAC/BN,QAAQ,CAACM,OAAT,CAAiBC,KAAjB;;GAFR,EAIG,EAJH;;;;EASA,MAAMC,aAAa,GAAIC,KAAD;IAClB,IAAI,CAACA,KAAK,CAACC,QAAP,KAAoBD,KAAK,CAACE,GAAN,KAAc,MAAd,IAAwBF,KAAK,CAACE,GAAN,KAAc,KAA1D,CAAJ,EAAsE;MAClEF,KAAK,CAACG,cAAN;MACA,MAAMC,QAAQ,GAAGJ,KAAK,CAACE,GAAN,KAAc,KAAd,GAAsBF,KAAK,CAACK,aAAN,CAAoBC,KAApB,CAA0BC,MAAhD,GAAyD,CAA1E;MACAP,KAAK,CAACK,aAAN,CAAoBG,iBAApB,CAAsCJ,QAAtC,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uB;mBAA8B;KAA9C,EACKR,KADL,EAEKC,KAFL,CADJ;;;EAQJ,OAAOD,KAAP;AACH,CA/EoB;;;;"}
@@ -1,53 +1,52 @@
1
- import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
2
1
  import { forwardRef, createElement } from 'react';
3
2
  import cn from 'classnames';
4
3
  import { ScrollableList } from './ScrollableList.js';
5
4
  import { useListbox } from './useListbox.js';
6
5
  import { useMultiListbox } from './useMultiListbox.js';
7
6
 
8
- var _excluded = ["className"],
9
- _excluded2 = ["className"];
10
- var Listbox = /*#__PURE__*/forwardRef(function Listbox(props, ref) {
11
- var externalClassName = props.className,
12
- otherProps = _objectWithoutPropertiesLoose(props, _excluded);
13
-
14
- var _useListbox = useListbox(otherProps, ref),
15
- list = _useListbox.list,
16
- input = _useListbox.input;
17
-
18
- var className = cn('bg-white inline-flex relative w-full', externalClassName);
7
+ const Listbox = /*#__PURE__*/forwardRef(function Listbox(props, ref) {
8
+ const {
9
+ className: externalClassName,
10
+ ...otherProps
11
+ } = props;
12
+ const {
13
+ list,
14
+ input
15
+ } = useListbox(otherProps, ref);
16
+ const className = cn('bg-white inline-flex relative w-full', externalClassName);
19
17
  return createElement("span", {
20
18
  "data-taco": "listbox",
21
19
  className: className
22
20
  }, createElement(ScrollableList, Object.assign({}, list, {
23
- style: _extends({}, list.style, {
21
+ style: { ...list.style,
24
22
  maxHeight: 'calc(12rem + 2px)'
25
23
  /* (6 * option height) + listbox border */
26
24
 
27
- })
25
+ }
28
26
  })), createElement("input", Object.assign({}, input, {
29
27
  className: "hidden",
30
28
  type: "text"
31
29
  })));
32
30
  });
33
- var MultiListbox = /*#__PURE__*/forwardRef(function Listbox(props, ref) {
34
- var externalClassName = props.className,
35
- otherProps = _objectWithoutPropertiesLoose(props, _excluded2);
36
-
37
- var _useMultiListbox = useMultiListbox(otherProps, ref),
38
- list = _useMultiListbox.list,
39
- input = _useMultiListbox.input;
40
-
41
- var className = cn('bg-white inline-flex relative w-full', externalClassName);
31
+ const MultiListbox = /*#__PURE__*/forwardRef(function Listbox(props, ref) {
32
+ const {
33
+ className: externalClassName,
34
+ ...otherProps
35
+ } = props;
36
+ const {
37
+ list,
38
+ input
39
+ } = useMultiListbox(otherProps, ref);
40
+ const className = cn('bg-white inline-flex relative w-full', externalClassName);
42
41
  return createElement("span", {
43
42
  "data-taco": "listbox",
44
43
  className: className
45
44
  }, createElement(ScrollableList, Object.assign({}, list, {
46
- style: _extends({}, list.style, {
45
+ style: { ...list.style,
47
46
  maxHeight: 'calc(12rem + 2px + 2px)'
48
47
  /* (6 * option height) + listbox border + ALL_OPTIONS bottom border */
49
48
 
50
- })
49
+ }
51
50
  })), createElement("input", Object.assign({}, input, {
52
51
  className: "hidden",
53
52
  type: "text"
@@ -1 +1 @@
1
- {"version":3,"file":"Listbox.js","sources":["../../../../src/components/Listbox/Listbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport { useListbox } from './useListbox';\nimport { useMultiListbox } from './useMultiListbox';\nimport { ScrollableList, ScrollableListItemValue, ScrollableListItem } from './ScrollableList';\n\nexport type ListboxItem = ScrollableListItem;\nexport type ListboxValue = ScrollableListItemValue;\n\nexport type ListboxTexts = {\n /**\n * Text displayed in the listbox if no data provided.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n empty: string;\n /**\n * Text displayed in the listbox to indicate the data is loading.\n * Read more about how to provide the text in [Provider](component:provider) component\n */\n loading: string;\n /**\n * The first option displayed in a multiselect listbox that selects all available options.\n * Read more about how to provide the text in [Provider](component:provider) component\n */\n allOption: string;\n};\n\nexport type ListboxProps = Pick<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'onFocus'> &\n Omit<React.InputHTMLAttributes<HTMLElement>, 'defaultValue' | 'onChange' | 'value'> & {\n /** Data indicating the options in listbox */\n data?: ListboxItem[];\n /**\n * Initial value of the listbox.\n * This is used when listbox is mounted, if no value is provided.\n * *Note* that listbox is a controlled component, setting this will also trigger the `onChange` event\n */\n defaultValue?: ListboxValue;\n /** Set what value should have an empty option in listbox */\n emptyValue?: ListboxValue;\n /** Draws attention to the listbox by changing its style and making it visually prominent */\n highlighted?: boolean;\n /* Whether the input is in an invalid state */\n invalid?: boolean;\n /**\n * Shows a loading indicator with a text next to it.\n * Read more about how to provide the text in [Provider](component:provider) component\n */\n loading?: boolean;\n /**\n * Value of the listbox representing the selected item.\n * It needs to be an existing value from the provided data\n */\n value?: ListboxValue;\n };\n\nexport const Listbox = React.forwardRef(function Listbox(props: ListboxProps, ref: React.Ref<HTMLInputElement>) {\n const { className: externalClassName, ...otherProps } = props;\n const { list, input } = useListbox(otherProps, ref);\n const className = cn('bg-white inline-flex relative w-full', externalClassName);\n\n return (\n <span data-taco=\"listbox\" className={className}>\n <ScrollableList\n {...list}\n style={{ ...list.style, maxHeight: 'calc(12rem + 2px)' /* (6 * option height) + listbox border */ }}\n />\n <input {...input} className=\"hidden\" type=\"text\" />\n </span>\n );\n});\n\nexport const MultiListbox = React.forwardRef(function Listbox(props: ListboxProps, ref: React.Ref<HTMLInputElement>) {\n const { className: externalClassName, ...otherProps } = props;\n const { list, input } = useMultiListbox(otherProps, ref);\n const className = cn('bg-white inline-flex relative w-full', externalClassName);\n\n return (\n <span data-taco=\"listbox\" className={className}>\n <ScrollableList\n {...list}\n style={{\n ...list.style,\n maxHeight: 'calc(12rem + 2px + 2px)' /* (6 * option height) + listbox border + ALL_OPTIONS bottom border */,\n }}\n />\n <input {...input} className=\"hidden\" type=\"text\" />\n </span>\n );\n});\n"],"names":["Listbox","React","props","ref","externalClassName","className","otherProps","useListbox","list","input","cn","ScrollableList","style","maxHeight","type","MultiListbox","useMultiListbox"],"mappings":";;;;;;;;;IAuDaA,OAAO,gBAAGC,UAAA,CAAiB,SAASD,OAAT,CAAiBE,KAAjB,EAAsCC,GAAtC;EACpC,IAAmBC,iBAAnB,GAAwDF,KAAxD,CAAQG,SAAR;MAAyCC,UAAzC,iCAAwDJ,KAAxD;;EACA,kBAAwBK,UAAU,CAACD,UAAD,EAAaH,GAAb,CAAlC;MAAQK,IAAR,eAAQA,IAAR;MAAcC,KAAd,eAAcA,KAAd;;EACA,IAAMJ,SAAS,GAAGK,EAAE,CAAC,sCAAD,EAAyCN,iBAAzC,CAApB;EAEA,OACIH,aAAA,OAAA;iBAAgB;IAAUI,SAAS,EAAEA;GAArC,EACIJ,aAAA,CAACU,cAAD,oBACQH;IACJI,KAAK,eAAOJ,IAAI,CAACI,KAAZ;MAAmBC,SAAS,EAAE;;;;IAFvC,CADJ,EAKIZ,aAAA,QAAA,oBAAWQ;IAAOJ,SAAS,EAAC;IAASS,IAAI,EAAC;IAA1C,CALJ,CADJ;AASH,CAdsB;IAgBVC,YAAY,gBAAGd,UAAA,CAAiB,SAASD,OAAT,CAAiBE,KAAjB,EAAsCC,GAAtC;EACzC,IAAmBC,iBAAnB,GAAwDF,KAAxD,CAAQG,SAAR;MAAyCC,UAAzC,iCAAwDJ,KAAxD;;EACA,uBAAwBc,eAAe,CAACV,UAAD,EAAaH,GAAb,CAAvC;MAAQK,IAAR,oBAAQA,IAAR;MAAcC,KAAd,oBAAcA,KAAd;;EACA,IAAMJ,SAAS,GAAGK,EAAE,CAAC,sCAAD,EAAyCN,iBAAzC,CAApB;EAEA,OACIH,aAAA,OAAA;iBAAgB;IAAUI,SAAS,EAAEA;GAArC,EACIJ,aAAA,CAACU,cAAD,oBACQH;IACJI,KAAK,eACEJ,IAAI,CAACI,KADP;MAEDC,SAAS,EAAE;;;;IAJnB,CADJ,EAQIZ,aAAA,QAAA,oBAAWQ;IAAOJ,SAAS,EAAC;IAASS,IAAI,EAAC;IAA1C,CARJ,CADJ;AAYH,CAjB2B;;;;"}
1
+ {"version":3,"file":"Listbox.js","sources":["../../../../src/components/Listbox/Listbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport { useListbox } from './useListbox';\nimport { useMultiListbox } from './useMultiListbox';\nimport { ScrollableList, ScrollableListItemValue, ScrollableListItem } from './ScrollableList';\n\nexport type ListboxItem = ScrollableListItem;\nexport type ListboxValue = ScrollableListItemValue;\n\nexport type ListboxTexts = {\n /**\n * Text displayed in the listbox if no data provided.\n * To read more about how to provide the text, see [Provider](component:provider) component\n */\n empty: string;\n /**\n * Text displayed in the listbox to indicate the data is loading.\n * Read more about how to provide the text in [Provider](component:provider) component\n */\n loading: string;\n /**\n * The first option displayed in a multiselect listbox that selects all available options.\n * Read more about how to provide the text in [Provider](component:provider) component\n */\n allOption: string;\n};\n\nexport type ListboxProps = Pick<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'onFocus'> &\n Omit<React.InputHTMLAttributes<HTMLElement>, 'defaultValue' | 'onChange' | 'value'> & {\n /** Data indicating the options in listbox */\n data?: ListboxItem[];\n /**\n * Initial value of the listbox.\n * This is used when listbox is mounted, if no value is provided.\n * *Note* that listbox is a controlled component, setting this will also trigger the `onChange` event\n */\n defaultValue?: ListboxValue;\n /** Set what value should have an empty option in listbox */\n emptyValue?: ListboxValue;\n /** Draws attention to the listbox by changing its style and making it visually prominent */\n highlighted?: boolean;\n /* Whether the input is in an invalid state */\n invalid?: boolean;\n /**\n * Shows a loading indicator with a text next to it.\n * Read more about how to provide the text in [Provider](component:provider) component\n */\n loading?: boolean;\n /**\n * Value of the listbox representing the selected item.\n * It needs to be an existing value from the provided data\n */\n value?: ListboxValue;\n };\n\nexport const Listbox = React.forwardRef(function Listbox(props: ListboxProps, ref: React.Ref<HTMLInputElement>) {\n const { className: externalClassName, ...otherProps } = props;\n const { list, input } = useListbox(otherProps, ref);\n const className = cn('bg-white inline-flex relative w-full', externalClassName);\n\n return (\n <span data-taco=\"listbox\" className={className}>\n <ScrollableList\n {...list}\n style={{ ...list.style, maxHeight: 'calc(12rem + 2px)' /* (6 * option height) + listbox border */ }}\n />\n <input {...input} className=\"hidden\" type=\"text\" />\n </span>\n );\n});\n\nexport const MultiListbox = React.forwardRef(function Listbox(props: ListboxProps, ref: React.Ref<HTMLInputElement>) {\n const { className: externalClassName, ...otherProps } = props;\n const { list, input } = useMultiListbox(otherProps, ref);\n const className = cn('bg-white inline-flex relative w-full', externalClassName);\n\n return (\n <span data-taco=\"listbox\" className={className}>\n <ScrollableList\n {...list}\n style={{\n ...list.style,\n maxHeight: 'calc(12rem + 2px + 2px)' /* (6 * option height) + listbox border + ALL_OPTIONS bottom border */,\n }}\n />\n <input {...input} className=\"hidden\" type=\"text\" />\n </span>\n );\n});\n"],"names":["Listbox","React","props","ref","className","externalClassName","otherProps","list","input","useListbox","cn","ScrollableList","style","maxHeight","type","MultiListbox","useMultiListbox"],"mappings":";;;;;;MAuDaA,OAAO,gBAAGC,UAAA,CAAiB,SAASD,OAAT,CAAiBE,KAAjB,EAAsCC,GAAtC;EACpC,MAAM;IAAEC,SAAS,EAAEC,iBAAb;IAAgC,GAAGC;MAAeJ,KAAxD;EACA,MAAM;IAAEK,IAAF;IAAQC;MAAUC,UAAU,CAACH,UAAD,EAAaH,GAAb,CAAlC;EACA,MAAMC,SAAS,GAAGM,EAAE,CAAC,sCAAD,EAAyCL,iBAAzC,CAApB;EAEA,OACIJ,aAAA,OAAA;iBAAgB;IAAUG,SAAS,EAAEA;GAArC,EACIH,aAAA,CAACU,cAAD,oBACQJ;IACJK,KAAK,EAAE,EAAE,GAAGL,IAAI,CAACK,KAAV;MAAiBC,SAAS,EAAE;;;;IAFvC,CADJ,EAKIZ,aAAA,QAAA,oBAAWO;IAAOJ,SAAS,EAAC;IAASU,IAAI,EAAC;IAA1C,CALJ,CADJ;AASH,CAdsB;MAgBVC,YAAY,gBAAGd,UAAA,CAAiB,SAASD,OAAT,CAAiBE,KAAjB,EAAsCC,GAAtC;EACzC,MAAM;IAAEC,SAAS,EAAEC,iBAAb;IAAgC,GAAGC;MAAeJ,KAAxD;EACA,MAAM;IAAEK,IAAF;IAAQC;MAAUQ,eAAe,CAACV,UAAD,EAAaH,GAAb,CAAvC;EACA,MAAMC,SAAS,GAAGM,EAAE,CAAC,sCAAD,EAAyCL,iBAAzC,CAApB;EAEA,OACIJ,aAAA,OAAA;iBAAgB;IAAUG,SAAS,EAAEA;GAArC,EACIH,aAAA,CAACU,cAAD,oBACQJ;IACJK,KAAK,EAAE,EACH,GAAGL,IAAI,CAACK,KADL;MAEHC,SAAS,EAAE;;;;IAJnB,CADJ,EAQIZ,aAAA,QAAA,oBAAWO;IAAOJ,SAAS,EAAC;IAASU,IAAI,EAAC;IAA1C,CARJ,CADJ;AAYH,CAjB2B;;;;"}
@@ -5,13 +5,13 @@ import { useLocalization } from '../Provider/Provider.js';
5
5
  import { Checkbox } from '../Checkbox/Checkbox.js';
6
6
  import { useProxiedRef } from '../../utils/hooks/useProxiedRef.js';
7
7
  import { getInputClasses } from '../Input/util.js';
8
- import { getNextIndexFromKeycode } from '../../utils/hooks/useListKeyboardNavigation.js';
8
+ import { getNextIndexFromKey } from '../../utils/hooks/useListKeyboardNavigation.js';
9
9
  import { useListScrollTo } from '../../utils/hooks/useListScrollTo.js';
10
10
 
11
11
  const getId = (id, value) => `${id}_${value}`;
12
12
 
13
13
  const getNextEnabledItem = (event, data, index) => {
14
- const nextIndex = getNextIndexFromKeycode(event.keyCode, data.length, index);
14
+ const nextIndex = getNextIndexFromKey(event.key, data.length, index);
15
15
 
16
16
  if (nextIndex) {
17
17
  if (nextIndex === index) {
@@ -1 +1 @@
1
- {"version":3,"file":"ScrollableList.js","sources":["../../../../src/components/Listbox/ScrollableList.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\nimport { getNextIndexFromKeycode } from '../../utils/hooks/useListKeyboardNavigation';\nimport { useListScrollTo } from '../../utils/hooks/useListScrollTo';\nimport './ScrollableList.css';\nimport { Spinner } from '../Spinner/Spinner';\nimport { useLocalization } from '../Provider/Provider';\nimport { Checkbox } from '../Checkbox/Checkbox';\nimport { getInputClasses } from '../Input/util';\n\nexport type ScrollableListItemValue = string | number | boolean | null;\n\nexport type ScrollableListItem = {\n /**\n * Set whether the item is disabled.\n * This will both change the style and make the item unselectable\n */\n disabled?: boolean;\n /* Specifies whether the item has child items -- intended for internal use only */\n hasChildren?: boolean;\n /** Place an icon before the item's text */\n icon?: React.ReactElement;\n /* The index path to the item -- intended for internal use only */\n path?: string;\n /** Text describing the item */\n text: string | JSX.Element;\n /** Value of the item */\n value: ScrollableListItemValue;\n /** Child items to show hierarchical data */\n children?: ScrollableListItem[];\n};\n\n/** @internal */\nexport type ScrollableListProps = Omit<\n React.HTMLAttributes<HTMLUListElement>,\n 'defaultValue' | 'id' | 'onChange' | 'onClick' | 'onKeyDown'\n> & {\n /** Data indicating the options in scrollable list */\n data: ScrollableListItem[];\n /** Sets the list to be disabled */\n disabled?: boolean;\n /** Draws attention to the scrollable list by changing its style and making it visually prominent */\n highlighted?: boolean;\n /** Set an id for the scrollable list */\n id: string;\n /* Whether the input is in an invalid state */\n invalid?: boolean;\n /**\n * Shows a loading indicator with a text next to it.\n * Read more about how to provide the text in `Provider` component.\n */\n loading?: boolean;\n /**\n * Handler called when current active/selected option changes in a scrollable list.\n * @param index indicates the index of the current active option\n */\n onChange: (index: number) => void;\n /** Handler called when option is clicked */\n onClick?: (event: React.MouseEvent<HTMLLIElement>, index: number) => void;\n /**\n * Set whether the selected item should be scrolled into view when listbox is focused.\n * Default value is `false`\n */\n scrollOnFocus?: boolean;\n /** Handler called when a key is pressed */\n onKeyDown?: (event: React.KeyboardEvent<HTMLUListElement>, index: number | undefined) => void;\n /* Sets the list to read only mode */\n readOnly?: boolean;\n /**\n * Value of the scrollable list representing the selected item.\n * It needs to be an existing value from the provided data.\n */\n value: number | undefined;\n /**\n * Allows to select multiple items from the list\n */\n multiselect?: boolean;\n /**\n * Contains the currently selected values when multiselect mode is ON.\n */\n selectedIndexes?: number[];\n /**\n * True when all available (not disabled) options are selected\n */\n allOptionsSelected?: boolean;\n};\n\n/** @internal */\nexport type ScrollableListPropsWithRef = ScrollableListProps & React.RefAttributes<HTMLUListElement>;\n\nexport const getId = (id: string, value: ScrollableListItemValue): string => `${id}_${value}`;\n\nconst getNextEnabledItem = (\n event: React.KeyboardEvent<HTMLElement>,\n data: ScrollableListItem[],\n index: number | undefined\n): number | undefined => {\n const nextIndex = getNextIndexFromKeycode(event.keyCode, data.length, index);\n\n if (nextIndex) {\n if (nextIndex === index) {\n return index;\n } else if (data[nextIndex] && data[nextIndex].disabled) {\n return getNextEnabledItem(event, data, nextIndex);\n }\n }\n\n return nextIndex;\n};\n\nexport const ScrollableList = React.forwardRef(function ScrollableList(\n props: ScrollableListProps,\n ref: React.Ref<HTMLUListElement>\n) {\n const {\n data,\n disabled,\n highlighted,\n id,\n invalid: _,\n loading,\n onChange: setCurrentIndex,\n onClick,\n onFocus,\n onKeyDown,\n readOnly,\n scrollOnFocus = false,\n value: currentIndex,\n multiselect,\n selectedIndexes = [],\n allOptionsSelected = false,\n ...otherProps\n } = props;\n const listRef = useProxiedRef<HTMLUListElement>(ref);\n const itemRefs = React.useMemo(() => data.map(() => React.createRef<HTMLLIElement>()), [data]);\n const { texts } = useLocalization();\n const { scrollTo } = useListScrollTo(listRef, itemRefs);\n\n React.useEffect(() => {\n if (currentIndex && itemRefs[currentIndex]?.current) {\n itemRefs[currentIndex].current?.scrollIntoView({\n block: 'center',\n });\n }\n }, []);\n\n React.useEffect(() => {\n scrollTo(currentIndex);\n }, [currentIndex]);\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLUListElement>): void => {\n const nextIndex = getNextEnabledItem(event, data, currentIndex);\n\n if (nextIndex !== undefined && nextIndex !== currentIndex) {\n event.preventDefault();\n scrollTo(nextIndex);\n setCurrentIndex(nextIndex);\n }\n\n if (onKeyDown) {\n event.persist();\n const index = nextIndex !== undefined ? nextIndex : currentIndex;\n onKeyDown(event, index);\n }\n };\n\n const handleClick = (index: number) => (event: React.MouseEvent<HTMLLIElement>) => {\n setCurrentIndex(index);\n\n if (onClick) {\n event.persist();\n onClick(event, index);\n }\n };\n\n const handleFocus = (event: React.FocusEvent<HTMLUListElement>): void => {\n if (scrollOnFocus) {\n scrollTo(currentIndex);\n }\n\n if (onFocus) {\n event.persist();\n onFocus(event);\n }\n };\n\n const getOptionCheckedState = (optionValue: string, index: number): boolean => {\n if (optionValue === '#ALL-OPTIONS#') {\n return allOptionsSelected;\n } else if (!optionValue || !selectedIndexes) {\n return false;\n } else {\n return selectedIndexes.findIndex(i => i === index) !== -1;\n }\n };\n\n const list: React.HTMLAttributes<HTMLUListElement> &\n React.RefAttributes<HTMLUListElement> & { disabled?: boolean; readOnly?: boolean } = {\n ...otherProps,\n className: cn(\n 'inline-flex flex-col list-none !p-0 m-0 overflow-y-auto h-auto',\n getInputClasses(props),\n {\n 'yt-list--multiselect': multiselect,\n 'pointer-events-none': disabled,\n 'cursor-not-allowed': disabled || readOnly,\n },\n otherProps.className\n ),\n disabled,\n id,\n onFocus: !disabled && !readOnly ? handleFocus : undefined,\n onKeyDown: !disabled && !readOnly ? handleKeyDown : undefined,\n readOnly,\n ref: listRef,\n role: 'listbox',\n tabIndex: otherProps.tabIndex || 0,\n };\n\n const options = data.map((option, index) => {\n const depth = option.path ? option.path.split('.').length - 1 : 0;\n\n return {\n 'aria-selected': multiselect ? getOptionCheckedState(String(option.value), index) : currentIndex === index,\n 'data-focused': currentIndex === index,\n children: option.text,\n className: cn(\n 'flex items-center px-3 w-full cursor-pointer bg-white flex-[0_0_2rem] focus:wcag-blue focus:border-blue',\n {\n 'sticky top-0 font-bold': depth === 0 && !!option.hasChildren,\n }\n ),\n disabled: option.disabled,\n icon: option.icon,\n id: getId(id, option.value),\n key: getId(id, option.value),\n onClick: !disabled && !readOnly ? handleClick(index) : undefined,\n ref: itemRefs[index],\n role: 'option',\n style:\n depth > 0\n ? {\n paddingLeft: `${depth + 1}rem`,\n }\n : undefined,\n };\n });\n\n return (\n <ul {...list} data-taco=\"scrollable-list\">\n {loading ? (\n <li className=\"yt-list__empty\">\n <span>\n <Spinner delay={0} />\n </span>\n <span>{texts.listbox.loading}</span>\n </li>\n ) : options.length ? (\n options.map(({ children, icon, ...optionProps }) => (\n <li {...optionProps}>\n {icon}\n <span className=\"flex-grow truncate text-left\">{children}</span>\n {multiselect && (\n <Checkbox\n checked={optionProps['aria-selected']}\n onChange={() => null}\n className=\"pointer-events-none ml-2 self-center p-px\"\n />\n )}\n </li>\n ))\n ) : (\n <li className=\"yt-list__empty\">\n <span>{texts.listbox.empty}</span>\n </li>\n )}\n </ul>\n );\n});\n"],"names":["getId","id","value","getNextEnabledItem","event","data","index","nextIndex","getNextIndexFromKeycode","keyCode","length","disabled","ScrollableList","React","props","ref","highlighted","invalid","_","loading","onChange","setCurrentIndex","onClick","onFocus","onKeyDown","readOnly","scrollOnFocus","currentIndex","multiselect","selectedIndexes","allOptionsSelected","otherProps","listRef","useProxiedRef","itemRefs","map","texts","useLocalization","scrollTo","useListScrollTo","current","scrollIntoView","block","handleKeyDown","undefined","preventDefault","persist","handleClick","handleFocus","getOptionCheckedState","optionValue","findIndex","i","list","className","cn","getInputClasses","role","tabIndex","options","option","depth","path","split","String","children","text","hasChildren","icon","key","style","paddingLeft","Spinner","delay","listbox","optionProps","Checkbox","checked","empty"],"mappings":";;;;;;;;;;MA2FaA,KAAK,GAAG,CAACC,EAAD,EAAaC,KAAb,QAA2DD,MAAMC;;AAEtF,MAAMC,kBAAkB,GAAG,CACvBC,KADuB,EAEvBC,IAFuB,EAGvBC,KAHuB;EAKvB,MAAMC,SAAS,GAAGC,uBAAuB,CAACJ,KAAK,CAACK,OAAP,EAAgBJ,IAAI,CAACK,MAArB,EAA6BJ,KAA7B,CAAzC;;EAEA,IAAIC,SAAJ,EAAe;IACX,IAAIA,SAAS,KAAKD,KAAlB,EAAyB;MACrB,OAAOA,KAAP;KADJ,MAEO,IAAID,IAAI,CAACE,SAAD,CAAJ,IAAmBF,IAAI,CAACE,SAAD,CAAJ,CAAgBI,QAAvC,EAAiD;MACpD,OAAOR,kB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AO,EAAE,CAACX,QAAD,IAAa,CAACc,QAAd,GAAyBsB,WAAW,CAACzC,KAAD,CAApC,GAA8CsC,SAdpD;MAeH7B,GAAG,EAAEmB,QAAQ,CAAC5B,KAAD,CAfV;MAgBHmD,IAAI,EAAE,QAhBH;MAiBHa,KAAK,EACDT,KAAK,GAAG,CAAR,GACM;QACIU,WAAW,KAAKV,KAAK,GAAG;OAFlC,GAIMjB;KAtBd;GAHY,CAAhB;EA6BA,OACI/B,aAAA,KAAA,oBAAQwC;iBAAgB;IAAxB,EACKlC,OAAO,GACJN,aAAA,KAAA;IAAIyC,SAAS,EAAC;GAAd,EACIzC,aAAA,OAAA,MAAA,EACIA,aAAA,CAAC2D,OAAD;IAASC,KAAK,EAAE;GAAhB,CADJ,CADJ,EAII5D,aAAA,OAAA,MAAA,EAAOuB,KAAK,CAACsC,OAAN,CAAcvD,OAArB,CAJJ,CADI,GAOJwC,OAAO,CAACjD,MAAR,GACAiD,OAAO,CAACxB,GAAR,CAAY,CAAC;IAAE8B,QAAF;IAAYG,IAAZ;IAAkB,GAAGO;GAAtB,KACR9D,aAAA,KAAA,oBAAQ8D,YAAR,EACKP,IADL,EAEIvD,aAAA,OAAA;IAAMyC,SAAS,EAAC;GAAhB,EAAgDW,QAAhD,CAFJ,EAGKrC,WAAW,IACRf,aAAA,CAAC+D,QAAD;IACIC,OAAO,EAAEF,WAAW,CAAC,eAAD;IACpBvD,QAAQ,EAAE,MAAM;IAChBkC,SAAS,EAAC;GAHd,CAJR,CADJ,CADA,GAeAzC,aAAA,KAAA;IAAIyC,SAAS,EAAC;GAAd,EACIzC,aAAA,OAAA,MAAA,EAAOuB,KAAK,CAACsC,OAAN,CAAcI,KAArB,CADJ,CAvBR,CADJ;AA8BH,CAxK6B;;;;"}
1
+ {"version":3,"file":"ScrollableList.js","sources":["../../../../src/components/Listbox/ScrollableList.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\nimport { getNextIndexFromKey } from '../../utils/hooks/useListKeyboardNavigation';\nimport { useListScrollTo } from '../../utils/hooks/useListScrollTo';\nimport './ScrollableList.css';\nimport { Spinner } from '../Spinner/Spinner';\nimport { useLocalization } from '../Provider/Provider';\nimport { Checkbox } from '../Checkbox/Checkbox';\nimport { getInputClasses } from '../Input/util';\n\nexport type ScrollableListItemValue = string | number | boolean | null;\n\nexport type ScrollableListItem = {\n /**\n * Set whether the item is disabled.\n * This will both change the style and make the item unselectable\n */\n disabled?: boolean;\n /* Specifies whether the item has child items -- intended for internal use only */\n hasChildren?: boolean;\n /** Place an icon before the item's text */\n icon?: React.ReactElement;\n /* The index path to the item -- intended for internal use only */\n path?: string;\n /** Text describing the item */\n text: string | JSX.Element;\n /** Value of the item */\n value: ScrollableListItemValue;\n /** Child items to show hierarchical data */\n children?: ScrollableListItem[];\n};\n\n/** @internal */\nexport type ScrollableListProps = Omit<\n React.HTMLAttributes<HTMLUListElement>,\n 'defaultValue' | 'id' | 'onChange' | 'onClick' | 'onKeyDown'\n> & {\n /** Data indicating the options in scrollable list */\n data: ScrollableListItem[];\n /** Sets the list to be disabled */\n disabled?: boolean;\n /** Draws attention to the scrollable list by changing its style and making it visually prominent */\n highlighted?: boolean;\n /** Set an id for the scrollable list */\n id: string;\n /* Whether the input is in an invalid state */\n invalid?: boolean;\n /**\n * Shows a loading indicator with a text next to it.\n * Read more about how to provide the text in `Provider` component.\n */\n loading?: boolean;\n /**\n * Handler called when current active/selected option changes in a scrollable list.\n * @param index indicates the index of the current active option\n */\n onChange: (index: number) => void;\n /** Handler called when option is clicked */\n onClick?: (event: React.MouseEvent<HTMLLIElement>, index: number) => void;\n /**\n * Set whether the selected item should be scrolled into view when listbox is focused.\n * Default value is `false`\n */\n scrollOnFocus?: boolean;\n /** Handler called when a key is pressed */\n onKeyDown?: (event: React.KeyboardEvent<HTMLUListElement>, index: number | undefined) => void;\n /* Sets the list to read only mode */\n readOnly?: boolean;\n /**\n * Value of the scrollable list representing the selected item.\n * It needs to be an existing value from the provided data.\n */\n value: number | undefined;\n /**\n * Allows to select multiple items from the list\n */\n multiselect?: boolean;\n /**\n * Contains the currently selected values when multiselect mode is ON.\n */\n selectedIndexes?: number[];\n /**\n * True when all available (not disabled) options are selected\n */\n allOptionsSelected?: boolean;\n};\n\n/** @internal */\nexport type ScrollableListPropsWithRef = ScrollableListProps & React.RefAttributes<HTMLUListElement>;\n\nexport const getId = (id: string, value: ScrollableListItemValue): string => `${id}_${value}`;\n\nconst getNextEnabledItem = (\n event: React.KeyboardEvent<HTMLElement>,\n data: ScrollableListItem[],\n index: number | undefined\n): number | undefined => {\n const nextIndex = getNextIndexFromKey(event.key, data.length, index);\n\n if (nextIndex) {\n if (nextIndex === index) {\n return index;\n } else if (data[nextIndex] && data[nextIndex].disabled) {\n return getNextEnabledItem(event, data, nextIndex);\n }\n }\n\n return nextIndex;\n};\n\nexport const ScrollableList = React.forwardRef(function ScrollableList(\n props: ScrollableListProps,\n ref: React.Ref<HTMLUListElement>\n) {\n const {\n data,\n disabled,\n highlighted,\n id,\n invalid: _,\n loading,\n onChange: setCurrentIndex,\n onClick,\n onFocus,\n onKeyDown,\n readOnly,\n scrollOnFocus = false,\n value: currentIndex,\n multiselect,\n selectedIndexes = [],\n allOptionsSelected = false,\n ...otherProps\n } = props;\n const listRef = useProxiedRef<HTMLUListElement>(ref);\n const itemRefs = React.useMemo(() => data.map(() => React.createRef<HTMLLIElement>()), [data]);\n const { texts } = useLocalization();\n const { scrollTo } = useListScrollTo(listRef, itemRefs);\n\n React.useEffect(() => {\n if (currentIndex && itemRefs[currentIndex]?.current) {\n itemRefs[currentIndex].current?.scrollIntoView({\n block: 'center',\n });\n }\n }, []);\n\n React.useEffect(() => {\n scrollTo(currentIndex);\n }, [currentIndex]);\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLUListElement>): void => {\n const nextIndex = getNextEnabledItem(event, data, currentIndex);\n\n if (nextIndex !== undefined && nextIndex !== currentIndex) {\n event.preventDefault();\n scrollTo(nextIndex);\n setCurrentIndex(nextIndex);\n }\n\n if (onKeyDown) {\n event.persist();\n const index = nextIndex !== undefined ? nextIndex : currentIndex;\n onKeyDown(event, index);\n }\n };\n\n const handleClick = (index: number) => (event: React.MouseEvent<HTMLLIElement>) => {\n setCurrentIndex(index);\n\n if (onClick) {\n event.persist();\n onClick(event, index);\n }\n };\n\n const handleFocus = (event: React.FocusEvent<HTMLUListElement>): void => {\n if (scrollOnFocus) {\n scrollTo(currentIndex);\n }\n\n if (onFocus) {\n event.persist();\n onFocus(event);\n }\n };\n\n const getOptionCheckedState = (optionValue: string, index: number): boolean => {\n if (optionValue === '#ALL-OPTIONS#') {\n return allOptionsSelected;\n } else if (!optionValue || !selectedIndexes) {\n return false;\n } else {\n return selectedIndexes.findIndex(i => i === index) !== -1;\n }\n };\n\n const list: React.HTMLAttributes<HTMLUListElement> &\n React.RefAttributes<HTMLUListElement> & { disabled?: boolean; readOnly?: boolean } = {\n ...otherProps,\n className: cn(\n 'inline-flex flex-col list-none !p-0 m-0 overflow-y-auto h-auto',\n getInputClasses(props),\n {\n 'yt-list--multiselect': multiselect,\n 'pointer-events-none': disabled,\n 'cursor-not-allowed': disabled || readOnly,\n },\n otherProps.className\n ),\n disabled,\n id,\n onFocus: !disabled && !readOnly ? handleFocus : undefined,\n onKeyDown: !disabled && !readOnly ? handleKeyDown : undefined,\n readOnly,\n ref: listRef,\n role: 'listbox',\n tabIndex: otherProps.tabIndex || 0,\n };\n\n const options = data.map((option, index) => {\n const depth = option.path ? option.path.split('.').length - 1 : 0;\n\n return {\n 'aria-selected': multiselect ? getOptionCheckedState(String(option.value), index) : currentIndex === index,\n 'data-focused': currentIndex === index,\n children: option.text,\n className: cn(\n 'flex items-center px-3 w-full cursor-pointer bg-white flex-[0_0_2rem] focus:wcag-blue focus:border-blue',\n {\n 'sticky top-0 font-bold': depth === 0 && !!option.hasChildren,\n }\n ),\n disabled: option.disabled,\n icon: option.icon,\n id: getId(id, option.value),\n key: getId(id, option.value),\n onClick: !disabled && !readOnly ? handleClick(index) : undefined,\n ref: itemRefs[index],\n role: 'option',\n style:\n depth > 0\n ? {\n paddingLeft: `${depth + 1}rem`,\n }\n : undefined,\n };\n });\n\n return (\n <ul {...list} data-taco=\"scrollable-list\">\n {loading ? (\n <li className=\"yt-list__empty\">\n <span>\n <Spinner delay={0} />\n </span>\n <span>{texts.listbox.loading}</span>\n </li>\n ) : options.length ? (\n options.map(({ children, icon, ...optionProps }) => (\n <li {...optionProps}>\n {icon}\n <span className=\"flex-grow truncate text-left\">{children}</span>\n {multiselect && (\n <Checkbox\n checked={optionProps['aria-selected']}\n onChange={() => null}\n className=\"pointer-events-none ml-2 self-center p-px\"\n />\n )}\n </li>\n ))\n ) : (\n <li className=\"yt-list__empty\">\n <span>{texts.listbox.empty}</span>\n </li>\n )}\n </ul>\n );\n});\n"],"names":["getId","id","value","getNextEnabledItem","event","data","index","nextIndex","getNextIndexFromKey","key","length","disabled","ScrollableList","React","props","ref","highlighted","invalid","_","loading","onChange","setCurrentIndex","onClick","onFocus","onKeyDown","readOnly","scrollOnFocus","currentIndex","multiselect","selectedIndexes","allOptionsSelected","otherProps","listRef","useProxiedRef","itemRefs","map","texts","useLocalization","scrollTo","useListScrollTo","current","scrollIntoView","block","handleKeyDown","undefined","preventDefault","persist","handleClick","handleFocus","getOptionCheckedState","optionValue","findIndex","i","list","className","cn","getInputClasses","role","tabIndex","options","option","depth","path","split","String","children","text","hasChildren","icon","style","paddingLeft","Spinner","delay","listbox","optionProps","Checkbox","checked","empty"],"mappings":";;;;;;;;;;MA2FaA,KAAK,GAAG,CAACC,EAAD,EAAaC,KAAb,QAA2DD,MAAMC;;AAEtF,MAAMC,kBAAkB,GAAG,CACvBC,KADuB,EAEvBC,IAFuB,EAGvBC,KAHuB;EAKvB,MAAMC,SAAS,GAAGC,mBAAmB,CAACJ,KAAK,CAACK,GAAP,EAAYJ,IAAI,CAACK,MAAjB,EAAyBJ,KAAz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AK,CAACqC,OAAN,CAAcI,KAArB,CADJ,CAvBR,CADJ;AA8BH,CAxK6B;;;;"}
@@ -61,9 +61,10 @@ const useListbox = ({
61
61
  }, [data]);
62
62
 
63
63
  const handleListboxKeyDown = event => {
64
- const charKey = String.fromCharCode(event.keyCode);
64
+ const charKey = event.key; // event.key always returns the whole string (String.fromCharCode(event.keyCode) does not)
65
+ // We need to filter out only alphabetical or numeric letters, that's why that condition has been changed
65
66
 
66
- if (charKey.match(/(\w)/g)) {
67
+ if (charKey.length === 1 && /(\w)/g.test(charKey)) {
67
68
  const nextIndex = getNextIndex(charKey);
68
69
 
69
70
  if (nextIndex > -1 && nextIndex !== currentIndex) {
@@ -1 +1 @@
1
- {"version":3,"file":"useListbox.js","sources":["../../../../src/components/Listbox/useListbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { v4 as uuid } from 'uuid';\nimport { ListboxProps } from './Listbox';\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\nimport { setInputValueByRef, getIndexFromValue, findByValue, getActiveDescendant, useFlattenedData, sanitizeItem } from './util';\nimport { ScrollableListProps } from './ScrollableList';\nimport { useTypeahead } from './useTypeahead';\n\ntype useListbox = {\n list: ScrollableListProps;\n input: Omit<React.HTMLAttributes<HTMLInputElement>, 'defaultValue'>;\n};\n\nexport const useListbox = (\n {\n data: externalData = [],\n defaultValue,\n disabled,\n emptyValue,\n id: nativeId,\n invalid,\n name,\n onChange,\n onFocus,\n onKeyDown,\n value = emptyValue,\n ...otherProps\n }: ListboxProps,\n ref: React.Ref<HTMLInputElement>\n): useListbox => {\n const data = useFlattenedData(emptyValue !== undefined ? [{ text: '', value: emptyValue }, ...externalData] : externalData);\n const id = React.useMemo(() => nativeId || uuid(), [nativeId]);\n const inputRef = useProxiedRef<HTMLInputElement>(ref);\n const currentIndex = value !== undefined ? getIndexFromValue(data, value) : undefined;\n const { getNextIndex } = useTypeahead({ data, currentIndex });\n\n const setInputValueByIndex = (index: number | undefined): void => {\n if (index !== undefined) {\n const option = data[index];\n\n if (option && !option.disabled) {\n setInputValueByRef(inputRef.current, option.value);\n }\n }\n };\n\n const handleListboxChange = (index: number): void => {\n setInputValueByIndex(index);\n };\n\n React.useEffect(() => {\n if (data.length && currentIndex === undefined) {\n if (defaultValue !== undefined) {\n const defaultValueIndex = getIndexFromValue(data, defaultValue);\n\n if (defaultValueIndex !== undefined) {\n setInputValueByIndex(defaultValueIndex);\n }\n } else {\n setInputValueByIndex(0);\n }\n }\n }, [data]);\n\n const handleListboxKeyDown = (event: React.KeyboardEvent<HTMLElement>): void => {\n const charKey = String.fromCharCode(event.keyCode);\n\n if (charKey.match(/(\\w)/g)) {\n const nextIndex = getNextIndex(charKey);\n\n if (nextIndex > -1 && nextIndex !== currentIndex) {\n setInputValueByIndex(nextIndex);\n }\n return;\n }\n\n if (onKeyDown) {\n event.persist();\n onKeyDown(event);\n }\n };\n\n const handleListboxFocus = (event: React.FocusEvent<HTMLElement>): void => {\n if (currentIndex === undefined && data.length) {\n setInputValueByIndex(0);\n }\n\n if (onFocus) {\n event.persist();\n onFocus(event);\n }\n };\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\n event.persist();\n\n if (onChange) {\n const item = findByValue(data, event.target.value);\n (event as any).detail = sanitizeItem(item);\n\n const indexes = item?.path?.split('.') ?? [];\n\n if (indexes.length > 1) {\n // we don't want to map the current item\n indexes.pop();\n // we need to rebuild the path as we map\n let lastPath: string;\n\n (event as any).detail.parents = indexes.map(i => {\n lastPath = lastPath ? [lastPath, i].join('.') : i;\n return sanitizeItem(data.find(i => i.path === lastPath));\n });\n }\n\n onChange(event);\n }\n };\n\n const list: ScrollableListProps = {\n ...otherProps,\n 'aria-activedescendant': getActiveDescendant(data, currentIndex, id),\n data,\n disabled,\n id,\n invalid,\n onChange: handleListboxChange,\n onFocus: handleListboxFocus,\n onKeyDown: handleListboxKeyDown,\n scrollOnFocus: true,\n tabIndex: disabled ? -1 : otherProps.tabIndex ? otherProps.tabIndex : 0,\n value: currentIndex,\n };\n\n const input = {\n name,\n onChange: handleInputChange,\n ref: inputRef,\n tabIndex: -1,\n value: value ?? '',\n };\n\n return { list, input };\n};\n"],"names":["useListbox","data","externalData","defaultValue","disabled","emptyValue","id","nativeId","invalid","name","onChange","onFocus","onKeyDown","value","otherProps","ref","useFlattenedData","undefined","text","React","uuid","inputRef","useProxiedRef","currentIndex","getIndexFromValue","getNextIndex","useTypeahead","setInputValueByIndex","index","option","setInputValueByRef","current","handleListboxChange","length","defaultValueIndex","handleListboxKeyDown","event","charKey","String","fromCharCode","keyCode","match","nextIndex","persist","handleListboxFocus","handleInputChange","item","findByValue","target","detail","sanitizeItem","indexes","path","split","pop","lastPath","parents","map","i","join","find","list","getActiveDescendant","scrollOnFocus","tabIndex","input"],"mappings":";;;;;;MAaaA,UAAU,GAAG,CACtB;EACIC,IAAI,EAAEC,YAAY,GAAG,EADzB;EAEIC,YAFJ;EAGIC,QAHJ;EAIIC,UAJJ;EAKIC,EAAE,EAAEC,QALR;EAMIC,OANJ;EAOIC,IAPJ;EAQIC,QARJ;EASIC,OATJ;EAUIC,SAVJ;EAWIC,KAAK,GAAGR,UAXZ;EAYI,GAAGS;AAZP,CADsB,EAetBC,GAfsB;EAiBtB,MAAMd,IAAI,GAAGe,gBAAgB,CAACX,UAAU,KAAKY,SAAf,GAA2B,CAAC;IAAEC,IAAI,EAAE,EAAR;IAAYL,KAAK,EAAER;GAApB,EAAkC,GAAGH,YAArC,CAA3B,GAAgFA,YAAjF,CAA7B;EACA,MAAMI,EAAE,GAAGa,OAAA,CAAc,MAAMZ,QAAQ,IAAIa,EAAI,EAApC,EAAwC,CAACb,QAAD,CAAxC,CAAX;EACA,MAAMc,QAAQ,GAAGC,aAAa,CAAmBP,GAAnB,CAA9B;EACA,MAAMQ,YAAY,GAAGV,KAAK,KAAKI,SAAV,GAAsBO,iBAAiB,CAACvB,IAAD,EAAOY,KAAP,CAAvC,GAAuDI,SAA5E;EACA,MAAM;IAAEQ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IAI9BG,QAJ8B;IAK9BE,EAL8B;IAM9BE,OAN8B;IAO9BE,QAAQ,EAAEsB,mBAPoB;IAQ9BrB,OAAO,EAAEiC,kBARqB;IAS9BhC,SAAS,EAAEuB,oBATmB;IAU9B4B,aAAa,EAAE,IAVe;IAW9BC,QAAQ,EAAE5D,QAAQ,GAAG,CAAC,CAAJ,GAAQU,UAAU,CAACkD,QAAX,GAAsBlD,UAAU,CAACkD,QAAjC,GAA4C,CAXxC;IAY9BnD,KAAK,EAAEU;GAZX;EAeA,MAAM0C,KAAK,GAAG;IACVxD,IADU;IAEVC,QAAQ,EAAEmC,iBAFA;IAGV9B,GAAG,EAAEM,QAHK;IAIV2C,QAAQ,EAAE,CAAC,CAJD;IAKVnD,KAAK,EAAEA,KAAF,aAAEA,KAAF,cAAEA,KAAF,GAAW;GALpB;EAQA,OAAO;IAAEgD,IAAF;IAAQI;GAAf;AACH;;;;"}
1
+ {"version":3,"file":"useListbox.js","sources":["../../../../src/components/Listbox/useListbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { v4 as uuid } from 'uuid';\nimport { ListboxProps } from './Listbox';\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\nimport { setInputValueByRef, getIndexFromValue, findByValue, getActiveDescendant, useFlattenedData, sanitizeItem } from './util';\nimport { ScrollableListProps } from './ScrollableList';\nimport { useTypeahead } from './useTypeahead';\n\ntype useListbox = {\n list: ScrollableListProps;\n input: Omit<React.HTMLAttributes<HTMLInputElement>, 'defaultValue'>;\n};\n\nexport const useListbox = (\n {\n data: externalData = [],\n defaultValue,\n disabled,\n emptyValue,\n id: nativeId,\n invalid,\n name,\n onChange,\n onFocus,\n onKeyDown,\n value = emptyValue,\n ...otherProps\n }: ListboxProps,\n ref: React.Ref<HTMLInputElement>\n): useListbox => {\n const data = useFlattenedData(emptyValue !== undefined ? [{ text: '', value: emptyValue }, ...externalData] : externalData);\n const id = React.useMemo(() => nativeId || uuid(), [nativeId]);\n const inputRef = useProxiedRef<HTMLInputElement>(ref);\n const currentIndex = value !== undefined ? getIndexFromValue(data, value) : undefined;\n const { getNextIndex } = useTypeahead({ data, currentIndex });\n\n const setInputValueByIndex = (index: number | undefined): void => {\n if (index !== undefined) {\n const option = data[index];\n\n if (option && !option.disabled) {\n setInputValueByRef(inputRef.current, option.value);\n }\n }\n };\n\n const handleListboxChange = (index: number): void => {\n setInputValueByIndex(index);\n };\n\n React.useEffect(() => {\n if (data.length && currentIndex === undefined) {\n if (defaultValue !== undefined) {\n const defaultValueIndex = getIndexFromValue(data, defaultValue);\n\n if (defaultValueIndex !== undefined) {\n setInputValueByIndex(defaultValueIndex);\n }\n } else {\n setInputValueByIndex(0);\n }\n }\n }, [data]);\n\n const handleListboxKeyDown = (event: React.KeyboardEvent<HTMLElement>): void => {\n const charKey = event.key;\n\n // event.key always returns the whole string (String.fromCharCode(event.keyCode) does not)\n // We need to filter out only alphabetical or numeric letters, that's why that condition has been changed\n if (charKey.length === 1 && /(\\w)/g.test(charKey)) {\n const nextIndex = getNextIndex(charKey);\n\n if (nextIndex > -1 && nextIndex !== currentIndex) {\n setInputValueByIndex(nextIndex);\n }\n return;\n }\n\n if (onKeyDown) {\n event.persist();\n onKeyDown(event);\n }\n };\n\n const handleListboxFocus = (event: React.FocusEvent<HTMLElement>): void => {\n if (currentIndex === undefined && data.length) {\n setInputValueByIndex(0);\n }\n\n if (onFocus) {\n event.persist();\n onFocus(event);\n }\n };\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\n event.persist();\n\n if (onChange) {\n const item = findByValue(data, event.target.value);\n (event as any).detail = sanitizeItem(item);\n\n const indexes = item?.path?.split('.') ?? [];\n\n if (indexes.length > 1) {\n // we don't want to map the current item\n indexes.pop();\n // we need to rebuild the path as we map\n let lastPath: string;\n\n (event as any).detail.parents = indexes.map(i => {\n lastPath = lastPath ? [lastPath, i].join('.') : i;\n return sanitizeItem(data.find(i => i.path === lastPath));\n });\n }\n\n onChange(event);\n }\n };\n\n const list: ScrollableListProps = {\n ...otherProps,\n 'aria-activedescendant': getActiveDescendant(data, currentIndex, id),\n data,\n disabled,\n id,\n invalid,\n onChange: handleListboxChange,\n onFocus: handleListboxFocus,\n onKeyDown: handleListboxKeyDown,\n scrollOnFocus: true,\n tabIndex: disabled ? -1 : otherProps.tabIndex ? otherProps.tabIndex : 0,\n value: currentIndex,\n };\n\n const input = {\n name,\n onChange: handleInputChange,\n ref: inputRef,\n tabIndex: -1,\n value: value ?? '',\n };\n\n return { list, input };\n};\n"],"names":["useListbox","data","externalData","defaultValue","disabled","emptyValue","id","nativeId","invalid","name","onChange","onFocus","onKeyDown","value","otherProps","ref","useFlattenedData","undefined","text","React","uuid","inputRef","useProxiedRef","currentIndex","getIndexFromValue","getNextIndex","useTypeahead","setInputValueByIndex","index","option","setInputValueByRef","current","handleListboxChange","length","defaultValueIndex","handleListboxKeyDown","event","charKey","key","test","nextIndex","persist","handleListboxFocus","handleInputChange","item","findByValue","target","detail","sanitizeItem","indexes","path","split","pop","lastPath","parents","map","i","join","find","list","getActiveDescendant","scrollOnFocus","tabIndex","input"],"mappings":";;;;;;MAaaA,UAAU,GAAG,CACtB;EACIC,IAAI,EAAEC,YAAY,GAAG,EADzB;EAEIC,YAFJ;EAGIC,QAHJ;EAIIC,UAJJ;EAKIC,EAAE,EAAEC,QALR;EAMIC,OANJ;EAOIC,IAPJ;EAQIC,QARJ;EASIC,OATJ;EAUIC,SAVJ;EAWIC,KAAK,GAAGR,UAXZ;EAYI,GAAGS;AAZP,CADsB,EAetBC,GAfsB;EAiBtB,MAAMd,IAAI,GAAGe,gBAAgB,CAACX,UAAU,KAAKY,SAAf,GAA2B,CAAC;IAAEC,IAAI,EAAE,EAAR;IAAYL,KAAK,EAAER;GAApB,EAAkC,GAAGH,YAArC,CAA3B,GAAgFA,YAAjF,CAA7B;EACA,MAAMI,EAAE,GAAGa,OAAA,CAAc,MAAMZ,QAAQ,IAAIa,EAAI,EAApC,EAAwC,CAACb,QAAD,CAA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,CAA/B;;;MAML3C,QAAQ,CAAC0B,KAAD,CAAR;;GArBR;;EAyBA,MAAMuB,IAAI,GAAwB,EAC9B,GAAG7C,UAD2B;IAE9B,yBAAyB8C,mBAAmB,CAAC3D,IAAD,EAAOsB,YAAP,EAAqBjB,EAArB,CAFd;IAG9BL,IAH8B;IAI9BG,QAJ8B;IAK9BE,EAL8B;IAM9BE,OAN8B;IAO9BE,QAAQ,EAAEsB,mBAPoB;IAQ9BrB,OAAO,EAAE+B,kBARqB;IAS9B9B,SAAS,EAAEuB,oBATmB;IAU9B0B,aAAa,EAAE,IAVe;IAW9BC,QAAQ,EAAE1D,QAAQ,GAAG,CAAC,CAAJ,GAAQU,UAAU,CAACgD,QAAX,GAAsBhD,UAAU,CAACgD,QAAjC,GAA4C,CAXxC;IAY9BjD,KAAK,EAAEU;GAZX;EAeA,MAAMwC,KAAK,GAAG;IACVtD,IADU;IAEVC,QAAQ,EAAEiC,iBAFA;IAGV5B,GAAG,EAAEM,QAHK;IAIVyC,QAAQ,EAAE,CAAC,CAJD;IAKVjD,KAAK,EAAEA,KAAF,aAAEA,KAAF,cAAEA,KAAF,GAAW;GALpB;EAQA,OAAO;IAAE8C,IAAF;IAAQI;GAAf;AACH;;;;"}
@@ -2,7 +2,6 @@ import { useMemo, useState, useEffect } from 'react';
2
2
  import { v4 } from 'uuid';
3
3
  import { useLocalization } from '../Provider/Provider.js';
4
4
  import { useProxiedRef } from '../../utils/hooks/useProxiedRef.js';
5
- import keycode from 'keycode';
6
5
  import { getIndexFromValue, getSelectedIndexesFromValue, setInputValueByRef, getActiveDescendant, findByValue } from './util.js';
7
6
  import { useTypeahead } from './useTypeahead.js';
8
7
 
@@ -101,9 +100,10 @@ const useMultiListbox = ({
101
100
  };
102
101
 
103
102
  const handleListboxKeyDown = (event, index) => {
104
- const charKey = String.fromCharCode(event.keyCode);
103
+ const charKey = event.key; // event.key always returns the whole string (String.fromCharCode(event.keyCode) does not)
104
+ // We need to filter out only alphabetical or numeric letters, that's why that condition has been changed
105
105
 
106
- if (charKey.match(/(\w)/g)) {
106
+ if (charKey.length === 1 && /(\w)/g.test(charKey)) {
107
107
  const nextIndex = getNextIndex(charKey);
108
108
 
109
109
  if (nextIndex > -1 && nextIndex !== currentIndex) {
@@ -113,22 +113,22 @@ const useMultiListbox = ({
113
113
  return;
114
114
  }
115
115
 
116
- switch (event.keyCode) {
117
- case keycode('space'):
116
+ switch (event.key) {
117
+ case ' ':
118
118
  {
119
119
  event.preventDefault();
120
120
  setInputValueByIndex(index);
121
121
  break;
122
122
  }
123
123
 
124
- case keycode('enter'):
124
+ case 'Enter':
125
125
  {
126
126
  setInputValueByIndex(index);
127
127
  break;
128
128
  }
129
129
  }
130
130
 
131
- setCurrentIndex(index);
131
+ setCurrentIndex(index !== undefined ? index : 0);
132
132
 
133
133
  if (onKeyDown) {
134
134
  event.persist();
@@ -1 +1 @@
1
- {"version":3,"file":"useMultiListbox.js","sources":["../../../../src/components/Listbox/useMultiListbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport keycode from 'keycode';\nimport { v4 as uuid } from 'uuid';\nimport { useLocalization } from '../Provider/Provider';\nimport { ListboxProps } from './Listbox';\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\nimport { setInputValueByRef, getIndexFromValue, getSelectedIndexesFromValue, findByValue, getActiveDescendant } from './util';\nimport { ScrollableListProps, ScrollableListItem, ScrollableListItemValue } from './ScrollableList';\nimport { useTypeahead } from './useTypeahead';\n\ntype useListbox = {\n list: ScrollableListProps;\n input: Omit<React.HTMLAttributes<HTMLInputElement>, 'defaultValue'>;\n};\n\nexport const useMultiListbox = (\n {\n data: externalData = [],\n defaultValue,\n disabled,\n emptyValue: _,\n id: nativeId,\n name,\n onClick,\n onChange,\n onFocus,\n onKeyDown,\n value,\n ...otherProps\n }: ListboxProps,\n ref: React.Ref<HTMLInputElement>\n): useListbox => {\n const { texts } = useLocalization();\n const id = React.useMemo(() => nativeId || uuid(), [nativeId]);\n const inputRef = useProxiedRef<HTMLInputElement>(ref);\n const data = React.useMemo(() => {\n return [{ text: texts.listbox.allOption, value: '#ALL-OPTIONS#' }, ...externalData];\n }, [externalData]);\n const [currentIndex, setCurrentIndex] = React.useState(getIndexFromValue(data, value) || 0);\n const [allOptionsSelected, setAllOptionsSelected] = React.useState(false);\n const { getNextIndex } = useTypeahead({ data, currentIndex });\n const [selectedIndexes, setSelectedIndexes] = React.useState(getSelectedIndexesFromValue(data, value));\n\n React.useEffect(() => {\n if (defaultValue && !value) {\n setInputValueByRef(inputRef.current, defaultValue.toString());\n }\n }, []);\n\n React.useEffect(() => {\n const selectableItemsCount = data.filter(item => !item.disabled).length - 1;\n\n if (selectableItemsCount === selectedIndexes.length) {\n setAllOptionsSelected(true);\n } else {\n setAllOptionsSelected(false);\n }\n }, [selectedIndexes, data]);\n\n const setInputValueByIndex = (index: number | undefined): void => {\n if (index !== undefined) {\n const option = data[index];\n\n if (option && !option.disabled) {\n let newInputValue: ScrollableListItemValue = '';\n const currentInputValue = inputRef.current?.value;\n const currentValuesArray = currentInputValue?.split(',') || [];\n const optionAlreadySelected = currentValuesArray.findIndex(val => val === String(option.value)) !== -1;\n\n // Handling the select_all option\n if (option.value === '#ALL-OPTIONS#') {\n if (!allOptionsSelected) {\n newInputValue = data\n .filter((option, index) => index !== 0 && !option.disabled)\n .map(option => option.value)\n .join(',');\n } else {\n newInputValue = '';\n }\n } else {\n // Handling rest options\n if (optionAlreadySelected) {\n newInputValue = currentValuesArray.filter(val => val !== String(option.value)).join(',');\n } else {\n newInputValue = currentInputValue ? `${currentInputValue},${option.value}` : option.value;\n }\n }\n\n setInputValueByRef(inputRef.current, newInputValue);\n }\n }\n };\n\n const handleListboxClick = (event: React.MouseEvent<HTMLLIElement>, index: number): void => {\n event.preventDefault();\n\n if (!data[index].disabled) {\n setCurrentIndex(index);\n setInputValueByIndex(index);\n }\n\n if (onClick) {\n onClick(event);\n }\n };\n\n const handleListboxKeyDown = (event: React.KeyboardEvent<HTMLElement>, index: number): void => {\n const charKey = String.fromCharCode(event.keyCode);\n\n if (charKey.match(/(\\w)/g)) {\n const nextIndex = getNextIndex(charKey);\n\n if (nextIndex > -1 && nextIndex !== currentIndex) {\n setCurrentIndex(nextIndex);\n }\n return;\n }\n\n switch (event.keyCode) {\n case keycode('space'): {\n event.preventDefault();\n setInputValueByIndex(index);\n break;\n }\n\n case keycode('enter'): {\n setInputValueByIndex(index);\n break;\n }\n\n default:\n }\n setCurrentIndex(index);\n\n if (onKeyDown) {\n event.persist();\n onKeyDown(event);\n }\n };\n\n const handleListboxFocus = (event: React.FocusEvent<HTMLElement>): void => {\n if (onFocus) {\n event.persist();\n onFocus(event);\n }\n };\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\n event.persist();\n\n setSelectedIndexes(getSelectedIndexesFromValue(data, event.target.value));\n\n if (onChange) {\n const detail: ScrollableListItem[] = [];\n const valuesArray = event.target.value.split(',');\n\n valuesArray.forEach(val => {\n const item = findByValue(data, val);\n if (item) {\n detail.push(item);\n }\n });\n (event as any).detail = detail;\n\n onChange(event);\n }\n };\n\n const list = {\n ...otherProps,\n 'aria-activedescendant': getActiveDescendant(data, currentIndex, id),\n 'aria-multiselectable': true,\n data,\n disabled,\n id,\n onChange: () => null,\n onClick: handleListboxClick,\n onFocus: handleListboxFocus,\n onKeyDown: handleListboxKeyDown,\n scrollOnFocus: false,\n tabIndex: disabled ? -1 : otherProps.tabIndex ? otherProps.tabIndex : 0,\n value: currentIndex,\n selectedIndexes,\n multiselect: true,\n allOptionsSelected,\n };\n\n const input = {\n name,\n onChange: handleInputChange,\n ref: inputRef,\n tabIndex: -1,\n value: value ?? '',\n };\n\n return { list, input };\n};\n"],"names":["useMultiListbox","data","externalData","defaultValue","disabled","emptyValue","_","id","nativeId","name","onClick","onChange","onFocus","onKeyDown","value","otherProps","ref","texts","useLocalization","React","uuid","inputRef","useProxiedRef","text","listbox","allOption","currentIndex","setCurrentIndex","getIndexFromValue","allOptionsSelected","setAllOptionsSelected","getNextIndex","useTypeahead","selectedIndexes","setSelectedIndexes","getSelectedIndexesFromValue","setInputValueByRef","current","toString","selectableItemsCount","filter","item","length","setInputValueByIndex","index","undefined","option","newInputValue","currentInputValue","currentValuesArray","split","optionAlreadySelected","findIndex","val","String","map","join","handleListboxClick","event","preventDefault","handleListboxKeyDown","charKey","fromCharCode","keyCode","match","nextIndex","keycode","persist","handleListboxFocus","handleInputChange","target","detail","valuesArray","forEach","findByValue","push","list","getActiveDescendant","scrollOnFocus","tabIndex","multiselect","input"],"mappings":";;;;;;;;MAeaA,eAAe,GAAG,CAC3B;EACIC,IAAI,EAAEC,YAAY,GAAG,EADzB;EAEIC,YAFJ;EAGIC,QAHJ;EAIIC,UAAU,EAAEC,CAJhB;EAKIC,EAAE,EAAEC,QALR;EAMIC,IANJ;EAOIC,OAPJ;EAQIC,QARJ;EASIC,OATJ;EAUIC,SAVJ;EAWIC,KAXJ;EAYI,GAAGC;AAZP,CAD2B,EAe3BC,GAf2B;EAiB3B,MAAM;IAAEC;MAAUC,eAAe,EAAjC;EACA,MAAMX,EAAE,GAAGY,OAAA,CAAc,MAAMX,QAAQ,IAAIY,EAAI,EAApC,EAAwC,CAACZ,QAAD,CAAxC,CAAX;EACA,MAAMa,QAAQ,GAAGC,aAAa,CAAmBN,GAAnB,CAA9B;EACA,MAAMf,IAAI,GAAGkB,OAAA,CAAc;IACvB,OAAO,CAAC;MAAEI,IAAI,EAAEN,KAAK,CAACO,OAAN,CAAcC,SAAtB;MAAiCX,KAAK,EAAE;KAAzC,EAA4D,GAAGZ,YAA/D,CAAP;GADS,EAEV,CAACA,YAAD,CAFU,CAAb;EAGA,MAAM,CAACwB,YAAD,EAAeC,eAAf,IAAkCR,QAAA,CAAeS,iBAAiB,CAAC3B,IAAD,EAAOa,KAAP,CAAjB,IAAkC,CAAjD,CAAxC;EACA,MAAM,CAACe,kBAAD,EAAqBC,qBAArB,IAA8CX,QAAA,CAAe,KAAf,CAApD;EACA,MA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uBA,MAAvB;MAED5D,QAAQ,CAAC+C,KAAD,CAAR;;GAjBR;;EAqBA,MAAMkB,IAAI,GAAG,EACT,GAAG7D,UADM;IAET,yBAAyB8D,mBAAmB,CAAC5E,IAAD,EAAOyB,YAAP,EAAqBnB,EAArB,CAFnC;IAGT,wBAAwB,IAHf;IAITN,IAJS;IAKTG,QALS;IAMTG,EANS;IAOTI,QAAQ,EAAE,MAAM,IAPP;IAQTD,OAAO,EAAE+C,kBARA;IAST7C,OAAO,EAAEwD,kBATA;IAUTvD,SAAS,EAAE+C,oBAVF;IAWTkB,aAAa,EAAE,KAXN;IAYTC,QAAQ,EAAE3E,QAAQ,GAAG,CAAC,CAAJ,GAAQW,UAAU,CAACgE,QAAX,GAAsBhE,UAAU,CAACgE,QAAjC,GAA4C,CAZ7D;IAaTjE,KAAK,EAAEY,YAbE;IAcTO,eAdS;IAeT+C,WAAW,EAAE,IAfJ;IAgBTnD;GAhBJ;EAmBA,MAAMoD,KAAK,GAAG;IACVxE,IADU;IAEVE,QAAQ,EAAE0D,iBAFA;IAGVrD,GAAG,EAAEK,QAHK;IAIV0D,QAAQ,EAAE,CAAC,CAJD;IAKVjE,KAAK,EAAEA,KAAF,aAAEA,KAAF,cAAEA,KAAF,GAAW;GALpB;EAQA,OAAO;IAAE8D,IAAF;IAAQK;GAAf;AACH;;;;"}
1
+ {"version":3,"file":"useMultiListbox.js","sources":["../../../../src/components/Listbox/useMultiListbox.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport { v4 as uuid } from 'uuid';\r\nimport { useLocalization } from '../Provider/Provider';\r\nimport { ListboxProps } from './Listbox';\r\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\r\nimport { setInputValueByRef, getIndexFromValue, getSelectedIndexesFromValue, findByValue, getActiveDescendant } from './util';\r\nimport { ScrollableListProps, ScrollableListItem, ScrollableListItemValue } from './ScrollableList';\r\nimport { useTypeahead } from './useTypeahead';\r\n\r\ntype useListbox = {\r\n list: ScrollableListProps;\r\n input: Omit<React.HTMLAttributes<HTMLInputElement>, 'defaultValue'>;\r\n};\r\n\r\nexport const useMultiListbox = (\r\n {\r\n data: externalData = [],\r\n defaultValue,\r\n disabled,\r\n emptyValue: _,\r\n id: nativeId,\r\n name,\r\n onClick,\r\n onChange,\r\n onFocus,\r\n onKeyDown,\r\n value,\r\n ...otherProps\r\n }: ListboxProps,\r\n ref: React.Ref<HTMLInputElement>\r\n): useListbox => {\r\n const { texts } = useLocalization();\r\n const id = React.useMemo(() => nativeId || uuid(), [nativeId]);\r\n const inputRef = useProxiedRef<HTMLInputElement>(ref);\r\n const data = React.useMemo(() => {\r\n return [{ text: texts.listbox.allOption, value: '#ALL-OPTIONS#' }, ...externalData];\r\n }, [externalData]);\r\n const [currentIndex, setCurrentIndex] = React.useState(getIndexFromValue(data, value) || 0);\r\n const [allOptionsSelected, setAllOptionsSelected] = React.useState(false);\r\n const { getNextIndex } = useTypeahead({ data, currentIndex });\r\n const [selectedIndexes, setSelectedIndexes] = React.useState(getSelectedIndexesFromValue(data, value));\r\n\r\n React.useEffect(() => {\r\n if (defaultValue && !value) {\r\n setInputValueByRef(inputRef.current, defaultValue.toString());\r\n }\r\n }, []);\r\n\r\n React.useEffect(() => {\r\n const selectableItemsCount = data.filter(item => !item.disabled).length - 1;\r\n\r\n if (selectableItemsCount === selectedIndexes.length) {\r\n setAllOptionsSelected(true);\r\n } else {\r\n setAllOptionsSelected(false);\r\n }\r\n }, [selectedIndexes, data]);\r\n\r\n const setInputValueByIndex = (index: number | undefined): void => {\r\n if (index !== undefined) {\r\n const option = data[index];\r\n\r\n if (option && !option.disabled) {\r\n let newInputValue: ScrollableListItemValue = '';\r\n const currentInputValue = inputRef.current?.value;\r\n const currentValuesArray = currentInputValue?.split(',') || [];\r\n const optionAlreadySelected = currentValuesArray.findIndex(val => val === String(option.value)) !== -1;\r\n\r\n // Handling the select_all option\r\n if (option.value === '#ALL-OPTIONS#') {\r\n if (!allOptionsSelected) {\r\n newInputValue = data\r\n .filter((option, index) => index !== 0 && !option.disabled)\r\n .map(option => option.value)\r\n .join(',');\r\n } else {\r\n newInputValue = '';\r\n }\r\n } else {\r\n // Handling rest options\r\n if (optionAlreadySelected) {\r\n newInputValue = currentValuesArray.filter(val => val !== String(option.value)).join(',');\r\n } else {\r\n newInputValue = currentInputValue ? `${currentInputValue},${option.value}` : option.value;\r\n }\r\n }\r\n\r\n setInputValueByRef(inputRef.current, newInputValue);\r\n }\r\n }\r\n };\r\n\r\n const handleListboxClick = (event: React.MouseEvent<HTMLLIElement>, index: number): void => {\r\n event.preventDefault();\r\n\r\n if (!data[index].disabled) {\r\n setCurrentIndex(index);\r\n setInputValueByIndex(index);\r\n }\r\n\r\n if (onClick) {\r\n onClick(event);\r\n }\r\n };\r\n\r\n const handleListboxKeyDown = (event: React.KeyboardEvent<HTMLElement>, index?: number): void => {\r\n const charKey = event.key;\r\n\r\n // event.key always returns the whole string (String.fromCharCode(event.keyCode) does not)\r\n // We need to filter out only alphabetical or numeric letters, that's why that condition has been changed\r\n if (charKey.length === 1 && /(\\w)/g.test(charKey)) {\r\n const nextIndex = getNextIndex(charKey);\r\n\r\n if (nextIndex > -1 && nextIndex !== currentIndex) {\r\n setCurrentIndex(nextIndex);\r\n }\r\n return;\r\n }\r\n\r\n switch (event.key) {\r\n case ' ': {\r\n event.preventDefault();\r\n setInputValueByIndex(index);\r\n break;\r\n }\r\n\r\n case 'Enter': {\r\n setInputValueByIndex(index);\r\n break;\r\n }\r\n\r\n default:\r\n }\r\n setCurrentIndex(index !== undefined ? index : 0);\r\n\r\n if (onKeyDown) {\r\n event.persist();\r\n onKeyDown(event);\r\n }\r\n };\r\n\r\n const handleListboxFocus = (event: React.FocusEvent<HTMLElement>): void => {\r\n if (onFocus) {\r\n event.persist();\r\n onFocus(event);\r\n }\r\n };\r\n\r\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\r\n event.persist();\r\n\r\n setSelectedIndexes(getSelectedIndexesFromValue(data, event.target.value));\r\n\r\n if (onChange) {\r\n const detail: ScrollableListItem[] = [];\r\n const valuesArray = event.target.value.split(',');\r\n\r\n valuesArray.forEach(val => {\r\n const item = findByValue(data, val);\r\n if (item) {\r\n detail.push(item);\r\n }\r\n });\r\n (event as any).detail = detail;\r\n\r\n onChange(event);\r\n }\r\n };\r\n\r\n const list = {\r\n ...otherProps,\r\n 'aria-activedescendant': getActiveDescendant(data, currentIndex, id),\r\n 'aria-multiselectable': true,\r\n data,\r\n disabled,\r\n id,\r\n onChange: () => null,\r\n onClick: handleListboxClick,\r\n onFocus: handleListboxFocus,\r\n onKeyDown: handleListboxKeyDown,\r\n scrollOnFocus: false,\r\n tabIndex: disabled ? -1 : otherProps.tabIndex ? otherProps.tabIndex : 0,\r\n value: currentIndex,\r\n selectedIndexes,\r\n multiselect: true,\r\n allOptionsSelected,\r\n };\r\n\r\n const input = {\r\n name,\r\n onChange: handleInputChange,\r\n ref: inputRef,\r\n tabIndex: -1,\r\n value: value ?? '',\r\n };\r\n\r\n return { list, input };\r\n};\r\n"],"names":["useMultiListbox","data","externalData","defaultValue","disabled","emptyValue","_","id","nativeId","name","onClick","onChange","onFocus","onKeyDown","value","otherProps","ref","texts","useLocalization","React","uuid","inputRef","useProxiedRef","text","listbox","allOption","currentIndex","setCurrentIndex","getIndexFromValue","allOptionsSelected","setAllOptionsSelected","getNextIndex","useTypeahead","selectedIndexes","setSelectedIndexes","getSelectedIndexesFromValue","setInputValueByRef","current","toString","selectableItemsCount","filter","item","length","setInputValueByIndex","index","undefined","option","newInputValue","currentInputValue","currentValuesArray","split","optionAlreadySelected","findIndex","val","String","map","join","handleListboxClick","event","preventDefault","handleListboxKeyDown","charKey","key","test","nextIndex","persist","handleListboxFocus","handleInputChange","target","detail","valuesArray","forEach","findByValue","push","list","getActiveDescendant","scrollOnFocus","tabIndex","multiselect","input"],"mappings":";;;;;;;MAcaA,eAAe,GAAG,CAC3B;EACIC,IAAI,EAAEC,YAAY,GAAG,EADzB;EAEIC,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,GAAQW,UAAU,CAAC8D,QAAX,GAAsB9D,UAAU,CAAC8D,QAAjC,GAA4C,CAZ7D;IAaT/D,KAAK,EAAEY,YAbE;IAcTO,eAdS;IAeT6C,WAAW,EAAE,IAfJ;IAgBTjD;GAhBJ;EAmBA,MAAMkD,KAAK,GAAG;IACVtE,IADU;IAEVE,QAAQ,EAAEwD,iBAFA;IAGVnD,GAAG,EAAEK,QAHK;IAIVwD,QAAQ,EAAE,CAAC,CAJD;IAKV/D,KAAK,EAAEA,KAAF,aAAEA,KAAF,cAAEA,KAAF,GAAW;GALpB;EAQA,OAAO;IAAE4D,IAAF;IAAQK;GAAf;AACH;;;;"}
@@ -1,4 +1,3 @@
1
- import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose } from '../../_virtual/_rollupPluginBabelHelpers.js';
2
1
  import { useState, useMemo, createElement } from 'react';
3
2
  import { MenuContext } from './Context.js';
4
3
  import { Root } from '@radix-ui/react-dropdown-menu';
@@ -11,39 +10,22 @@ import { RadioGroup } from './components/RadioGroup.js';
11
10
  import { Separator } from './components/Separator.js';
12
11
  import { Header } from './components/Header.js';
13
12
 
14
- var _excluded = ["children", "trigger"];
15
- var Menu = function Menu(externalProps) {
16
- var children = externalProps.children,
17
- trigger = externalProps.trigger,
18
- props = _objectWithoutPropertiesLoose(externalProps, _excluded);
19
-
20
- var _React$useState = useState(false),
21
- open = _React$useState[0],
22
- setOpen = _React$useState[1];
23
-
24
- var _React$useState2 = useState(false),
25
- indented = _React$useState2[0],
26
- setIndented = _React$useState2[1];
27
-
28
- var _React$useState3 = useState(undefined),
29
- minWidth = _React$useState3[0],
30
- _setMinWidth = _React$useState3[1];
31
-
32
- var context = useMemo(function () {
33
- return {
34
- indented: indented,
35
- registerIndentation: function registerIndentation() {
36
- return setIndented(true);
37
- },
38
- minWidth: minWidth,
39
- setMinWidth: function setMinWidth(width) {
40
- return _setMinWidth(width);
41
- },
42
- close: function close() {
43
- return setOpen(false);
44
- }
45
- };
46
- }, [indented, minWidth]);
13
+ const Menu = externalProps => {
14
+ const {
15
+ children,
16
+ trigger,
17
+ ...props
18
+ } = externalProps;
19
+ const [open, setOpen] = useState(false);
20
+ const [indented, setIndented] = useState(false);
21
+ const [minWidth, setMinWidth] = useState(undefined);
22
+ const context = useMemo(() => ({
23
+ indented,
24
+ registerIndentation: () => setIndented(true),
25
+ minWidth,
26
+ setMinWidth: width => setMinWidth(width),
27
+ close: () => setOpen(false)
28
+ }), [indented, minWidth]);
47
29
  return createElement(MenuContext.Provider, {
48
30
  value: context
49
31
  }, createElement(Root, Object.assign({}, props, {
@@ -1 +1 @@
1
- {"version":3,"file":"Menu.js","sources":["../../../../src/components/Menu/Menu.tsx"],"sourcesContent":["import * as React from 'react';\nimport * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';\nimport { MenuContext } from './Context';\nimport { Content } from './components/Content';\nimport { Item } from './components/Item';\nimport { Link } from './components/Link';\nimport { Trigger } from './components/Trigger';\nimport { Checkbox } from './components/Checkbox';\nimport { RadioGroup } from './components/RadioGroup';\nimport { Separator } from './components/Separator';\nimport { Header } from './components/Header';\n\nexport type MenuProps = {\n children: React.ReactNode;\n id?: string;\n /** A trigger to be used for the menu, should not be set if `children` already contains a trigger */\n trigger?: JSX.Element;\n};\n\nexport const Menu = (externalProps: MenuProps): JSX.Element => {\n const { children, trigger, ...props } = externalProps;\n const [open, setOpen] = React.useState(false);\n const [indented, setIndented] = React.useState(false);\n const [minWidth, setMinWidth] = React.useState<number | undefined>(undefined);\n\n const context = React.useMemo(\n () => ({\n indented,\n registerIndentation: () => setIndented(true),\n minWidth,\n setMinWidth: (width: number) => setMinWidth(width),\n close: () => setOpen(false),\n }),\n [indented, minWidth]\n );\n\n return (\n <MenuContext.Provider value={context}>\n <DropdownMenuPrimitive.Root {...props} modal={false} open={open} onOpenChange={setOpen}>\n {trigger && <Trigger>{trigger}</Trigger>}\n {children}\n </DropdownMenuPrimitive.Root>\n </MenuContext.Provider>\n );\n};\nMenu.Trigger = Trigger;\nMenu.Content = Content;\nMenu.Item = Item;\nMenu.Link = Link;\nMenu.Checkbox = Checkbox;\nMenu.Separator = Separator;\nMenu.Header = Header;\nMenu.RadioGroup = RadioGroup;\n"],"names":["Menu","externalProps","children","trigger","props","React","open","setOpen","indented","setIndented","undefined","minWidth","setMinWidth","context","registerIndentation","width","close","MenuContext","Provider","value","DropdownMenuPrimitive","modal","onOpenChange","Trigger","Content","Item","Link","Checkbox","Separator","Header","RadioGroup"],"mappings":";;;;;;;;;;;;;;IAmBaA,IAAI,GAAG,SAAPA,IAAO,CAACC,aAAD;EAChB,IAAQC,QAAR,GAAwCD,aAAxC,CAAQC,QAAR;MAAkBC,OAAlB,GAAwCF,aAAxC,CAAkBE,OAAlB;MAA8BC,KAA9B,iCAAwCH,aAAxC;;EACA,sBAAwBI,QAAA,CAAe,KAAf,CAAxB;MAAOC,IAAP;MAAaC,OAAb;;EACA,uBAAgCF,QAAA,CAAe,KAAf,CAAhC;MAAOG,QAAP;MAAiBC,WAAjB;;EACA,uBAAgCJ,QAAA,CAAmCK,SAAnC,CAAhC;MAAOC,QAAP;MAAiBC,YAAjB;;EAEA,IAAMC,OAAO,GAAGR,OAAA,CACZ;IAAA,OAAO;MACHG,QAAQ,EAARA,QADG;MAEHM,mBAAmB,EAAE;QAAA,OAAML,WAAW,CAAC,IAAD,CAAjB;OAFlB;MAGHE,QAAQ,EAARA,QAHG;MAIHC,WAAW,EAAE,qBAACG,KAAD;QAAA,OAAmBH,YAAW,CAACG,KAAD,CAA9B;OAJV;MAKHC,KAAK,EAAE;QAAA,OAAMT,OAAO,CAAC,KAAD,CAAb;;KALX;GADY,EAQZ,CAACC,QAAD,EAAWG,QAAX,CARY,CAAhB;EAWA,OACIN,aAAA,CAACY,WAAW,CAACC,QAAb;IAAsBC,KAAK,EAAEN;GAA7B,EACIR,aAAA,CAACe,IAAD,oBAAgChB;IAAOiB,KAAK,EAAE;IAAOf,IAAI,EAAEA;IAAMgB,YAAY,EAAEf;IAA/E,EACKJ,OAAO,IAAIE,aAAA,CAACkB,OAAD,MAAA,EAAUpB,OAAV,CADhB,EAEKD,QAFL,CADJ,CADJ;AAQH;AACDF,IAAI,CAACuB,OAAL,GAAeA,OAAf;AACAvB,IAAI,CAACwB,OAAL,GAAeA,OAAf;AACAxB,IAAI,CAACyB,IAAL,GAAYA,IAAZ;AACAzB,IAAI,CAAC0B,IAAL,GAAYA,IAAZ;AACA1B,IAAI,CAAC2B,QAAL,GAAgBA,QAAhB;AACA3B,IAAI,CAAC4B,SAAL,GAAiBA,SAAjB;AACA5B,IAAI,CAAC6B,MAAL,GAAcA,MAAd;AACA7B,IAAI,CAAC8B,UAAL,GAAkBA,UAAlB;;;;"}
1
+ {"version":3,"file":"Menu.js","sources":["../../../../src/components/Menu/Menu.tsx"],"sourcesContent":["import * as React from 'react';\nimport * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';\nimport { MenuContext } from './Context';\nimport { Content } from './components/Content';\nimport { Item } from './components/Item';\nimport { Link } from './components/Link';\nimport { Trigger } from './components/Trigger';\nimport { Checkbox } from './components/Checkbox';\nimport { RadioGroup } from './components/RadioGroup';\nimport { Separator } from './components/Separator';\nimport { Header } from './components/Header';\n\nexport type MenuProps = {\n children: React.ReactNode;\n id?: string;\n /** A trigger to be used for the menu, should not be set if `children` already contains a trigger */\n trigger?: JSX.Element;\n};\n\nexport const Menu = (externalProps: MenuProps): JSX.Element => {\n const { children, trigger, ...props } = externalProps;\n const [open, setOpen] = React.useState(false);\n const [indented, setIndented] = React.useState(false);\n const [minWidth, setMinWidth] = React.useState<number | undefined>(undefined);\n\n const context = React.useMemo(\n () => ({\n indented,\n registerIndentation: () => setIndented(true),\n minWidth,\n setMinWidth: (width: number) => setMinWidth(width),\n close: () => setOpen(false),\n }),\n [indented, minWidth]\n );\n\n return (\n <MenuContext.Provider value={context}>\n <DropdownMenuPrimitive.Root {...props} modal={false} open={open} onOpenChange={setOpen}>\n {trigger && <Trigger>{trigger}</Trigger>}\n {children}\n </DropdownMenuPrimitive.Root>\n </MenuContext.Provider>\n );\n};\nMenu.Trigger = Trigger;\nMenu.Content = Content;\nMenu.Item = Item;\nMenu.Link = Link;\nMenu.Checkbox = Checkbox;\nMenu.Separator = Separator;\nMenu.Header = Header;\nMenu.RadioGroup = RadioGroup;\n"],"names":["Menu","externalProps","children","trigger","props","open","setOpen","React","indented","setIndented","minWidth","setMinWidth","undefined","context","registerIndentation","width","close","MenuContext","Provider","value","DropdownMenuPrimitive","modal","onOpenChange","Trigger","Content","Item","Link","Checkbox","Separator","Header","RadioGroup"],"mappings":";;;;;;;;;;;;MAmBaA,IAAI,GAAIC,aAAD;EAChB,MAAM;IAAEC,QAAF;IAAYC,OAAZ;IAAqB,GAAGC;MAAUH,aAAxC;EACA,MAAM,CAACI,IAAD,EAAOC,OAAP,IAAkBC,QAAA,CAAe,KAAf,CAAxB;EACA,MAAM,CAACC,QAAD,EAAWC,WAAX,IAA0BF,QAAA,CAAe,KAAf,CAAhC;EACA,MAAM,CAACG,QAAD,EAAWC,WAAX,IAA0BJ,QAAA,CAAmCK,SAAnC,CAAhC;EAEA,MAAMC,OAAO,GAAGN,OAAA,CACZ,OAAO;IACHC,QADG;IAEHM,mBAAmB,EAAE,MAAML,WAAW,CAAC,IAAD,CAFnC;IAGHC,QAHG;IAIHC,WAAW,EAAGI,KAAD,IAAmBJ,WAAW,CAACI,KAAD,CAJxC;IAKHC,KAAK,EAAE,MAAMV,OAAO,CAAC,KAAD;GALxB,CADY,EAQZ,CAACE,QAAD,EAAWE,QAAX,CARY,CAAhB;EAWA,OACIH,aAAA,CAACU,WAAW,CAACC,QAAb;IAAsBC,KAAK,EAAEN;GAA7B,EACIN,aAAA,CAACa,IAAD,oBAAgChB;IAAOiB,KAAK,EAAE;IAAOhB,IAAI,EAAEA;IAAMiB,YAAY,EAAEhB;IAA/E,EACKH,OAAO,IAAII,aAAA,CAACgB,OAAD,MAAA,EAAUpB,OAAV,CADhB,EAEKD,QAF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