@pega/cosmos-react-core 5.0.0-dev.9.3 → 6.0.1

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 (219) hide show
  1. package/SECURITY.md +11 -0
  2. package/lib/components/AppShell/AppShell.js +1 -1
  3. package/lib/components/AppShell/AppShell.js.map +1 -1
  4. package/lib/components/AppShell/Drawer.d.ts.map +1 -1
  5. package/lib/components/AppShell/Drawer.js +3 -3
  6. package/lib/components/AppShell/Drawer.js.map +1 -1
  7. package/lib/components/AppShell/Operator.d.ts.map +1 -1
  8. package/lib/components/AppShell/Operator.js +5 -2
  9. package/lib/components/AppShell/Operator.js.map +1 -1
  10. package/lib/components/Badges/Keyboard.d.ts.map +1 -1
  11. package/lib/components/Badges/Keyboard.js +10 -10
  12. package/lib/components/Badges/Keyboard.js.map +1 -1
  13. package/lib/components/Badges/Status.d.ts.map +1 -1
  14. package/lib/components/Badges/Status.js +2 -0
  15. package/lib/components/Badges/Status.js.map +1 -1
  16. package/lib/components/Banner/Banner.d.ts +5 -3
  17. package/lib/components/Banner/Banner.d.ts.map +1 -1
  18. package/lib/components/Banner/Banner.js +22 -15
  19. package/lib/components/Banner/Banner.js.map +1 -1
  20. package/lib/components/Banner/Banner.test-ids.d.ts +2 -0
  21. package/lib/components/Banner/Banner.test-ids.d.ts.map +1 -0
  22. package/lib/components/Banner/Banner.test-ids.js +10 -0
  23. package/lib/components/Banner/Banner.test-ids.js.map +1 -0
  24. package/lib/components/Button/Button.js +1 -1
  25. package/lib/components/Button/Button.js.map +1 -1
  26. package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.js +1 -1
  27. package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.js.map +1 -1
  28. package/lib/components/Configuration/Configuration.d.ts +3 -0
  29. package/lib/components/Configuration/Configuration.d.ts.map +1 -1
  30. package/lib/components/Configuration/Configuration.js +20 -12
  31. package/lib/components/Configuration/Configuration.js.map +1 -1
  32. package/lib/components/Configuration/index.d.ts +1 -0
  33. package/lib/components/Configuration/index.d.ts.map +1 -1
  34. package/lib/components/Configuration/index.js +1 -0
  35. package/lib/components/Configuration/index.js.map +1 -1
  36. package/lib/components/Configuration/withConfiguration.d.ts +8 -0
  37. package/lib/components/Configuration/withConfiguration.d.ts.map +1 -0
  38. package/lib/components/Configuration/withConfiguration.js +9 -0
  39. package/lib/components/Configuration/withConfiguration.js.map +1 -0
  40. package/lib/components/DateTime/DateTime.types.d.ts +1 -4
  41. package/lib/components/DateTime/DateTime.types.d.ts.map +1 -1
  42. package/lib/components/DateTime/DateTime.types.js.map +1 -1
  43. package/lib/components/DateTime/DurationDisplay.d.ts +7 -3
  44. package/lib/components/DateTime/DurationDisplay.d.ts.map +1 -1
  45. package/lib/components/DateTime/DurationDisplay.js +2 -2
  46. package/lib/components/DateTime/DurationDisplay.js.map +1 -1
  47. package/lib/components/DateTime/Input/DateInput.d.ts +3 -5
  48. package/lib/components/DateTime/Input/DateInput.d.ts.map +1 -1
  49. package/lib/components/DateTime/Input/DateInput.js +2 -17
  50. package/lib/components/DateTime/Input/DateInput.js.map +1 -1
  51. package/lib/components/DateTime/Input/DateRangeInput.d.ts +2 -4
  52. package/lib/components/DateTime/Input/DateRangeInput.d.ts.map +1 -1
  53. package/lib/components/DateTime/Input/DateRangeInput.js +33 -84
  54. package/lib/components/DateTime/Input/DateRangeInput.js.map +1 -1
  55. package/lib/components/DateTime/Input/DateTime.styles.d.ts.map +1 -1
  56. package/lib/components/DateTime/Input/DateTime.styles.js +2 -1
  57. package/lib/components/DateTime/Input/DateTime.styles.js.map +1 -1
  58. package/lib/components/DateTime/Input/DateTimeInput.d.ts +3 -0
  59. package/lib/components/DateTime/Input/DateTimeInput.d.ts.map +1 -1
  60. package/lib/components/DateTime/Input/DateTimeInput.js +17 -36
  61. package/lib/components/DateTime/Input/DateTimeInput.js.map +1 -1
  62. package/lib/components/DateTime/Input/Duration/NumberUnit.d.ts.map +1 -1
  63. package/lib/components/DateTime/Input/Duration/NumberUnit.js +2 -1
  64. package/lib/components/DateTime/Input/Duration/NumberUnit.js.map +1 -1
  65. package/lib/components/DateTime/Input/MonthInput.d.ts +5 -0
  66. package/lib/components/DateTime/Input/MonthInput.d.ts.map +1 -1
  67. package/lib/components/DateTime/Input/MonthInput.js +14 -6
  68. package/lib/components/DateTime/Input/MonthInput.js.map +1 -1
  69. package/lib/components/DateTime/Input/PartInput.js +1 -1
  70. package/lib/components/DateTime/Input/PartInput.js.map +1 -1
  71. package/lib/components/DateTime/Input/QuarterInput.d.ts.map +1 -1
  72. package/lib/components/DateTime/Input/QuarterInput.js +5 -0
  73. package/lib/components/DateTime/Input/QuarterInput.js.map +1 -1
  74. package/lib/components/DateTime/Input/TimeInput.d.ts.map +1 -1
  75. package/lib/components/DateTime/Input/TimeInput.js +13 -24
  76. package/lib/components/DateTime/Input/TimeInput.js.map +1 -1
  77. package/lib/components/DateTime/Input/TimeRangeInput.d.ts +2 -4
  78. package/lib/components/DateTime/Input/TimeRangeInput.d.ts.map +1 -1
  79. package/lib/components/DateTime/Input/TimeRangeInput.js +25 -64
  80. package/lib/components/DateTime/Input/TimeRangeInput.js.map +1 -1
  81. package/lib/components/DateTime/Input/utils.d.ts +3 -2
  82. package/lib/components/DateTime/Input/utils.d.ts.map +1 -1
  83. package/lib/components/DateTime/Input/utils.js +19 -16
  84. package/lib/components/DateTime/Input/utils.js.map +1 -1
  85. package/lib/components/DateTime/Picker/DatePicker.d.ts.map +1 -1
  86. package/lib/components/DateTime/Picker/DatePicker.js +3 -3
  87. package/lib/components/DateTime/Picker/DatePicker.js.map +1 -1
  88. package/lib/components/DateTime/Picker/DatePicker.styles.d.ts +2 -0
  89. package/lib/components/DateTime/Picker/DatePicker.styles.d.ts.map +1 -1
  90. package/lib/components/DateTime/Picker/DatePicker.styles.js +37 -1
  91. package/lib/components/DateTime/Picker/DatePicker.styles.js.map +1 -1
  92. package/lib/components/DateTime/Picker/DateRangePicker.d.ts.map +1 -1
  93. package/lib/components/DateTime/Picker/DateRangePicker.js +3 -3
  94. package/lib/components/DateTime/Picker/DateRangePicker.js.map +1 -1
  95. package/lib/components/DateTime/Picker/TimePicker.js +1 -1
  96. package/lib/components/DateTime/Picker/TimePicker.js.map +1 -1
  97. package/lib/components/DateTime/utils.d.ts +13 -2
  98. package/lib/components/DateTime/utils.d.ts.map +1 -1
  99. package/lib/components/DateTime/utils.js +7 -13
  100. package/lib/components/DateTime/utils.js.map +1 -1
  101. package/lib/components/Dialog/FormDialog.js +1 -1
  102. package/lib/components/Dialog/FormDialog.js.map +1 -1
  103. package/lib/components/Dialog/InfoDialog.js +1 -1
  104. package/lib/components/Dialog/InfoDialog.js.map +1 -1
  105. package/lib/components/FieldGroup/FieldGroupList.d.ts.map +1 -1
  106. package/lib/components/FieldGroup/FieldGroupList.js +5 -2
  107. package/lib/components/FieldGroup/FieldGroupList.js.map +1 -1
  108. package/lib/components/FormField/FormField.d.ts +1 -0
  109. package/lib/components/FormField/FormField.d.ts.map +1 -1
  110. package/lib/components/FormField/FormField.js +1 -1
  111. package/lib/components/FormField/FormField.js.map +1 -1
  112. package/lib/components/HTML/HTML.js +1 -1
  113. package/lib/components/HTML/HTML.js.map +1 -1
  114. package/lib/components/Lightbox/Lightbox.d.ts +1 -1
  115. package/lib/components/Lightbox/Lightbox.d.ts.map +1 -1
  116. package/lib/components/Lightbox/Lightbox.js +66 -19
  117. package/lib/components/Lightbox/Lightbox.js.map +1 -1
  118. package/lib/components/Lightbox/Lightbox.styles.d.ts +3 -3
  119. package/lib/components/Lightbox/Lightbox.styles.d.ts.map +1 -1
  120. package/lib/components/Lightbox/Lightbox.styles.js +29 -16
  121. package/lib/components/Lightbox/Lightbox.styles.js.map +1 -1
  122. package/lib/components/Lightbox/Lightbox.test-ids.d.ts +1 -1
  123. package/lib/components/Lightbox/Lightbox.test-ids.d.ts.map +1 -1
  124. package/lib/components/Lightbox/Lightbox.test-ids.js +3 -1
  125. package/lib/components/Lightbox/Lightbox.test-ids.js.map +1 -1
  126. package/lib/components/Lightbox/Lightbox.types.d.ts +19 -8
  127. package/lib/components/Lightbox/Lightbox.types.d.ts.map +1 -1
  128. package/lib/components/Lightbox/Lightbox.types.js.map +1 -1
  129. package/lib/components/ListToolbar/ListToolbar.d.ts +1 -1
  130. package/lib/components/ListToolbar/ListToolbar.d.ts.map +1 -1
  131. package/lib/components/ListToolbar/ListToolbar.js +61 -51
  132. package/lib/components/ListToolbar/ListToolbar.js.map +1 -1
  133. package/lib/components/ListToolbar/ListToolbar.styles.d.ts +4 -0
  134. package/lib/components/ListToolbar/ListToolbar.styles.d.ts.map +1 -1
  135. package/lib/components/ListToolbar/ListToolbar.styles.js +41 -8
  136. package/lib/components/ListToolbar/ListToolbar.styles.js.map +1 -1
  137. package/lib/components/ListToolbar/ListToolbar.test-ids.d.ts +1 -1
  138. package/lib/components/ListToolbar/ListToolbar.test-ids.d.ts.map +1 -1
  139. package/lib/components/ListToolbar/ListToolbar.test-ids.js +2 -1
  140. package/lib/components/ListToolbar/ListToolbar.test-ids.js.map +1 -1
  141. package/lib/components/ListToolbar/ListToolbar.types.d.ts +1 -1
  142. package/lib/components/ListToolbar/ListToolbar.types.d.ts.map +1 -1
  143. package/lib/components/ListToolbar/ListToolbar.types.js.map +1 -1
  144. package/lib/components/Menu/MenuItem.js +1 -1
  145. package/lib/components/Menu/MenuItem.js.map +1 -1
  146. package/lib/components/MenuButton/MenuButton.d.ts.map +1 -1
  147. package/lib/components/MenuButton/MenuButton.js +8 -4
  148. package/lib/components/MenuButton/MenuButton.js.map +1 -1
  149. package/lib/components/Modal/MinimizedModal.d.ts.map +1 -1
  150. package/lib/components/Modal/MinimizedModal.js +3 -3
  151. package/lib/components/Modal/MinimizedModal.js.map +1 -1
  152. package/lib/components/Modal/Modal.d.ts.map +1 -1
  153. package/lib/components/Modal/Modal.js +4 -4
  154. package/lib/components/Modal/Modal.js.map +1 -1
  155. package/lib/components/MultiStepForm/FormProgress.styles.d.ts +2 -0
  156. package/lib/components/MultiStepForm/FormProgress.styles.d.ts.map +1 -1
  157. package/lib/components/MultiStepForm/FormProgress.styles.js +26 -2
  158. package/lib/components/MultiStepForm/FormProgress.styles.js.map +1 -1
  159. package/lib/components/MultiStepForm/HorizontalFormProgress.d.ts +0 -1
  160. package/lib/components/MultiStepForm/HorizontalFormProgress.d.ts.map +1 -1
  161. package/lib/components/MultiStepForm/HorizontalFormProgress.js +26 -29
  162. package/lib/components/MultiStepForm/HorizontalFormProgress.js.map +1 -1
  163. package/lib/components/MultiStepForm/MultiStepForm.d.ts.map +1 -1
  164. package/lib/components/MultiStepForm/MultiStepForm.js +27 -11
  165. package/lib/components/MultiStepForm/MultiStepForm.js.map +1 -1
  166. package/lib/components/NoValue/NoValue.d.ts.map +1 -1
  167. package/lib/components/NoValue/NoValue.js +6 -1
  168. package/lib/components/NoValue/NoValue.js.map +1 -1
  169. package/lib/components/Popover/Popover.d.ts.map +1 -1
  170. package/lib/components/Popover/Popover.js +9 -0
  171. package/lib/components/Popover/Popover.js.map +1 -1
  172. package/lib/components/RadioCheck/RadioCheck.d.ts.map +1 -1
  173. package/lib/components/RadioCheck/RadioCheck.js +3 -1
  174. package/lib/components/RadioCheck/RadioCheck.js.map +1 -1
  175. package/lib/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
  176. package/lib/components/SearchInput/SearchInput.styles.js +15 -0
  177. package/lib/components/SearchInput/SearchInput.styles.js.map +1 -1
  178. package/lib/components/ShortcutManager/ShortcutManager.js +1 -1
  179. package/lib/components/ShortcutManager/ShortcutManager.js.map +1 -1
  180. package/lib/components/TextArea/TextArea.d.ts +1 -1
  181. package/lib/components/TextArea/TextArea.d.ts.map +1 -1
  182. package/lib/components/TextArea/TextArea.js +16 -8
  183. package/lib/components/TextArea/TextArea.js.map +1 -1
  184. package/lib/components/TextArea/TextArea.styles.d.ts +1 -0
  185. package/lib/components/TextArea/TextArea.styles.d.ts.map +1 -1
  186. package/lib/components/TextArea/TextArea.styles.js +32 -4
  187. package/lib/components/TextArea/TextArea.styles.js.map +1 -1
  188. package/lib/components/Tooltip/Tooltip.js +1 -1
  189. package/lib/components/Tooltip/Tooltip.js.map +1 -1
  190. package/lib/hooks/useArrows.d.ts +2 -1
  191. package/lib/hooks/useArrows.d.ts.map +1 -1
  192. package/lib/hooks/useArrows.js +47 -22
  193. package/lib/hooks/useArrows.js.map +1 -1
  194. package/lib/hooks/useFocusTrap.d.ts.map +1 -1
  195. package/lib/hooks/useFocusTrap.js +30 -3
  196. package/lib/hooks/useFocusTrap.js.map +1 -1
  197. package/lib/hooks/useFocusWithin.d.ts.map +1 -1
  198. package/lib/hooks/useFocusWithin.js +13 -3
  199. package/lib/hooks/useFocusWithin.js.map +1 -1
  200. package/lib/hooks/useI18n.d.ts +17 -0
  201. package/lib/hooks/useI18n.d.ts.map +1 -1
  202. package/lib/i18n/default.d.ts +17 -0
  203. package/lib/i18n/default.d.ts.map +1 -1
  204. package/lib/i18n/default.js +21 -2
  205. package/lib/i18n/default.js.map +1 -1
  206. package/lib/i18n/i18n.d.ts +17 -0
  207. package/lib/i18n/i18n.d.ts.map +1 -1
  208. package/lib/styles/GlobalStyle.d.ts.map +1 -1
  209. package/lib/styles/GlobalStyle.js +11 -1
  210. package/lib/styles/GlobalStyle.js.map +1 -1
  211. package/lib/utils/focusHeadingOrContainer.d.ts +1 -1
  212. package/lib/utils/focusHeadingOrContainer.d.ts.map +1 -1
  213. package/lib/utils/focusHeadingOrContainer.js +1 -1
  214. package/lib/utils/focusHeadingOrContainer.js.map +1 -1
  215. package/lib/utils/getFocusables.d.ts +7 -3
  216. package/lib/utils/getFocusables.d.ts.map +1 -1
  217. package/lib/utils/getFocusables.js +31 -9
  218. package/lib/utils/getFocusables.js.map +1 -1
  219. package/package.json +5 -4
@@ -11,6 +11,10 @@ export const StyledSearchButton = styled(BareButton)(({ theme: { base } }) => {
11
11
  return css `
12
12
  padding-inline-start: ${base.spacing};
13
13
  color: ${iconColor};
14
+
15
+ @media (pointer: coarse) {
16
+ padding-inline-start: calc(3 * ${base.spacing});
17
+ }
14
18
  `;
15
19
  });
16
20
  StyledSearchButton.defaultProps = defaultThemeProp;
@@ -45,6 +49,12 @@ export const StyledCancelButton = styled(Button)(({ theme }) => {
45
49
  (${theme.components.input.height} - ${theme.base['hit-area'].compact}) / 2
46
50
  );
47
51
  z-index: 3;
52
+
53
+ @media (pointer: coarse) {
54
+ inset-block-start: calc(
55
+ (${theme.base['hit-area']['finger-min']} - ${theme.base['hit-area'].compact}) / 2
56
+ );
57
+ }
48
58
  `;
49
59
  });
50
60
  StyledCancelButton.defaultProps = defaultThemeProp;
@@ -119,6 +129,11 @@ export const StyledSearchInput = styled.div(({ theme: { base, components: { inpu
119
129
  box-shadow: ${formControl[':focus']['box-shadow']};
120
130
  }
121
131
  `}
132
+
133
+ @media (pointer: coarse) {
134
+ min-height: ${base['hit-area']['finger-min']};
135
+ min-width: ${base['hit-area']['finger-min']};
136
+ }
122
137
  `;
123
138
  });
124
139
  StyledSearchInput.defaultProps = defaultThemeProp;
@@ -1 +1 @@
1
- {"version":3,"file":"SearchInput.styles.js","sourceRoot":"","sources":["../../../src/components/SearchInput/SearchInput.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,UAAU,MAAM,sBAAsB,CAAC;AAC9C,OAAO,KAAK,MAAM,UAAU,CAAC;AAE7B,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,E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A,WAAW,CAAC,eAAe,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC;QAC3E,UAAU;QACV,CAAC,CAAC,GAAG,CAAA;;WAEF;QACH,CAAC,CAAC,GAAG,CAAA;sBACS,KAAK,CAAC,cAAc,CAAC,UAAU,KAAK,CAAC,cAAc,CAAC;WAC/D;;QAEH,CAAC,UAAU;QACb,GAAG,CAAA;;0BAEiB,IAAI,CAAC,OAAO,CAAC,KAAK;wBACpB,WAAW,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC;;OAEpD;KACF,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,iBAAiB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAElD,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;CAIzC,CAAC;AAEF,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAC,GAAG,CAAA;iBACrC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO;CACjD,CAAC;AAEF,4BAA4B,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE7D,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAA,EAAE,CAAC;AAEjD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAA,EAAE,CAAC","sourcesContent":["import { transparentize } from 'polished';\nimport styled, { css } from 'styled-components';\n\nimport MenuButton from '../MenuButton';\nimport { defaultThemeProp } from '../../theme';\nimport { tryCatch } from '../../utils';\nimport Button from '../Button';\nimport BareButton from '../Button/BareButton';\nimport Input from '../Input';\n\nexport const StyledSearchButton = styled(BareButton)(({ theme: { base } }) => {\n const iconColor = tryCatch(() => transparentize(0.3, base.palette['foreground-color']));\n return css`\n padding-inline-start: ${base.spacing};\n color: ${iconColor};\n `;\n});\n\nStyledSearchButton.defaultProps = defaultThemeProp;\n\nexport const StyledMenuButton = styled(MenuButton)(\n ({\n theme: {\n base,\n components: { 'search-input': searchInput, 'form-control': formControl, input }\n }\n }) => {\n const iconColor = tryCatch(() => transparentize(0.3, base.palette['foreground-color']));\n return css`\n border-start-start-radius: calc(${base['border-radius']} * ${searchInput['border-radius']});\n border-end-start-radius: calc(${base['border-radius']} * ${searchInput['border-radius']});\n padding-inline-start: ${base.spacing};\n border: ${input['border-width']} solid ${input['border-color']};\n color: ${iconColor};\n position: relative;\n z-index: 2;\n &:hover {\n text-decoration: none;\n }\n\n &:focus:enabled {\n border-color: ${formControl[':focus']['border-color']};\n box-shadow: ${formControl[':focus']['box-shadow']};\n }\n `;\n }\n);\n\nStyledMenuButton.defaultProps = defaultThemeProp;\n\nexport const StyledCancelButton = styled(Button)(({ theme }) => {\n return css`\n position: absolute;\n inset-inline-end: calc(\n (${theme.base['hit-area'].finger} - ${theme.base['hit-area'].compact}) / 2\n );\n inset-block-start: calc(\n (${theme.components.input.height} - ${theme.base['hit-area'].compact}) / 2\n );\n z-index: 3;\n `;\n});\n\nStyledCancelButton.defaultProps = defaultThemeProp;\n\nexport const StyledSearchTextInput = styled(Input)<{ decoupled: boolean }>(props => {\n const { theme, decoupled } = props;\n const comp = theme.components['search-input'];\n return css`\n flex: 1;\n background: transparent;\n padding-inline-end: calc(${theme.base['hit-area'].finger});\n border-radius: calc(${comp['border-radius']} * ${theme.base['border-radius']});\n border-start-start-radius: 0;\n border-end-start-radius: 0;\n ${decoupled\n ? css`\n border-inline-start: none;\n `\n : css`\n border: none;\n `}\n height: 100%;\n min-height: 100%;\n position: relative;\n z-index: 1;\n\n &[value=''] {\n padding-inline-end: 0;\n }\n\n &::-ms-clear {\n display: none;\n }\n\n &::-webkit-search-cancel-button {\n display: none;\n }\n\n ::-webkit-search-decoration {\n -webkit-appearance: none;\n }\n\n &:focus:not([disabled]) {\n z-index: 2;\n ${!decoupled &&\n css`\n border: none;\n box-shadow: none;\n `}\n }\n `;\n});\n\nStyledSearchTextInput.defaultProps = defaultThemeProp;\n\nexport const StyledSearchInput = styled.div<{ hasFilters: boolean }>(\n ({\n theme: {\n base,\n components: { input, 'form-control': formControl, 'search-input': searchInput }\n },\n hasFilters\n }) => {\n return css`\n background: ${formControl['background-color']};\n min-height: ${input.height};\n position: relative;\n height: ${input.height};\n border-radius: calc(${searchInput['border-radius']} * ${base['border-radius']});\n ${hasFilters\n ? css`\n border: none;\n `\n : css`\n border: ${input['border-width']} solid ${input['border-color']};\n `}\n\n ${!hasFilters &&\n css`\n :focus-within {\n border-color: ${base.palette.light};\n box-shadow: ${formControl[':focus']['box-shadow']};\n }\n `}\n `;\n }\n);\n\nStyledSearchInput.defaultProps = defaultThemeProp;\n\nexport const StyledSearchMenu = styled.div`\n header {\n border-bottom: none;\n }\n`;\n\nexport const StyledSearchResultsContainer = styled.div`\n padding-top: ${props => props.theme.base.spacing};\n`;\n\nStyledSearchResultsContainer.defaultProps = defaultThemeProp;\n\nexport const StyledFiltersPopover = styled.div``;\n\nexport const StyledResultsPopover = styled.div``;\n"]}
1
+ {"version":3,"file":"SearchInput.styles.js","sourceRoot":"","sources":["../../../src/components/SearchInput/SearchInput.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,UAAU,MAAM,sBAAsB,CAAC;AAC9C,OAAO,KAAK,MAAM,UAAU,CAAC;AAE7B,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE;IAC3E,MAAM,SAAS,GAAG,QAAQ,CAAC,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,GAAG,CAAA;oBACM,WAAW,CAAC,kBAAkB,CAAC;oBAC/B,KAAK,CAAC,MAAM;;gBAEhB,KAAK,CAAC,MAAM;4BACA,WAAW,CAAC,eAAe,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC;QAC3E,UAAU;QACV,CAAC,CAAC,GAAG,CAAA;;WAEF;QACH,CAAC,CAAC,GAAG,CAAA;sBACS,KAAK,CAAC,cAAc,CAAC,UAAU,KAAK,CAAC,cAAc,CAAC;WAC/D;;QAEH,CAAC,UAAU;QACb,GAAG,CAAA;;0BAEiB,IAAI,CAAC,OAAO,CAAC,KAAK;wBACpB,WAAW,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC;;OAEpD;;;sBAGe,IAAI,CAAC,UAAU,CAAC,CAAC,YAAY,CAAC;qBAC/B,IAAI,CAAC,UAAU,CAAC,CAAC,YAAY,CAAC;;KAE9C,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,iBAAiB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAElD,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;CAIzC,CAAC;AAEF,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAC,GAAG,CAAA;iBACrC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO;CACjD,CAAC;AAEF,4BAA4B,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE7D,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAA,EAAE,CAAC;AAEjD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAA,EAAE,CAAC","sourcesContent":["import { transparentize } from 'polished';\nimport styled, { css } from 'styled-components';\n\nimport MenuButton from '../MenuButton';\nimport { defaultThemeProp } from '../../theme';\nimport { tryCatch } from '../../utils';\nimport Button from '../Button';\nimport BareButton from '../Button/BareButton';\nimport Input from '../Input';\n\nexport const StyledSearchButton = styled(BareButton)(({ theme: { base } }) => {\n const iconColor = tryCatch(() => transparentize(0.3, base.palette['foreground-color']));\n return css`\n padding-inline-start: ${base.spacing};\n color: ${iconColor};\n\n @media (pointer: coarse) {\n padding-inline-start: calc(3 * ${base.spacing});\n }\n `;\n});\n\nStyledSearchButton.defaultProps = defaultThemeProp;\n\nexport const StyledMenuButton = styled(MenuButton)(\n ({\n theme: {\n base,\n components: { 'search-input': searchInput, 'form-control': formControl, input }\n }\n }) => {\n const iconColor = tryCatch(() => transparentize(0.3, base.palette['foreground-color']));\n return css`\n border-start-start-radius: calc(${base['border-radius']} * ${searchInput['border-radius']});\n border-end-start-radius: calc(${base['border-radius']} * ${searchInput['border-radius']});\n padding-inline-start: ${base.spacing};\n border: ${input['border-width']} solid ${input['border-color']};\n color: ${iconColor};\n position: relative;\n z-index: 2;\n &:hover {\n text-decoration: none;\n }\n\n &:focus:enabled {\n border-color: ${formControl[':focus']['border-color']};\n box-shadow: ${formControl[':focus']['box-shadow']};\n }\n `;\n }\n);\n\nStyledMenuButton.defaultProps = defaultThemeProp;\n\nexport const StyledCancelButton = styled(Button)(({ theme }) => {\n return css`\n position: absolute;\n inset-inline-end: calc(\n (${theme.base['hit-area'].finger} - ${theme.base['hit-area'].compact}) / 2\n );\n inset-block-start: calc(\n (${theme.components.input.height} - ${theme.base['hit-area'].compact}) / 2\n );\n z-index: 3;\n\n @media (pointer: coarse) {\n inset-block-start: calc(\n (${theme.base['hit-area']['finger-min']} - ${theme.base['hit-area'].compact}) / 2\n );\n }\n `;\n});\n\nStyledCancelButton.defaultProps = defaultThemeProp;\n\nexport const StyledSearchTextInput = styled(Input)<{ decoupled: boolean }>(props => {\n const { theme, decoupled } = props;\n const comp = theme.components['search-input'];\n return css`\n flex: 1;\n background: transparent;\n padding-inline-end: calc(${theme.base['hit-area'].finger});\n border-radius: calc(${comp['border-radius']} * ${theme.base['border-radius']});\n border-start-start-radius: 0;\n border-end-start-radius: 0;\n ${decoupled\n ? css`\n border-inline-start: none;\n `\n : css`\n border: none;\n `}\n height: 100%;\n min-height: 100%;\n position: relative;\n z-index: 1;\n\n &[value=''] {\n padding-inline-end: 0;\n }\n\n &::-ms-clear {\n display: none;\n }\n\n &::-webkit-search-cancel-button {\n display: none;\n }\n\n ::-webkit-search-decoration {\n -webkit-appearance: none;\n }\n\n &:focus:not([disabled]) {\n z-index: 2;\n ${!decoupled &&\n css`\n border: none;\n box-shadow: none;\n `}\n }\n `;\n});\n\nStyledSearchTextInput.defaultProps = defaultThemeProp;\n\nexport const StyledSearchInput = styled.div<{ hasFilters: boolean }>(\n ({\n theme: {\n base,\n components: { input, 'form-control': formControl, 'search-input': searchInput }\n },\n hasFilters\n }) => {\n return css`\n background: ${formControl['background-color']};\n min-height: ${input.height};\n position: relative;\n height: ${input.height};\n border-radius: calc(${searchInput['border-radius']} * ${base['border-radius']});\n ${hasFilters\n ? css`\n border: none;\n `\n : css`\n border: ${input['border-width']} solid ${input['border-color']};\n `}\n\n ${!hasFilters &&\n css`\n :focus-within {\n border-color: ${base.palette.light};\n box-shadow: ${formControl[':focus']['box-shadow']};\n }\n `}\n\n @media (pointer: coarse) {\n min-height: ${base['hit-area']['finger-min']};\n min-width: ${base['hit-area']['finger-min']};\n }\n `;\n }\n);\n\nStyledSearchInput.defaultProps = defaultThemeProp;\n\nexport const StyledSearchMenu = styled.div`\n header {\n border-bottom: none;\n }\n`;\n\nexport const StyledSearchResultsContainer = styled.div`\n padding-top: ${props => props.theme.base.spacing};\n`;\n\nStyledSearchResultsContainer.defaultProps = defaultThemeProp;\n\nexport const StyledFiltersPopover = styled.div``;\n\nexport const StyledResultsPopover = styled.div``;\n"]}
@@ -54,7 +54,7 @@ const ShortcutManager = ({ children, target, bindings: customBindings = {} }) =>
54
54
  // don't process event during typing letters/digits into inputs without modifier keys
55
55
  !(e.target instanceof HTMLElement &&
56
56
  ['input', 'textarea'].includes(e.target.nodeName.toLowerCase()) &&
57
- e.key.match(/a-zA-Z0-9/) &&
57
+ (e.code.startsWith('Key') || e.code.startsWith('Digit') || e.code.startsWith('Numpad')) &&
58
58
  !['Control', 'Meta'].some(modifier => e.getModifierState(modifier))),
59
59
  shortcuts: bindings.map(({ action, shortcut }) => ({
60
60
  shortcut,
@@ -1 +1 @@
1
- {"version":3,"file":"ShortcutManager.js","sourceRoot":"","sources":["../../../src/components/ShortcutManager/ShortcutManager.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAG,OAAyB,EAAQ,EAAE;IACnE,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC3B,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,iBAAiB,EAAE,eAAe,EAAE,EAAE,EAAE;YAC7D,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;gBACrB,QAAQ,GAAG;oBACT,GAAI,QAA8B;oBAClC,CAAC,EAAE,CAAC,EAAE,EAAE,iBAAiB,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe,EAAE;iBAC1E,CAAC;QACN,CAAC,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAAG,CAAC,QAA8B,EAAE,CAAgB,EAAE,EAAE;IACjF,MAAM,aAAa,GAAG,IAAI,WAAW,CAAC,UAAU,EAAE;QAChD,OAAO,EAAE,IAAI;QACb,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BACX,CAAC,CAAC,cAAc,EAAE,CAAC;oBACnB,qBAAqB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;gBACnC,CAAC;aACF,CAAC,CAAC,CACJ,CAAC;SACH;IACH,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE/B,OAAO,4BAAG,QAAQ,GAAI,CAAC;AACzB,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { FunctionComponent } from 'react';\nimport { Shortcuts } from 'shortcuts';\n\nimport { useAfterInitialEffect, useSimpleStore } from '../../hooks';\nimport { hasProp } from '../../utils';\n\nimport type { ShortcutAction, ShortcutManagerProps } from './ShortcutManager.types';\nimport { actionStore } from './Store';\nimport type { ActionDefinitions } from './Store';\n\n/**\n * Function to register an action triggerable using a shortcut. All actions must be registered before\n * binding a callback.\n * @param actions actions with definitions to be registered.\n */\nexport const registerAction = (...actions: ShortcutAction[]): void => {\n actionStore.setStore(store => {\n let newStore = store;\n actions.forEach(({ id, defaultKeyBinding: defaultShortcut }) => {\n if (!hasProp(store, id))\n newStore = {\n ...(newStore as ActionDefinitions),\n [id]: { defaultKeyBinding: defaultShortcut, keyBinding: defaultShortcut }\n };\n });\n return newStore;\n });\n};\n\nconst dispatchShortcutEvent = (actionId: ShortcutAction['id'], e: KeyboardEvent) => {\n const shortcutEvent = new CustomEvent('shortcut', {\n bubbles: true,\n detail: { actionId }\n });\n e.target?.dispatchEvent(shortcutEvent);\n};\n\nconst ShortcutManager: FunctionComponent<ShortcutManagerProps> = ({\n children,\n target,\n bindings: customBindings = {}\n}) => {\n const shortcutsRef = useRef<Shortcuts>();\n\n const [bindings, setBindings] = useSimpleStore(actionStore, store =>\n Object.entries(store).map(([actionId, actionDefinition]) => ({\n action: actionId,\n shortcut: actionDefinition.keyBinding\n }))\n );\n\n useEffect(() => {\n setBindings(store => {\n let newStore = store;\n Object.entries(customBindings).forEach(([actionId, keyBinding]) => {\n newStore = { ...newStore, [actionId]: { ...newStore[actionId], keyBinding } };\n });\n return newStore;\n });\n }, [JSON.stringify(customBindings)]);\n\n useEffect(() => {\n shortcutsRef.current = new Shortcuts({\n target,\n shouldHandleEvent: e =>\n // both 'keydown' and 'keypress' events are handled by default ('shortcuts' bug?)\n e.type === 'keydown' &&\n !e.defaultPrevented &&\n // don't process event during typing letters/digits into inputs without modifier keys\n !(\n e.target instanceof HTMLElement &&\n ['input', 'textarea'].includes(e.target.nodeName.toLowerCase()) &&\n e.key.match(/a-zA-Z0-9/) &&\n !['Control', 'Meta'].some(modifier => e.getModifierState(modifier))\n ),\n shortcuts: bindings.map(({ action, shortcut }) => ({\n shortcut,\n handler: e => {\n e.preventDefault();\n dispatchShortcutEvent(action, e);\n }\n }))\n });\n\n return () => {\n shortcutsRef.current?.reset();\n shortcutsRef.current = undefined;\n };\n }, [target]);\n\n useAfterInitialEffect(() => {\n const shortcutInstance = shortcutsRef.current;\n if (shortcutInstance) {\n shortcutInstance.reset();\n shortcutInstance.add(\n bindings.map(({ action, shortcut }) => ({\n shortcut,\n handler: e => {\n e.preventDefault();\n dispatchShortcutEvent(action, e);\n }\n }))\n );\n }\n }, [JSON.stringify(bindings)]);\n\n return <>{children}</>;\n};\n\nexport default ShortcutManager;\n"]}
1
+ {"version":3,"file":"ShortcutManager.js","sourceRoot":"","sources":["../../../src/components/ShortcutManager/ShortcutManager.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAA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Q,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;gBACjD,QAAQ;gBACR,OAAO,EAAE,CAAC,CAAC,EAAE;oBACX,CAAC,CAAC,cAAc,EAAE,CAAC;oBACnB,qBAAqB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;gBACnC,CAAC;aACF,CAAC,CAAC;SACJ,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;YAC9B,YAAY,CAAC,OAAO,GAAG,SAAS,CAAC;QACnC,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,qBAAqB,CAAC,GAAG,EAAE;QACzB,MAAM,gBAAgB,GAAG,YAAY,CAAC,OAAO,CAAC;QAC9C,IAAI,gBAAgB,EAAE;YACpB,gBAAgB,CAAC,KAAK,EAAE,CAAC;YACzB,gBAAgB,CAAC,GAAG,CAClB,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;gBACtC,QAAQ;gBACR,OAAO,EAAE,CAAC,CAAC,EAAE;oBACX,CAAC,CAAC,cAAc,EAAE,CAAC;oBACnB,qBAAqB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;gBACnC,CAAC;aACF,CAAC,CAAC,CACJ,CAAC;SACH;IACH,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE/B,OAAO,4BAAG,QAAQ,GAAI,CAAC;AACzB,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { FunctionComponent } from 'react';\nimport { Shortcuts } from 'shortcuts';\n\nimport { useAfterInitialEffect, useSimpleStore } from '../../hooks';\nimport { hasProp } from '../../utils';\n\nimport type { ShortcutAction, ShortcutManagerProps } from './ShortcutManager.types';\nimport { actionStore } from './Store';\nimport type { ActionDefinitions } from './Store';\n\n/**\n * Function to register an action triggerable using a shortcut. All actions must be registered before\n * binding a callback.\n * @param actions actions with definitions to be registered.\n */\nexport const registerAction = (...actions: ShortcutAction[]): void => {\n actionStore.setStore(store => {\n let newStore = store;\n actions.forEach(({ id, defaultKeyBinding: defaultShortcut }) => {\n if (!hasProp(store, id))\n newStore = {\n ...(newStore as ActionDefinitions),\n [id]: { defaultKeyBinding: defaultShortcut, keyBinding: defaultShortcut }\n };\n });\n return newStore;\n });\n};\n\nconst dispatchShortcutEvent = (actionId: ShortcutAction['id'], e: KeyboardEvent) => {\n const shortcutEvent = new CustomEvent('shortcut', {\n bubbles: true,\n detail: { actionId }\n });\n e.target?.dispatchEvent(shortcutEvent);\n};\n\nconst ShortcutManager: FunctionComponent<ShortcutManagerProps> = ({\n children,\n target,\n bindings: customBindings = {}\n}) => {\n const shortcutsRef = useRef<Shortcuts>();\n\n const [bindings, setBindings] = useSimpleStore(actionStore, store =>\n Object.entries(store).map(([actionId, actionDefinition]) => ({\n action: actionId,\n shortcut: actionDefinition.keyBinding\n }))\n );\n\n useEffect(() => {\n setBindings(store => {\n let newStore = store;\n Object.entries(customBindings).forEach(([actionId, keyBinding]) => {\n newStore = { ...newStore, [actionId]: { ...newStore[actionId], keyBinding } };\n });\n return newStore;\n });\n }, [JSON.stringify(customBindings)]);\n\n useEffect(() => {\n shortcutsRef.current = new Shortcuts({\n target,\n shouldHandleEvent: e =>\n // both 'keydown' and 'keypress' events are handled by default ('shortcuts' bug?)\n e.type === 'keydown' &&\n !e.defaultPrevented &&\n // don't process event during typing letters/digits into inputs without modifier keys\n !(\n e.target instanceof HTMLElement &&\n ['input', 'textarea'].includes(e.target.nodeName.toLowerCase()) &&\n (e.code.startsWith('Key') || e.code.startsWith('Digit') || e.code.startsWith('Numpad')) &&\n !['Control', 'Meta'].some(modifier => e.getModifierState(modifier))\n ),\n shortcuts: bindings.map(({ action, shortcut }) => ({\n shortcut,\n handler: e => {\n e.preventDefault();\n dispatchShortcutEvent(action, e);\n }\n }))\n });\n\n return () => {\n shortcutsRef.current?.reset();\n shortcutsRef.current = undefined;\n };\n }, [target]);\n\n useAfterInitialEffect(() => {\n const shortcutInstance = shortcutsRef.current;\n if (shortcutInstance) {\n shortcutInstance.reset();\n shortcutInstance.add(\n bindings.map(({ action, shortcut }) => ({\n shortcut,\n handler: e => {\n e.preventDefault();\n dispatchShortcutEvent(action, e);\n }\n }))\n );\n }\n }, [JSON.stringify(bindings)]);\n\n return <>{children}</>;\n};\n\nexport default ShortcutManager;\n"]}
@@ -7,7 +7,7 @@ export interface TextAreaProps extends FormControlProps, BaseProps, NoChildrenPr
7
7
  /** Maximum length of characters that can be input. */
8
8
  maxLength?: number;
9
9
  /**
10
- * Allows the user to resize the Text Area.
10
+ * Allows the user to resize the Text Area. This prop is ignored if autoResize is true.
11
11
  * @default false
12
12
  */
13
13
  resizable?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"TextArea.d.ts","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAqC,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAEvF,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGvF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAQvD,MAAM,WAAW,aAAc,SAAQ,gBAAgB,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU;IAC5F,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;CACpD;;;;AAuHD,wBAAyD"}
1
+ {"version":3,"file":"TextArea.d.ts","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAqC,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAEvF,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGvF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAQvD,MAAM,WAAW,aAAc,SAAQ,gBAAgB,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU;IAC5F,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;CACpD;;;;AAoID,wBAAyD"}
@@ -1,27 +1,34 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { forwardRef, useCallback, useState, useEffect } from 'react';
2
+ import { forwardRef, useCallback, useState, useEffect, useRef } from 'react';
3
3
  import FormField from '../FormField';
4
4
  import { StyledFormControl } from '../FormControl';
5
5
  import { hasProp, withTestIds } from '../../utils';
6
- import { useAutoResize, useConsolidatedRef, useI18n, useTestIds, useUID } from '../../hooks';
6
+ import { useI18n, useTestIds, useUID } from '../../hooks';
7
7
  import Text from '../Text';
8
- import StyledTextArea from './TextArea.styles';
8
+ import StyledTextArea, { AutoResizeWrapper } from './TextArea.styles';
9
9
  import { getTextAreaTestIds } from './TextArea.test-ids';
10
10
  const TextArea = forwardRef(function TextArea(props, ref) {
11
11
  const uid = useUID();
12
12
  const { testId, additionalInfo, id = uid, value, defaultValue, required = false, disabled = false, readOnly = false, label, labelHidden, info, status, resizable = false, autoResize = true, maxLength, displayCharCount = false, hardStop = true, onChange: onChangeProp, onResolveSuggestion, ...restProps } = props;
13
13
  const t = useI18n();
14
14
  const testIds = useTestIds(testId, getTextAreaTestIds);
15
- const [textAreaRef, resizeTextArea] = useAutoResize();
16
- const consolidatedRef = useConsolidatedRef(textAreaRef, ref);
15
+ const autoResizeRef = useRef(null);
17
16
  const [charCount, setCharCount] = useState(0);
18
17
  const controlProp = {};
18
+ // Sets the content for the hidden pseudo element that calculates the height of the textarea
19
+ const updateAutoResizeEl = (content) => {
20
+ if (autoResize && autoResizeRef.current) {
21
+ autoResizeRef.current.dataset.textareaContent = content ?? '';
22
+ }
23
+ };
19
24
  useEffect(() => {
20
25
  if ('value' in props) {
21
26
  setCharCount(props.value ? props.value.length : 0);
27
+ updateAutoResizeEl(props.value);
22
28
  }
23
29
  else if ('defaultValue' in props) {
24
30
  setCharCount(props.defaultValue ? props.defaultValue.length : 0);
31
+ updateAutoResizeEl(props.defaultValue);
25
32
  }
26
33
  }, [props]);
27
34
  // Conditionally render component as controlled/uncontrolled
@@ -35,10 +42,11 @@ const TextArea = forwardRef(function TextArea(props, ref) {
35
42
  if (!hardStop || maxLength === undefined || e.target.value.length <= maxLength) {
36
43
  onChangeProp?.(e);
37
44
  setCharCount(e.target.value.length);
38
- resizeTextArea();
45
+ updateAutoResizeEl(e.target.value);
39
46
  }
40
- }, [onChangeProp, resizeTextArea, hardStop, maxLength]);
41
- const Comp = (_jsx(StyledFormControl, { "data-testid": testIds.control, ref: autoResize ? consolidatedRef : ref, id: id, required: required, disabled: disabled, status: status, readOnly: readOnly, resizable: resizable, maxLength: hardStop ? maxLength : undefined, hasSuggestion: status === 'pending' && !!onResolveSuggestion, ...controlProp, ...restProps, onChange: onChange, as: StyledTextArea }));
47
+ }, [onChangeProp, hardStop, maxLength]);
48
+ const TextAreaControl = (_jsx(StyledFormControl, { "data-testid": testIds.control, ref: ref, id: id, required: required, disabled: disabled, status: status, readOnly: readOnly, resizable: autoResize ? false : resizable, maxLength: hardStop ? maxLength : undefined, hasSuggestion: status === 'pending' && !!onResolveSuggestion, ...controlProp, ...restProps, onChange: onChange, as: StyledTextArea }));
49
+ const Comp = autoResize ? (_jsx(AutoResizeWrapper, { ref: autoResizeRef, children: TextAreaControl })) : (_jsx("div", { children: TextAreaControl }));
42
50
  return label || displayCharCount ? (_jsx(FormField, { testId: testIds, additionalInfo: additionalInfo, label: label, labelHidden: labelHidden, id: id, readOnly: readOnly, info: info, status: status, charLimitDisplay: displayCharCount && typeof maxLength === 'number' ? (_jsx(Text, { readOnly: readOnly, variant: 'secondary', "aria-live": maxLength >= 0 && maxLength - charCount <= 20 ? 'polite' : 'off', children: maxLength >= 0 ? t('x_of_y', [charCount || '0', maxLength]) : charCount })) : undefined, required: required, disabled: disabled, onResolveSuggestion: onResolveSuggestion, children: Comp })) : (Comp);
43
51
  });
44
52
  export default withTestIds(TextArea, getTextAreaTestIds);
@@ -1 +1 @@
1
- {"version":3,"file":"TextArea.js","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIrE,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,OAAO,EAAE,UAAU,EA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,EAC3C,aAAa,EAAE,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,mBAAmB,KACxD,WAAW,KACX,SAAS,EACb,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,cAAc,GAClB,CACH,CAAC;IAEF,OAAO,KAAK,IAAI,gBAAgB,CAAC,CAAC,CAAC,CACjC,KAAC,SAAS,IACR,MAAM,EAAE,OAAO,EACf,cAAc,EAAE,cAAc,EAC9B,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,EAAE,EAAE,EAAE,EACN,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,EACd,gBAAgB,EACd,gBAAgB,IAAI,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,CAClD,KAAC,IAAI,IACH,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAC,WAAW,eACR,SAAS,IAAI,CAAC,IAAI,SAAS,GAAG,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,YAE1E,SAAS,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,SAAS,IAAI,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,GACnE,CACR,CAAC,CAAC,CAAC,SAAS,EAEf,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,mBAAmB,EAAE,mBAAmB,YAEvC,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC","sourcesContent":["import { forwardRef, useCallback, useState, useEffect } from 'react';\nimport type { FC, Ref, PropsWithoutRef, ChangeEvent, ChangeEventHandler } from 'react';\n\nimport type { BaseProps, ForwardProps, NoChildrenProp, TestIdProp } from '../../types';\nimport FormField from '../FormField';\nimport { StyledFormControl } from '../FormControl';\nimport type { FormControlProps } from '../FormControl';\nimport { hasProp, withTestIds } from '../../utils';\nimport { useAutoResize, useConsolidatedRef, useI18n, useTestIds, useUID } from '../../hooks';\nimport Text from '../Text';\n\nimport StyledTextArea from './TextArea.styles';\nimport { getTextAreaTestIds } from './TextArea.test-ids';\n\nexport interface TextAreaProps extends FormControlProps, BaseProps, NoChildrenProp, TestIdProp {\n /** Minimum length of characters that can be input. */\n minLength?: number;\n /** Maximum length of characters that can be input. */\n maxLength?: number;\n /**\n * Allows the user to resize the Text Area.\n * @default false\n */\n resizable?: boolean;\n /**\n * Enables the Text Area to resize itself automatically.\n * @default true\n */\n autoResize?: boolean;\n /**\n * Display a live character count in relation to the maxLength.\n * @default false\n */\n displayCharCount?: boolean;\n /**\n * Allow or disallow a value beyond the maxLength.\n * @default true\n */\n hardStop?: boolean;\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n}\n\nconst TextArea: FC<TextAreaProps & ForwardProps> = forwardRef(function TextArea(\n props: PropsWithoutRef<TextAreaProps>,\n ref: Ref<HTMLTextAreaElement>\n) {\n const uid = useUID();\n const {\n testId,\n additionalInfo,\n id = uid,\n value,\n defaultValue,\n required = false,\n disabled = false,\n readOnly = false,\n label,\n labelHidden,\n info,\n status,\n resizable = false,\n autoResize = true,\n maxLength,\n displayCharCount = false,\n hardStop = true,\n onChange: onChangeProp,\n onResolveSuggestion,\n ...restProps\n } = props;\n const t = useI18n();\n\n const testIds = useTestIds(testId, getTextAreaTestIds);\n\n const [textAreaRef, resizeTextArea] = useAutoResize<HTMLTextAreaElement>();\n const consolidatedRef = useConsolidatedRef(textAreaRef, ref);\n const [charCount, setCharCount] = useState(0);\n\n const controlProp: {\n value?: string;\n defaultValue?: string;\n } = {};\n\n useEffect(() => {\n if ('value' in props) {\n setCharCount(props.value ? props.value.length : 0);\n } else if ('defaultValue' in props) {\n setCharCount(props.defaultValue ? props.defaultValue.length : 0);\n }\n }, [props]);\n\n // Conditionally render component as controlled/uncontrolled\n if (hasProp(props, 'value')) {\n controlProp.value = value ?? '';\n } else if (hasProp(props, 'defaultValue')) {\n controlProp.defaultValue = defaultValue ?? '';\n }\n\n const onChange = useCallback(\n (e: ChangeEvent<HTMLTextAreaElement>) => {\n if (!hardStop || maxLength === undefined || e.target.value.length <= maxLength) {\n onChangeProp?.(e);\n setCharCount(e.target.value.length);\n resizeTextArea();\n }\n },\n [onChangeProp, resizeTextArea, hardStop, maxLength]\n );\n\n const Comp = (\n <StyledFormControl\n data-testid={testIds.control}\n ref={autoResize ? consolidatedRef : ref}\n id={id}\n required={required}\n disabled={disabled}\n status={status}\n readOnly={readOnly}\n resizable={resizable}\n maxLength={hardStop ? maxLength : undefined}\n hasSuggestion={status === 'pending' && !!onResolveSuggestion}\n {...controlProp}\n {...restProps}\n onChange={onChange}\n as={StyledTextArea}\n />\n );\n\n return label || displayCharCount ? (\n <FormField\n testId={testIds}\n additionalInfo={additionalInfo}\n label={label}\n labelHidden={labelHidden}\n id={id}\n readOnly={readOnly}\n info={info}\n status={status}\n charLimitDisplay={\n displayCharCount && typeof maxLength === 'number' ? (\n <Text\n readOnly={readOnly}\n variant='secondary'\n aria-live={maxLength >= 0 && maxLength - charCount <= 20 ? 'polite' : 'off'}\n >\n {maxLength >= 0 ? t('x_of_y', [charCount || '0', maxLength]) : charCount}\n </Text>\n ) : undefined\n }\n required={required}\n disabled={disabled}\n onResolveSuggestion={onResolveSuggestion}\n >\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n});\n\nexport default withTestIds(TextArea, getTextAreaTestIds);\n"]}
1
+ {"version":3,"file":"TextArea.js","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAI7E,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAA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CAAC,CAAC,KAAK,YAE1E,SAAS,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,SAAS,IAAI,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,GACnE,CACR,CAAC,CAAC,CAAC,SAAS,EAEf,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,mBAAmB,EAAE,mBAAmB,YAEvC,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC","sourcesContent":["import { forwardRef, useCallback, useState, useEffect, useRef } from 'react';\nimport type { FC, Ref, PropsWithoutRef, ChangeEvent, ChangeEventHandler } from 'react';\n\nimport type { BaseProps, ForwardProps, NoChildrenProp, TestIdProp } from '../../types';\nimport FormField from '../FormField';\nimport { StyledFormControl } from '../FormControl';\nimport type { FormControlProps } from '../FormControl';\nimport { hasProp, withTestIds } from '../../utils';\nimport { useI18n, useTestIds, useUID } from '../../hooks';\nimport Text from '../Text';\n\nimport StyledTextArea, { AutoResizeWrapper } from './TextArea.styles';\nimport { getTextAreaTestIds } from './TextArea.test-ids';\n\nexport interface TextAreaProps extends FormControlProps, BaseProps, NoChildrenProp, TestIdProp {\n /** Minimum length of characters that can be input. */\n minLength?: number;\n /** Maximum length of characters that can be input. */\n maxLength?: number;\n /**\n * Allows the user to resize the Text Area. This prop is ignored if autoResize is true.\n * @default false\n */\n resizable?: boolean;\n /**\n * Enables the Text Area to resize itself automatically.\n * @default true\n */\n autoResize?: boolean;\n /**\n * Display a live character count in relation to the maxLength.\n * @default false\n */\n displayCharCount?: boolean;\n /**\n * Allow or disallow a value beyond the maxLength.\n * @default true\n */\n hardStop?: boolean;\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n}\n\nconst TextArea: FC<TextAreaProps & ForwardProps> = forwardRef(function TextArea(\n props: PropsWithoutRef<TextAreaProps>,\n ref: Ref<HTMLTextAreaElement>\n) {\n const uid = useUID();\n const {\n testId,\n additionalInfo,\n id = uid,\n value,\n defaultValue,\n required = false,\n disabled = false,\n readOnly = false,\n label,\n labelHidden,\n info,\n status,\n resizable = false,\n autoResize = true,\n maxLength,\n displayCharCount = false,\n hardStop = true,\n onChange: onChangeProp,\n onResolveSuggestion,\n ...restProps\n } = props;\n const t = useI18n();\n\n const testIds = useTestIds(testId, getTextAreaTestIds);\n const autoResizeRef = useRef<HTMLDivElement>(null);\n const [charCount, setCharCount] = useState(0);\n\n const controlProp: {\n value?: string;\n defaultValue?: string;\n } = {};\n\n // Sets the content for the hidden pseudo element that calculates the height of the textarea\n const updateAutoResizeEl = (content?: string) => {\n if (autoResize && autoResizeRef.current) {\n autoResizeRef.current.dataset.textareaContent = content ?? '';\n }\n };\n\n useEffect(() => {\n if ('value' in props) {\n setCharCount(props.value ? props.value.length : 0);\n updateAutoResizeEl(props.value);\n } else if ('defaultValue' in props) {\n setCharCount(props.defaultValue ? props.defaultValue.length : 0);\n updateAutoResizeEl(props.defaultValue);\n }\n }, [props]);\n\n // Conditionally render component as controlled/uncontrolled\n if (hasProp(props, 'value')) {\n controlProp.value = value ?? '';\n } else if (hasProp(props, 'defaultValue')) {\n controlProp.defaultValue = defaultValue ?? '';\n }\n\n const onChange = useCallback(\n (e: ChangeEvent<HTMLTextAreaElement>) => {\n if (!hardStop || maxLength === undefined || e.target.value.length <= maxLength) {\n onChangeProp?.(e);\n setCharCount(e.target.value.length);\n updateAutoResizeEl(e.target.value);\n }\n },\n [onChangeProp, hardStop, maxLength]\n );\n\n const TextAreaControl = (\n <StyledFormControl\n data-testid={testIds.control}\n ref={ref}\n id={id}\n required={required}\n disabled={disabled}\n status={status}\n readOnly={readOnly}\n resizable={autoResize ? false : resizable}\n maxLength={hardStop ? maxLength : undefined}\n hasSuggestion={status === 'pending' && !!onResolveSuggestion}\n {...controlProp}\n {...restProps}\n onChange={onChange}\n as={StyledTextArea}\n />\n );\n\n const Comp = autoResize ? (\n <AutoResizeWrapper ref={autoResizeRef}>{TextAreaControl}</AutoResizeWrapper>\n ) : (\n <div>{TextAreaControl}</div>\n );\n\n return label || displayCharCount ? (\n <FormField\n testId={testIds}\n additionalInfo={additionalInfo}\n label={label}\n labelHidden={labelHidden}\n id={id}\n readOnly={readOnly}\n info={info}\n status={status}\n charLimitDisplay={\n displayCharCount && typeof maxLength === 'number' ? (\n <Text\n readOnly={readOnly}\n variant='secondary'\n aria-live={maxLength >= 0 && maxLength - charCount <= 20 ? 'polite' : 'off'}\n >\n {maxLength >= 0 ? t('x_of_y', [charCount || '0', maxLength]) : charCount}\n </Text>\n ) : undefined\n }\n required={required}\n disabled={disabled}\n onResolveSuggestion={onResolveSuggestion}\n >\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n});\n\nexport default withTestIds(TextArea, getTextAreaTestIds);\n"]}
@@ -1,5 +1,6 @@
1
1
  declare const StyledTextArea: import("styled-components").StyledComponent<"textarea", import("styled-components").DefaultTheme, {
2
2
  resizable: boolean;
3
3
  }, never>;
4
+ export declare const AutoResizeWrapper: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
4
5
  export default StyledTextArea;
5
6
  //# sourceMappingURL=TextArea.styles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TextArea.styles.d.ts","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.styles.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,cAAc;eAAgC,OAAO;SAWzD,CAAC;AAIH,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"TextArea.styles.d.ts","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.styles.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,cAAc;eAAgC,OAAO;SAczD,CAAC;AAMH,eAAO,MAAM,iBAAiB,yGAqB5B,CAAC;AAIH,eAAe,cAAc,CAAC"}
@@ -6,12 +6,40 @@ const StyledTextArea = styled.textarea(({ resizable }) => {
6
6
  min-height: ${props => props.theme.components['text-area']['min-height']};
7
7
  padding: ${props => props.theme.components['text-area'].padding};
8
8
  -webkit-appearance: none;
9
- ${!resizable &&
10
- css `
11
- resize: none;
12
- `}
9
+ ${resizable
10
+ ? css `
11
+ resize: vertical;
12
+ `
13
+ : css `
14
+ resize: none;
15
+ `}
13
16
  `;
14
17
  });
15
18
  StyledTextArea.defaultProps = defaultThemeProp;
19
+ // Creates a hidden pseudo element identical in size and content to the textarea element
20
+ // The hidden element mimics the textarea and is used to automatically calculate the necessary height
21
+ export const AutoResizeWrapper = styled.div(({ theme }) => {
22
+ return css `
23
+ display: grid;
24
+ grid-template-columns: minmax(0, 1fr);
25
+
26
+ ${StyledTextArea} {
27
+ overflow: hidden;
28
+ grid-area: 1 / 1 / -1 / -1;
29
+ }
30
+
31
+ &::after {
32
+ content: attr(data-textarea-content);
33
+ white-space: pre-wrap;
34
+ overflow-wrap: break-word;
35
+ visibility: hidden;
36
+ border-width: ${theme.components['form-control']['border-width']};
37
+ padding: ${theme.components['text-area'].padding};
38
+ font: inherit;
39
+ grid-area: 1 / 1 / -1 / -1;
40
+ }
41
+ `;
42
+ });
43
+ AutoResizeWrapper.defaultProps = defaultThemeProp;
16
44
  export default StyledTextArea;
17
45
  //# sourceMappingURL=TextArea.styles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TextArea.styles.js","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,cAAc,GAAG,MAAM,CAAC,QAAQ,CAAyB,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE;IAC/E,OAAO,GAAG,CAAA;;kBAEM,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,YAAY,CAAC;eAC7D,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,OAAO;;MAE7D,CAAC,SAAS;QACZ,GAAG,CAAA;;KAEF;GACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,cAAc,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE/C,eAAe,cAAc,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\n\nimport { defaultThemeProp } from '../../theme';\n\nconst StyledTextArea = styled.textarea<{ resizable: boolean }>(({ resizable }) => {\n return css`\n width: 100%;\n min-height: ${props => props.theme.components['text-area']['min-height']};\n padding: ${props => props.theme.components['text-area'].padding};\n -webkit-appearance: none;\n ${!resizable &&\n css`\n resize: none;\n `}\n `;\n});\n\nStyledTextArea.defaultProps = defaultThemeProp;\n\nexport default StyledTextArea;\n"]}
1
+ {"version":3,"file":"TextArea.styles.js","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,cAAc,GAAG,MAAM,CAAC,QAAQ,CAAyB,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE;IAC/E,OAAO,GAAG,CAAA;;kBAEM,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,YAAY,CAAC;eAC7D,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,OAAO;;MAE7D,SAAS;QACT,CAAC,CAAC,GAAG,CAAA;;SAEF;QACH,CAAC,CAAC,GAAG,CAAA;;SAEF;GACN,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,cAAc,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE/C,wFAAwF;AACxF,qGAAqG;AACrG,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACxD,OAAO,GAAG,CAAA;;;;MAIN,cAAc;;;;;;;;;;sBAUE,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,cAAc,CAAC;iBACrD,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,OAAO;;;;GAInD,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,iBAAiB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAElD,eAAe,cAAc,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\n\nimport { defaultThemeProp } from '../../theme';\n\nconst StyledTextArea = styled.textarea<{ resizable: boolean }>(({ resizable }) => {\n return css`\n width: 100%;\n min-height: ${props => props.theme.components['text-area']['min-height']};\n padding: ${props => props.theme.components['text-area'].padding};\n -webkit-appearance: none;\n ${resizable\n ? css`\n resize: vertical;\n `\n : css`\n resize: none;\n `}\n `;\n});\n\nStyledTextArea.defaultProps = defaultThemeProp;\n\n// Creates a hidden pseudo element identical in size and content to the textarea element\n// The hidden element mimics the textarea and is used to automatically calculate the necessary height\nexport const AutoResizeWrapper = styled.div(({ theme }) => {\n return css`\n display: grid;\n grid-template-columns: minmax(0, 1fr);\n\n ${StyledTextArea} {\n overflow: hidden;\n grid-area: 1 / 1 / -1 / -1;\n }\n\n &::after {\n content: attr(data-textarea-content);\n white-space: pre-wrap;\n overflow-wrap: break-word;\n visibility: hidden;\n border-width: ${theme.components['form-control']['border-width']};\n padding: ${theme.components['text-area'].padding};\n font: inherit;\n grid-area: 1 / 1 / -1 / -1;\n }\n `;\n});\n\nAutoResizeWrapper.defaultProps = defaultThemeProp;\n\nexport default StyledTextArea;\n"]}
@@ -46,7 +46,7 @@ const Tooltip = forwardRef(function Tooltip({ testId, children, target, showDela
46
46
  showTooltip();
47
47
  };
48
48
  const onFocusOut = () => {
49
- if (lastClickedRef.current !== tooltipRef.current) {
49
+ if (!lastClickedRef.current || lastClickedRef.current !== tooltipRef.current) {
50
50
  setShow(false);
51
51
  }
52
52
  lastClickedRef.current = null;
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../src/components/Tooltip/Tooltip.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE7E,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAyCvD,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACpD,MAAM,QAAQ,GAAG,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAEtF,OAAO,GAAG,CAAA;wBACY,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,kBAAkB,CAAC;aACvD,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,kBAAkB,CAAC;iBACxC,QAAQ,CAAC,GAAG;;eAEd,KAAK,CAAC,IAAI,CAAC,OAAO;;;;GAI9B,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,aAAa,CAAC,YAAY,GAAG,gBAAgB,C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Q,EAAC,OAAO,EAChB,EAAE,EAAE,aAAa,EACjB,IAAI,EAAC,SAAS,EACd,MAAM,EAAE,MAAM,EACd,KAAK,QACL,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,WAAW,EACxB,kBAAkB,QAClB,GAAG,EAAE,UAAU,YAEd,QAAQ,GACD,CACX,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC","sourcesContent":["import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';\nimport type { FunctionComponent, MutableRefObject, PropsWithoutRef, Ref } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport type { BaseProps, ForwardProps, TestIdProp } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport Popover from '../Popover';\nimport type { Delay, PopoverProps } from '../Popover';\nimport { useConsolidatedRef, useTestIds, useUID } from '../../hooks';\nimport { calculateFontSize } from '../../styles';\nimport { getActiveElement, withTestIds } from '../../utils';\n\nimport { getTooltipTestIds } from './Tooltip.test-ids';\n\nexport interface TooltipProps extends BaseProps, TestIdProp {\n /** Text content for the tooltip. */\n children: string | string[];\n /** Element to serve as the tooltip's target. */\n target: Element | null;\n /**\n * Delay showing the tooltip on mouseenter.\n * @default 'short'\n */\n showDelay?: Delay;\n /**\n * Delay hiding the tooltip on mouseleave.\n * @default 'long'\n */\n hideDelay?: Delay;\n /**\n * If true, the Tooltip will render outside of the current DOM hierarchy in a [portal](https://reactjs.org/docs/portals.html).\n * @default true\n */\n portal?: PopoverProps['portal'];\n /**\n * If true, the Tooltip will automatically apply an aria-describedby attribute to its target.\n * @default true\n */\n describeTarget?: boolean;\n /**\n * Sets the placement of the tooltip relative to the target.\n * @default 'bottom'\n */\n placement?: PopoverProps['placement'];\n /**\n * Conditionally renders a tooltip only if the associated element's text content is truncated.\n * To work, the associated element must be be displayed as a CSS \"block box\" i.e. block, inline-block, etc...\n * @default false\n */\n smart?: boolean;\n ref?: Ref<HTMLDivElement>;\n}\n\nexport const StyledTooltip = styled.div(({ theme }) => {\n const fontSize = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n\n return css`\n background-color: ${theme.components.tooltip['background-color']};\n color: ${theme.components.tooltip['foreground-color']};\n font-size: ${fontSize.xxs};\n max-width: 40ch;\n padding: ${theme.base.spacing};\n white-space: pre-line;\n word-break: break-word;\n pointer-events: none;\n `;\n});\n\nStyledTooltip.defaultProps = defaultThemeProp;\n\nconst Tooltip: FunctionComponent<TooltipProps & ForwardProps> = forwardRef(function Tooltip(\n {\n testId,\n children,\n target,\n showDelay = 'short',\n hideDelay = 'long',\n placement = 'bottom',\n describeTarget = true,\n smart,\n ...restProps\n }: PropsWithoutRef<TooltipProps>,\n ref: Ref<HTMLDivElement>\n) {\n const id = useUID();\n const [show, setShow] = useState(false);\n const tooltipRef = useConsolidatedRef(ref);\n const lastClickedRef: MutableRefObject<EventTarget | null> = useRef(null);\n const testIds = useTestIds(testId, getTooltipTestIds);\n\n const onMouseDown = useCallback(\n ({ target: eTarget }: MouseEvent) => {\n lastClickedRef.current = eTarget;\n if (eTarget === tooltipRef.current || eTarget === target) return;\n setShow(false);\n },\n [target]\n );\n\n useEffect(() => {\n if (!target) return;\n\n const showTooltip = () => {\n setShow(\n // This approach may result in a tooltip NOT appearing 1px before it should due to browser specifics. Enhance as needed.\n // https://stackoverflow.com/a/64747288\n smart ? target.scrollWidth > target.clientWidth : true\n );\n };\n\n const onFocusIn = () => {\n showTooltip();\n };\n\n const onFocusOut = () => {\n if (lastClickedRef.current !== tooltipRef.current) {\n setShow(false);\n }\n lastClickedRef.current = null;\n };\n\n const onMouseEnter = () => {\n showTooltip();\n };\n\n const onMouseLeave = () => {\n if (getActiveElement() !== target) {\n setShow(false);\n }\n };\n\n const onKeyDown = ({ key }: KeyboardEvent) => {\n if (key === 'Escape' && getActiveElement() === target) {\n setShow(false);\n }\n };\n\n document.addEventListener('keydown', onKeyDown);\n document.addEventListener('mousedown', onMouseDown);\n\n target.addEventListener('focusin', onFocusIn);\n target.addEventListener('focusout', onFocusOut);\n\n target.addEventListener('mouseenter', onMouseEnter);\n target.addEventListener('mouseleave', onMouseLeave);\n\n return () => {\n document.removeEventListener('keydown', onKeyDown);\n document.removeEventListener('mousedown', onMouseDown);\n\n target.removeEventListener('focusin', onFocusIn);\n target.removeEventListener('focusout', onFocusOut);\n\n target.removeEventListener('mouseenter', onMouseEnter);\n target.removeEventListener('mouseleave', onMouseLeave);\n };\n }, [target, onMouseDown, smart]);\n\n useEffect(() => {\n if (target && describeTarget && show) {\n const describedBy = target.getAttribute('aria-describedby');\n // Set the attribute to the old attribute plus the id\n target.setAttribute('aria-describedby', describedBy ? `${describedBy} ${id}` : id);\n } else if (target) {\n // Get the old attribute\n const describedBy = target.getAttribute('aria-describedby');\n if (describedBy) {\n // If the old attribute matches the id just remove it entirely\n if (describedBy === id) {\n target.removeAttribute('aria-describedby');\n } else {\n // Otherwise we want to just remove the id that was added and reset the attribute to what it was before\n const oldDescribedBy = describedBy.replace(new RegExp(`(?:^|\\\\s+)${id}`), '');\n target.setAttribute('aria-describedby', oldDescribedBy);\n }\n }\n }\n }, [describeTarget, target, show]);\n\n return (\n <Popover\n data-testid={testIds.root}\n id={id}\n {...restProps}\n show={show}\n showDelay={showDelay}\n hideDelay={hideDelay}\n groupId='tooltip'\n strategy='fixed'\n as={StyledTooltip}\n role='tooltip'\n target={target}\n arrow\n placement={placement}\n onMouseDown={onMouseDown}\n hideOnTargetHidden\n ref={tooltipRef}\n >\n {children}\n </Popover>\n );\n});\n\nexport default withTestIds(Tooltip, getTooltipTestIds);\n"]}
1
+ {"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../src/components/Tooltip/Tooltip.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE7E,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mB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FunctionComponent, MutableRefObject, PropsWithoutRef, Ref } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport type { BaseProps, ForwardProps, TestIdProp } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport Popover from '../Popover';\nimport type { Delay, PopoverProps } from '../Popover';\nimport { useConsolidatedRef, useTestIds, useUID } from '../../hooks';\nimport { calculateFontSize } from '../../styles';\nimport { getActiveElement, withTestIds } from '../../utils';\n\nimport { getTooltipTestIds } from './Tooltip.test-ids';\n\nexport interface TooltipProps extends BaseProps, TestIdProp {\n /** Text content for the tooltip. */\n children: string | string[];\n /** Element to serve as the tooltip's target. */\n target: Element | null;\n /**\n * Delay showing the tooltip on mouseenter.\n * @default 'short'\n */\n showDelay?: Delay;\n /**\n * Delay hiding the tooltip on mouseleave.\n * @default 'long'\n */\n hideDelay?: Delay;\n /**\n * If true, the Tooltip will render outside of the current DOM hierarchy in a [portal](https://reactjs.org/docs/portals.html).\n * @default true\n */\n portal?: PopoverProps['portal'];\n /**\n * If true, the Tooltip will automatically apply an aria-describedby attribute to its target.\n * @default true\n */\n describeTarget?: boolean;\n /**\n * Sets the placement of the tooltip relative to the target.\n * @default 'bottom'\n */\n placement?: PopoverProps['placement'];\n /**\n * Conditionally renders a tooltip only if the associated element's text content is truncated.\n * To work, the associated element must be be displayed as a CSS \"block box\" i.e. block, inline-block, etc...\n * @default false\n */\n smart?: boolean;\n ref?: Ref<HTMLDivElement>;\n}\n\nexport const StyledTooltip = styled.div(({ theme }) => {\n const fontSize = calculateFontSize(theme.base['font-size'], theme.base['font-scale']);\n\n return css`\n background-color: ${theme.components.tooltip['background-color']};\n color: ${theme.components.tooltip['foreground-color']};\n font-size: ${fontSize.xxs};\n max-width: 40ch;\n padding: ${theme.base.spacing};\n white-space: pre-line;\n word-break: break-word;\n pointer-events: none;\n `;\n});\n\nStyledTooltip.defaultProps = defaultThemeProp;\n\nconst Tooltip: FunctionComponent<TooltipProps & ForwardProps> = forwardRef(function Tooltip(\n {\n testId,\n children,\n target,\n showDelay = 'short',\n hideDelay = 'long',\n placement = 'bottom',\n describeTarget = true,\n smart,\n ...restProps\n }: PropsWithoutRef<TooltipProps>,\n ref: Ref<HTMLDivElement>\n) {\n const id = useUID();\n const [show, setShow] = useState(false);\n const tooltipRef = useConsolidatedRef(ref);\n const lastClickedRef: MutableRefObject<EventTarget | null> = useRef(null);\n const testIds = useTestIds(testId, getTooltipTestIds);\n\n const onMouseDown = useCallback(\n ({ target: eTarget }: MouseEvent) => {\n lastClickedRef.current = eTarget;\n if (eTarget === tooltipRef.current || eTarget === target) return;\n setShow(false);\n },\n [target]\n );\n\n useEffect(() => {\n if (!target) return;\n\n const showTooltip = () => {\n setShow(\n // This approach may result in a tooltip NOT appearing 1px before it should due to browser specifics. Enhance as needed.\n // https://stackoverflow.com/a/64747288\n smart ? target.scrollWidth > target.clientWidth : true\n );\n };\n\n const onFocusIn = () => {\n showTooltip();\n };\n\n const onFocusOut = () => {\n if (!lastClickedRef.current || lastClickedRef.current !== tooltipRef.current) {\n setShow(false);\n }\n lastClickedRef.current = null;\n };\n\n const onMouseEnter = () => {\n showTooltip();\n };\n\n const onMouseLeave = () => {\n if (getActiveElement() !== target) {\n setShow(false);\n }\n };\n\n const onKeyDown = ({ key }: KeyboardEvent) => {\n if (key === 'Escape' && getActiveElement() === target) {\n setShow(false);\n }\n };\n\n document.addEventListener('keydown', onKeyDown);\n document.addEventListener('mousedown', onMouseDown);\n\n target.addEventListener('focusin', onFocusIn);\n target.addEventListener('focusout', onFocusOut);\n\n target.addEventListener('mouseenter', onMouseEnter);\n target.addEventListener('mouseleave', onMouseLeave);\n\n return () => {\n document.removeEventListener('keydown', onKeyDown);\n document.removeEventListener('mousedown', onMouseDown);\n\n target.removeEventListener('focusin', onFocusIn);\n target.removeEventListener('focusout', onFocusOut);\n\n target.removeEventListener('mouseenter', onMouseEnter);\n target.removeEventListener('mouseleave', onMouseLeave);\n };\n }, [target, onMouseDown, smart]);\n\n useEffect(() => {\n if (target && describeTarget && show) {\n const describedBy = target.getAttribute('aria-describedby');\n // Set the attribute to the old attribute plus the id\n target.setAttribute('aria-describedby', describedBy ? `${describedBy} ${id}` : id);\n } else if (target) {\n // Get the old attribute\n const describedBy = target.getAttribute('aria-describedby');\n if (describedBy) {\n // If the old attribute matches the id just remove it entirely\n if (describedBy === id) {\n target.removeAttribute('aria-describedby');\n } else {\n // Otherwise we want to just remove the id that was added and reset the attribute to what it was before\n const oldDescribedBy = describedBy.replace(new RegExp(`(?:^|\\\\s+)${id}`), '');\n target.setAttribute('aria-describedby', oldDescribedBy);\n }\n }\n }\n }, [describeTarget, target, show]);\n\n return (\n <Popover\n data-testid={testIds.root}\n id={id}\n {...restProps}\n show={show}\n showDelay={showDelay}\n hideDelay={hideDelay}\n groupId='tooltip'\n strategy='fixed'\n as={StyledTooltip}\n role='tooltip'\n target={target}\n arrow\n placement={placement}\n onMouseDown={onMouseDown}\n hideOnTargetHidden\n ref={tooltipRef}\n >\n {children}\n </Popover>\n );\n});\n\nexport default withTestIds(Tooltip, getTooltipTestIds);\n"]}
@@ -3,12 +3,13 @@ import type { RefObject, DependencyList } from 'react';
3
3
  * @example useArrows(ref, { cycle, selector });
4
4
  * @param ref - A reference to the element that will be navigated through. [React RefObject](https://reactjs.org/docs/refs-and-the-dom.html)
5
5
  */
6
- declare const useArrows: (ref: RefObject<HTMLElement>, { cycle, selector, dir, allowTabFocus, updateTabIndex }?: {
6
+ declare const useArrows: (ref: RefObject<HTMLElement>, { cycle, selector, dir, allowTabFocus, updateTabIndex, initialFocusElement }?: {
7
7
  cycle?: boolean | undefined;
8
8
  selector?: string | undefined;
9
9
  dir?: "up-down" | "left-right" | undefined;
10
10
  allowTabFocus?: boolean | undefined;
11
11
  updateTabIndex?: boolean | undefined;
12
+ initialFocusElement?: Element | null | undefined;
12
13
  }, dependencies?: DependencyList) => void;
13
14
  export default useArrows;
14
15
  //# sourceMappingURL=useArrows.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useArrows.d.ts","sourceRoot":"","sources":["../../src/hooks/useArrows.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAWvD;;;GAGG;AACH,QAAA,MAAM,SAAS,QACR,UAAU,WAAW,CAAC;;;;;;yCA+G5B,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"useArrows.d.ts","sourceRoot":"","sources":["../../src/hooks/useArrows.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAWvD;;;GAGG;AACH,QAAA,MAAM,SAAS,QACR,UAAU,WAAW,CAAC;;;;;;;yCAuI5B,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -16,28 +16,31 @@ cycle = true,
16
16
  /** A query selector that will determine which elements to cycle through with the arrow keys. The selector will be used in conjunction with [querySelectorAll](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll#selectors). */
17
17
  selector = focusable,
18
18
  /** Which keys are used to navigate through the list */
19
- dir = 'up-down', allowTabFocus = true, updateTabIndex = true } = {},
19
+ dir = 'up-down', allowTabFocus = true, updateTabIndex = true,
20
+ /** When focus enters the ref, which element should receive focus first if available */
21
+ initialFocusElement } = {},
20
22
  /** Pass this prop in the internal dependencies when list is dynamic */
21
23
  dependencies = []) => {
22
24
  const [NextKey, PrevKey] = dir === 'up-down' ? ['ArrowDown', 'ArrowUp'] : ['ArrowRight', 'ArrowLeft'];
23
25
  const setTabIndexes = useCallback((el) => {
24
- // don't set tabindex -1 for first element, or an element with a checked input inside of it to be able to focus it
25
- // 0 second timeout added because DOM needs to be up to date after list is updated before running query
26
- setTimeout(() => {
27
- const focusableElements = Array.from(el.querySelectorAll(selector));
28
- if (focusableElements.length > 0) {
29
- if (allowTabFocus)
30
- focusableElements[0].tabIndex = 0;
31
- focusableElements.slice(1).forEach(item => {
32
- if (item instanceof HTMLElement) {
33
- const checked = item.checked;
34
- if (!checked)
35
- item.tabIndex = -1;
36
- }
37
- });
38
- }
39
- }, 0);
40
- }, [selector, ...dependencies]);
26
+ // don't set tabindex -1 for first element, or the initialFocusElement, or an element with a checked input inside of it to be able to focus it
27
+ const focusableElements = Array.from(el.querySelectorAll(selector));
28
+ if (focusableElements.length > 0) {
29
+ let focusIndex = focusableElements.findIndex(focusEl => focusEl === initialFocusElement);
30
+ if (focusIndex === -1)
31
+ focusIndex = 0;
32
+ if (allowTabFocus)
33
+ focusableElements[focusIndex].tabIndex = 0;
34
+ focusableElements.splice(focusIndex, 1);
35
+ focusableElements.forEach(item => {
36
+ if (item instanceof HTMLElement) {
37
+ const checked = item.checked;
38
+ if (!checked)
39
+ item.tabIndex = -1;
40
+ }
41
+ });
42
+ }
43
+ }, [selector, initialFocusElement, ...dependencies]);
41
44
  const listener = useCallback((e) => {
42
45
  const el = ref.current;
43
46
  if (!el)
@@ -56,7 +59,9 @@ dependencies = []) => {
56
59
  const lastIdx = items.length - 1;
57
60
  let newFocusIdx;
58
61
  if (e.key === 'Home' || (e.key === NextKey && focusIdx === -1)) {
59
- newFocusIdx = 0;
62
+ const focusableElements = Array.from(el.querySelectorAll(selector));
63
+ const focusIndex = focusableElements.findIndex(focusEl => focusEl === initialFocusElement);
64
+ newFocusIdx = focusIndex === -1 ? 0 : focusIndex;
60
65
  }
61
66
  else if (e.key === 'End' || (e.key === PrevKey && focusIdx === -1)) {
62
67
  newFocusIdx = lastIdx;
@@ -87,23 +92,43 @@ dependencies = []) => {
87
92
  newFocusIdx = focusIdx - 1;
88
93
  }
89
94
  }
95
+ else if (e.key === 'Tab' && initialFocusElement) {
96
+ // We need to reset the tabIndex for the initial focused element when leaving the group. 0 second timeout necessary to avoid focusing this element instad of leaving the group.
97
+ setTimeout(() => {
98
+ initialFocusElement.tabIndex = 0;
99
+ }, 0);
100
+ return;
101
+ }
90
102
  else {
91
103
  return;
92
104
  }
105
+ // If there is an initial focused element other than the default, the tabIndex must be set to -1 the moment arrow keys are used to prevent that element from being tabbable while within the group focus.
106
+ if ((e.key === PrevKey || e.key === NextKey) && initialFocusElement) {
107
+ initialFocusElement.tabIndex = -1;
108
+ }
93
109
  items[newFocusIdx].focus();
94
- }, [ref.current, cycle, selector, ...dependencies]);
110
+ }, [ref.current, cycle, selector, initialFocusElement, ...dependencies]);
95
111
  useEffect(() => {
96
112
  const el = ref.current;
97
113
  if (!el)
98
114
  return;
99
115
  if (updateTabIndex) {
100
- setTabIndexes(el);
116
+ if (initialFocusElement) {
117
+ // If there is an element defined that should receive default focus, no timeout is necessary
118
+ setTabIndexes(el);
119
+ }
120
+ else {
121
+ // 0 second timeout added because DOM needs to be up to date after list is updated before running query
122
+ setTimeout(() => {
123
+ setTabIndexes(el);
124
+ }, 0);
125
+ }
101
126
  }
102
127
  el.addEventListener('keydown', listener);
103
128
  return () => {
104
129
  el.removeEventListener('keydown', listener);
105
130
  };
106
- }, [ref.current, selector, listener, ...dependencies]);
131
+ }, [ref.current, selector, listener, initialFocusElement, ...dependencies]);
107
132
  };
108
133
  export default useArrows;
109
134
  //# sourceMappingURL=useArrows.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useArrows.js","sourceRoot":"","sources":["../../src/hooks/useArrows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAG/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,SAAS,GAAG;;;;;CAKjB,CAAC;AAEF;;;GAGG;AACH,MAAM,SAAS,GAAG,CAChB,GAA2B,EAC3B;AACE,yKAAyK;AACzK,KAAK,GAAG,IAAI;AACZ,wPAAwP;AACxP,QAAQ,GAAG,SAAS;AACpB,uDAAuD;AACvD,GAAG,GAAG,SAAS,EACf,aAAa,GAAG,IAAI,EACpB,cAAc,GAAG,IAAI,KAOnB,EAAE;AACN,uEAAuE;AACvE,eAA+B,EAAE,EACjC,EAAE;IACF,MAAM,C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AC5B;SACF;aAAM,IAAI,CAAC,CAAC,GAAG,KAAK,OAAO,EAAE;YAC5B,IAAI,QAAQ,KAAK,CAAC,EAAE;gBAClB,IAAI,CAAC,KAAK;oBAAE,OAAO;gBACnB,WAAW,GAAG,OAAO,CAAC;aACvB;iBAAM;gBACL,WAAW,GAAG,QAAQ,GAAG,CAAC,CAAC;aAC5B;SACF;aAAM;YACL,OAAO;SACR;QAED,KAAK,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC,EACD,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAC,CAChD,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC;QACvB,IAAI,CAAC,EAAE;YAAE,OAAO;QAChB,IAAI,cAAc,EAAE;YAClB,aAAa,CAAC,EAAE,CAAC,CAAC;SACnB;QACD,EAAE,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAEzC,OAAO,GAAG,EAAE;YACV,EAAE,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC9C,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import { useEffect, useCallback } from 'react';\nimport type { RefObject, DependencyList } from 'react';\n\nimport { documentIsAvailable } from '../utils';\n\nconst focusable = `\n a[href],\n button:enabled,\n input[type='checkbox']:enabled,\n input[type='radio']:enabled\n`;\n\n/**\n * @example useArrows(ref, { cycle, selector });\n * @param ref - A reference to the element that will be navigated through. [React RefObject](https://reactjs.org/docs/refs-and-the-dom.html)\n */\nconst useArrows = (\n ref: RefObject<HTMLElement>,\n {\n /** If true, the down or up arrow key will navigate to the first or last element if the element currently focused is the last or first index of the selected elements. */\n cycle = true,\n /** A query selector that will determine which elements to cycle through with the arrow keys. The selector will be used in conjunction with [querySelectorAll](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll#selectors). */\n selector = focusable,\n /** Which keys are used to navigate through the list */\n dir = 'up-down',\n allowTabFocus = true,\n updateTabIndex = true\n }: {\n cycle?: boolean;\n selector?: string;\n dir?: 'up-down' | 'left-right';\n allowTabFocus?: boolean;\n updateTabIndex?: boolean;\n } = {},\n /** Pass this prop in the internal dependencies when list is dynamic */\n dependencies: DependencyList = []\n) => {\n const [NextKey, PrevKey] =\n dir === 'up-down' ? ['ArrowDown', 'ArrowUp'] : ['ArrowRight', 'ArrowLeft'];\n\n const setTabIndexes = useCallback(\n (el: HTMLElement) => {\n // don't set tabindex -1 for first element, or an element with a checked input inside of it to be able to focus it\n\n // 0 second timeout added because DOM needs to be up to date after list is updated before running query\n setTimeout(() => {\n const focusableElements = Array.from(el.querySelectorAll(selector));\n\n if (focusableElements.length > 0) {\n if (allowTabFocus) (focusableElements[0] as HTMLElement).tabIndex = 0;\n focusableElements.slice(1).forEach(item => {\n if (item instanceof HTMLElement) {\n const checked = (item as HTMLInputElement).checked;\n if (!checked) item.tabIndex = -1;\n }\n });\n }\n }, 0);\n },\n [selector, ...dependencies]\n );\n\n const listener = useCallback(\n (e: KeyboardEvent) => {\n const el = ref.current;\n if (!el) return;\n if (['Home', 'End', NextKey, PrevKey].includes(e.key)) e.preventDefault();\n\n if (!documentIsAvailable) return;\n\n const items = Array.from(el.querySelectorAll(selector)).filter(\n (item): item is HTMLElement => item instanceof HTMLElement\n );\n\n if (!items.length) return;\n\n const rootNode = el.getRootNode();\n\n if (!(rootNode instanceof Document) && !(rootNode instanceof ShadowRoot)) return;\n\n const focusIdx = items.indexOf(rootNode.activeElement as HTMLElement);\n const lastIdx = items.length - 1;\n let newFocusIdx;\n\n if (e.key === 'Home' || (e.key === NextKey && focusIdx === -1)) {\n newFocusIdx = 0;\n } else if (e.key === 'End' || (e.key === PrevKey && focusIdx === -1)) {\n newFocusIdx = lastIdx;\n } else if (e.key === 'Enter') {\n if (updateTabIndex) {\n setTabIndexes(el);\n }\n return;\n } else if (e.key === NextKey) {\n if (focusIdx === lastIdx) {\n if (!cycle) return;\n newFocusIdx = 0;\n } else {\n newFocusIdx = focusIdx + 1;\n }\n } else if (e.key === PrevKey) {\n if (focusIdx === 0) {\n if (!cycle) return;\n newFocusIdx = lastIdx;\n } else {\n newFocusIdx = focusIdx - 1;\n }\n } else {\n return;\n }\n\n items[newFocusIdx].focus();\n },\n [ref.current, cycle, selector, ...dependencies]\n );\n\n useEffect(() => {\n const el = ref.current;\n if (!el) return;\n if (updateTabIndex) {\n setTabIndexes(el);\n }\n el.addEventListener('keydown', listener);\n\n return () => {\n el.removeEventListener('keydown', listener);\n };\n }, [ref.current, selector, listener, ...dependencies]);\n};\n\nexport default useArrows;\n"]}
1
+ {"version":3,"file":"useArrows.js","sourceRoot":"","sources":["../../src/hooks/useArrows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAG/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,SAAS,GAAG;;;;;CAKjB,CAAC;AAEF;;;GAGG;AACH,MAAM,SAAS,GAAG,CAChB,GAA2B,EAC3B;AACE,yKAAyK;AACzK,KAAK,GAAG,IAAI;AACZ,wPAAwP;AACxP,QAAQ,GAAG,SAAS;AACpB,uDAAuD;AACvD,GAAG,GAAG,SAAS,EACf,aAAa,GAAG,IAAI,EACpB,cAAc,GAAG,IAAI;AACrB,uFAAuF;AACvF,mBAAmB,KAQjB,EAAE;AACN,uEAAuE;AACvE,eAA+B,EAAE,EACjC,EAAE;IACF,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GACtB,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC,CAA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OAAO;QAChB,IAAI,cAAc,EAAE;YAClB,IAAI,mBAAmB,EAAE;gBACvB,4FAA4F;gBAC5F,aAAa,CAAC,EAAE,CAAC,CAAC;aACnB;iBAAM;gBACL,uGAAuG;gBACvG,UAAU,CAAC,GAAG,EAAE;oBACd,aAAa,CAAC,EAAE,CAAC,CAAC;gBACpB,CAAC,EAAE,CAAC,CAAC,CAAC;aACP;SACF;QACD,EAAE,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAEzC,OAAO,GAAG,EAAE;YACV,EAAE,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC9C,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,mBAAmB,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC;AAC9E,CAAC,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import { useEffect, useCallback } from 'react';\nimport type { RefObject, DependencyList } from 'react';\n\nimport { documentIsAvailable } from '../utils';\n\nconst focusable = `\n a[href],\n button:enabled,\n input[type='checkbox']:enabled,\n input[type='radio']:enabled\n`;\n\n/**\n * @example useArrows(ref, { cycle, selector });\n * @param ref - A reference to the element that will be navigated through. [React RefObject](https://reactjs.org/docs/refs-and-the-dom.html)\n */\nconst useArrows = (\n ref: RefObject<HTMLElement>,\n {\n /** If true, the down or up arrow key will navigate to the first or last element if the element currently focused is the last or first index of the selected elements. */\n cycle = true,\n /** A query selector that will determine which elements to cycle through with the arrow keys. The selector will be used in conjunction with [querySelectorAll](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll#selectors). */\n selector = focusable,\n /** Which keys are used to navigate through the list */\n dir = 'up-down',\n allowTabFocus = true,\n updateTabIndex = true,\n /** When focus enters the ref, which element should receive focus first if available */\n initialFocusElement\n }: {\n cycle?: boolean;\n selector?: string;\n dir?: 'up-down' | 'left-right';\n allowTabFocus?: boolean;\n updateTabIndex?: boolean;\n initialFocusElement?: Element | null;\n } = {},\n /** Pass this prop in the internal dependencies when list is dynamic */\n dependencies: DependencyList = []\n) => {\n const [NextKey, PrevKey] =\n dir === 'up-down' ? ['ArrowDown', 'ArrowUp'] : ['ArrowRight', 'ArrowLeft'];\n\n const setTabIndexes = useCallback(\n (el: HTMLElement) => {\n // don't set tabindex -1 for first element, or the initialFocusElement, or an element with a checked input inside of it to be able to focus it\n const focusableElements = Array.from(el.querySelectorAll(selector));\n\n if (focusableElements.length > 0) {\n let focusIndex = focusableElements.findIndex(focusEl => focusEl === initialFocusElement);\n if (focusIndex === -1) focusIndex = 0;\n\n if (allowTabFocus) (focusableElements[focusIndex] as HTMLElement).tabIndex = 0;\n focusableElements.splice(focusIndex, 1);\n focusableElements.forEach(item => {\n if (item instanceof HTMLElement) {\n const checked = (item as HTMLInputElement).checked;\n if (!checked) item.tabIndex = -1;\n }\n });\n }\n },\n [selector, initialFocusElement, ...dependencies]\n );\n\n const listener = useCallback(\n (e: KeyboardEvent) => {\n const el = ref.current;\n if (!el) return;\n if (['Home', 'End', NextKey, PrevKey].includes(e.key)) e.preventDefault();\n\n if (!documentIsAvailable) return;\n\n const items = Array.from(el.querySelectorAll(selector)).filter(\n (item): item is HTMLElement => item instanceof HTMLElement\n );\n\n if (!items.length) return;\n\n const rootNode = el.getRootNode();\n\n if (!(rootNode instanceof Document) && !(rootNode instanceof ShadowRoot)) return;\n\n const focusIdx = items.indexOf(rootNode.activeElement as HTMLElement);\n const lastIdx = items.length - 1;\n let newFocusIdx;\n\n if (e.key === 'Home' || (e.key === NextKey && focusIdx === -1)) {\n const focusableElements = Array.from(el.querySelectorAll(selector));\n const focusIndex = focusableElements.findIndex(focusEl => focusEl === initialFocusElement);\n newFocusIdx = focusIndex === -1 ? 0 : focusIndex;\n } else if (e.key === 'End' || (e.key === PrevKey && focusIdx === -1)) {\n newFocusIdx = lastIdx;\n } else if (e.key === 'Enter') {\n if (updateTabIndex) {\n setTabIndexes(el);\n }\n return;\n } else if (e.key === NextKey) {\n if (focusIdx === lastIdx) {\n if (!cycle) return;\n newFocusIdx = 0;\n } else {\n newFocusIdx = focusIdx + 1;\n }\n } else if (e.key === PrevKey) {\n if (focusIdx === 0) {\n if (!cycle) return;\n newFocusIdx = lastIdx;\n } else {\n newFocusIdx = focusIdx - 1;\n }\n } else if (e.key === 'Tab' && initialFocusElement) {\n // We need to reset the tabIndex for the initial focused element when leaving the group. 0 second timeout necessary to avoid focusing this element instad of leaving the group.\n setTimeout(() => {\n (initialFocusElement as HTMLElement).tabIndex = 0;\n }, 0);\n return;\n } else {\n return;\n }\n\n // If there is an initial focused element other than the default, the tabIndex must be set to -1 the moment arrow keys are used to prevent that element from being tabbable while within the group focus.\n if ((e.key === PrevKey || e.key === NextKey) && initialFocusElement) {\n (initialFocusElement as HTMLElement).tabIndex = -1;\n }\n\n items[newFocusIdx].focus();\n },\n [ref.current, cycle, selector, initialFocusElement, ...dependencies]\n );\n\n useEffect(() => {\n const el = ref.current;\n if (!el) return;\n if (updateTabIndex) {\n if (initialFocusElement) {\n // If there is an element defined that should receive default focus, no timeout is necessary\n setTabIndexes(el);\n } else {\n // 0 second timeout added because DOM needs to be up to date after list is updated before running query\n setTimeout(() => {\n setTabIndexes(el);\n }, 0);\n }\n }\n el.addEventListener('keydown', listener);\n\n return () => {\n el.removeEventListener('keydown', listener);\n };\n }, [ref.current, selector, listener, initialFocusElement, ...dependencies]);\n};\n\nexport default useArrows;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"useFocusTrap.d.ts","sourceRoot":"","sources":["../../src/hooks/useFocusTrap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAMvD;;;;;GAKG;AACH,QAAA,MAAM,YAAY,eACJ,UAAU,WAAW,CAAC,qBAChB,OAAO,wCAyB1B,CAAC;AAEF,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"useFocusTrap.d.ts","sourceRoot":"","sources":["../../src/hooks/useFocusTrap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAMvD;;;;;GAKG;AACH,QAAA,MAAM,YAAY,eACJ,UAAU,WAAW,CAAC,qBAChB,OAAO,wCAgD1B,CAAC;AAEF,eAAe,YAAY,CAAC"}