@registrucentras/rc-ses-react-components 2.0.0-rc.6 → 2.0.0-rc.8

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 (247) hide show
  1. package/dist/components/common/Accordion/hooks/useAccordionController.d.ts +2 -2
  2. package/dist/components/common/Accordion/types/AccordionControllerState.d.ts +2 -2
  3. package/dist/components/common/AdvancedList/components/AdvancedListItem/AdvancedListItem.types.d.ts +2 -2
  4. package/dist/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemLeading.d.ts +2 -2
  5. package/dist/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemTrailing.d.ts +2 -2
  6. package/dist/components/common/Badge/index.d.ts +2 -2
  7. package/dist/components/common/Breadcrumbs/index.d.ts +4 -4
  8. package/dist/components/common/Card/index.d.ts +2 -2
  9. package/dist/components/common/CardShell/CardFooter/index.d.ts +1 -1
  10. package/dist/components/common/CardShell/CardFooter/types.d.ts +4 -9
  11. package/dist/components/common/CardShell/types.d.ts +4 -4
  12. package/dist/components/common/IconWithCircularBackground.d.ts +2 -2
  13. package/dist/components/common/IconWithSquareBackground/index.d.ts +2 -2
  14. package/dist/components/common/ImageCard/index.d.ts +2 -2
  15. package/dist/components/common/SelectableCardList/components/SelectableCardListItem.d.ts +2 -2
  16. package/dist/components/common/SelectableCardList/index.d.ts +2 -2
  17. package/dist/components/common/ServiceLinks/types.d.ts +6 -6
  18. package/dist/components/common/SideNav/SideNav.types.d.ts +7 -5
  19. package/dist/components/common/SideNav/SideNavLayout.d.ts +1 -1
  20. package/dist/components/common/SideNav/components/SideNavPill.d.ts +2 -2
  21. package/dist/components/common/SideNav/components/SideNavPillList.d.ts +2 -2
  22. package/dist/components/common/SideNav/components/SideNavRow.d.ts +4 -3
  23. package/dist/components/common/SideNav/hooks/useKeepActiveItemInView.d.ts +19 -0
  24. package/dist/components/common/SideNav/hooks/useSideNavScrollSpy.d.ts +2 -2
  25. package/dist/components/common/SideNav/index.d.ts +2 -2
  26. package/dist/components/common/Tabs/TabPanel.d.ts +2 -2
  27. package/dist/components/common/Tabs/TabsWrapper.d.ts +2 -2
  28. package/dist/components/common/TitleBlock/types.d.ts +4 -4
  29. package/dist/components/form/components/FormControlWrapper/components/FieldSuffix.d.ts +2 -2
  30. package/dist/components/form/components/FormControlWrapper/index.d.ts +2 -2
  31. package/dist/components/form/inputs/RadioButtonGroup.d.ts +3 -3
  32. package/dist/components/form/inputs/SearchableField.d.ts +2 -2
  33. package/dist/components/form/inputs/Select/Select.types.d.ts +2 -2
  34. package/dist/components/layout/Footer/index.d.ts +2 -2
  35. package/dist/components/layout/ServiceFormActions.d.ts +2 -2
  36. package/dist/components/layout/ServiceFormContainer/AccordionFormContainer/components/AccordionCollapseControls.d.ts +2 -2
  37. package/dist/components/layout/ServiceFormContainer/AccordionFormContainer/index.d.ts +2 -2
  38. package/dist/components/layout/ServiceHeader.d.ts +2 -2
  39. package/dist/components/layout/ServicePage.d.ts +2 -2
  40. package/dist/components/utils/normalizeSx.d.ts +1 -1
  41. package/dist/library/types.d.ts +2 -2
  42. package/dist/registrucentras-rc-ses-react-components.cjs +1 -1
  43. package/dist/registrucentras-rc-ses-react-components.js +1767 -1672
  44. package/dist/theme/cards.d.ts +4 -0
  45. package/dist/types/assets/IconProps.d.ts +2 -2
  46. package/dist/types/cards/CardServiceProps.d.ts +2 -2
  47. package/dist/types/common/QuickLinkType.d.ts +2 -2
  48. package/dist/types/inputs/InputIconProps.d.ts +2 -2
  49. package/dist/types/lists/ListNewsItemType.d.ts +2 -2
  50. package/dist/types/lists/ListServicesItemType.d.ts +3 -3
  51. package/package.json +2 -1
  52. package/src/components/common/Accordion/hooks/useAccordionController.tsx +1 -1
  53. package/src/components/common/Accordion/index.tsx +1 -4
  54. package/src/components/common/Accordion/types/AccordionControllerState.ts +1 -1
  55. package/src/components/common/AdvancedList/components/AdvancedListItem/AdvancedListItem.types.ts +1 -1
  56. package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemLeading.tsx +1 -1
  57. package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemTrailing.tsx +1 -1
  58. package/src/components/common/AdvancedList/components/AdvancedListItem/index.test.tsx +2 -2
  59. package/src/components/common/Badge/index.tsx +3 -3
  60. package/src/components/common/Breadcrumbs/index.tsx +5 -2
  61. package/src/components/common/Card/index.tsx +1 -1
  62. package/src/components/common/CardShell/CardFooter/index.tsx +5 -3
  63. package/src/components/common/CardShell/CardFooter/types.ts +2 -7
  64. package/src/components/common/CardShell/index.tsx +31 -7
  65. package/src/components/common/CardShell/types.ts +2 -2
  66. package/src/components/common/IconWithCircularBackground.tsx +7 -8
  67. package/src/components/common/IconWithSquareBackground/index.tsx +7 -8
  68. package/src/components/common/ImageCard/index.tsx +1 -1
  69. package/src/components/common/SegmentedControl/components/SegmentButton/index.tsx +18 -19
  70. package/src/components/common/SelectableCardList/components/SelectableCardListItem.tsx +1 -1
  71. package/src/components/common/SelectableCardList/index.tsx +1 -1
  72. package/src/components/common/ServiceLinks/types.ts +3 -3
  73. package/src/components/common/SideNav/SideNav.types.ts +11 -3
  74. package/src/components/common/SideNav/SideNavLayout.tsx +3 -0
  75. package/src/components/common/SideNav/components/SideNavPill.tsx +1 -1
  76. package/src/components/common/SideNav/components/SideNavPillList.tsx +8 -23
  77. package/src/components/common/SideNav/components/SideNavRow.tsx +6 -2
  78. package/src/components/common/SideNav/hooks/useKeepActiveItemInView.test.ts +258 -0
  79. package/src/components/common/SideNav/hooks/useKeepActiveItemInView.ts +80 -0
  80. package/src/components/common/SideNav/hooks/useSideNavScrollSpy.test.ts +9 -2
  81. package/src/components/common/SideNav/hooks/useSideNavScrollSpy.ts +4 -3
  82. package/src/components/common/SideNav/index.test.tsx +51 -0
  83. package/src/components/common/SideNav/index.tsx +47 -12
  84. package/src/components/common/Snackbar/index.test.tsx +40 -0
  85. package/src/components/common/Snackbar/index.tsx +9 -3
  86. package/src/components/common/Tabs/TabPanel.tsx +1 -1
  87. package/src/components/common/Tabs/TabsWrapper.tsx +1 -1
  88. package/src/components/common/TitleBlock/index.test.tsx +9 -7
  89. package/src/components/common/TitleBlock/index.tsx +34 -11
  90. package/src/components/common/TitleBlock/types.ts +2 -2
  91. package/src/components/form/components/FormControlWrapper/components/FieldSuffix.tsx +1 -1
  92. package/src/components/form/components/FormControlWrapper/index.tsx +1 -1
  93. package/src/components/form/inputs/Datepicker/index.test.tsx +1 -1
  94. package/src/components/form/inputs/FileDropzone.tsx +1 -4
  95. package/src/components/form/inputs/NumberStepper.test.tsx +83 -0
  96. package/src/components/form/inputs/NumberStepper.tsx +7 -8
  97. package/src/components/form/inputs/RadioButtonGroup.test.tsx +1 -1
  98. package/src/components/form/inputs/RadioButtonGroup.tsx +2 -2
  99. package/src/components/form/inputs/SearchInput/index.tsx +1 -1
  100. package/src/components/form/inputs/SearchableField.test.tsx +2 -2
  101. package/src/components/form/inputs/SearchableField.tsx +1 -1
  102. package/src/components/form/inputs/Select/Select.types.ts +1 -1
  103. package/src/components/form/inputs/Select/index.test.tsx +3 -3
  104. package/src/components/layout/Footer/index.tsx +1 -1
  105. package/src/components/layout/ServiceFormActions.tsx +1 -1
  106. package/src/components/layout/ServiceFormContainer/AccordionFormContainer/components/AccordionCollapseControls.tsx +1 -1
  107. package/src/components/layout/ServiceFormContainer/AccordionFormContainer/index.tsx +1 -1
  108. package/src/components/layout/ServiceHeader.tsx +1 -1
  109. package/src/components/layout/ServicePage.tsx +1 -1
  110. package/src/components/utils/normalizeSx.ts +2 -4
  111. package/src/examples/ListWithPagination/index.tsx +0 -2
  112. package/src/examples/MultipleStepForm/components/AdditionalServicesForm.tsx +1 -1
  113. package/src/examples/MultipleStepForm/components/ServiceIssuanceForm.tsx +1 -1
  114. package/src/examples/MultipleStepForm/components/TermsAndConditionsForm.tsx +1 -1
  115. package/src/examples/MultipleStepForm/types/MultiStepFormModel.ts +1 -1
  116. package/src/examples/SingleStepForm/components/ObjectIdentifierSearchModal.tsx +2 -2
  117. package/src/examples/SingleStepForm/types/SingleStepFormModel.ts +1 -1
  118. package/src/library/types.ts +2 -1
  119. package/src/stories/Welcome.mdx +25 -2
  120. package/src/stories/{components/display → atoms}/Badge.stories.tsx +1 -1
  121. package/src/stories/{components/actions → atoms}/Button.stories.tsx +10 -15
  122. package/src/stories/{components/inputs → atoms}/Checkbox.stories.tsx +2 -2
  123. package/src/stories/{components/icons → atoms}/IconWithCircularBackground.stories.tsx +1 -1
  124. package/src/stories/{components/icons → atoms}/IconWithSquareBackground.stories.tsx +1 -1
  125. package/src/stories/{components/icons → atoms}/Icons.stories.tsx +2 -2
  126. package/src/stories/{components/loaders → atoms}/Loader.stories.tsx +1 -1
  127. package/src/stories/{components/loaders → atoms}/LoadingSpinner.stories.tsx +1 -1
  128. package/src/stories/{assets → atoms}/Logo.stories.tsx +1 -1
  129. package/src/stories/{components/inputs → atoms}/NumberStepper.stories.tsx +2 -2
  130. package/src/stories/{components/inputs → atoms}/PhoneInput.stories.tsx +2 -2
  131. package/src/stories/{components/inputs → atoms}/SearchInput.stories.tsx +1 -1
  132. package/src/stories/{components/inputs → atoms}/Select.stories.tsx +8 -10
  133. package/src/stories/{components/form → atoms}/SimpleCheckbox.stories.tsx +1 -1
  134. package/src/stories/{components/inputs → atoms}/Switch.stories.tsx +2 -2
  135. package/src/stories/{components/tabs → atoms}/Tab.stories.tsx +1 -1
  136. package/src/stories/{components/inputs → atoms}/TextField.stories.tsx +1 -1
  137. package/src/stories/{components/display → atoms}/Tooltip.stories.tsx +2 -2
  138. package/src/stories/{theme → foundations}/ThemedMuiComponents.stories.tsx +1 -1
  139. package/src/stories/{components/feedback → molecules}/Alert.stories.tsx +3 -3
  140. package/src/stories/{components/navigation → molecules}/Breadcrumbs.stories.tsx +1 -1
  141. package/src/stories/{components/actions → molecules}/ButtonWithPopover.stories.tsx +1 -1
  142. package/src/stories/{components/display → molecules}/Card.stories.tsx +1 -1
  143. package/src/stories/{components/display → molecules}/CardShell.stories.tsx +20 -1
  144. package/src/stories/{components/form → molecules}/CheckboxFormControl.stories.tsx +14 -22
  145. package/src/stories/{components/inputs → molecules}/DatePicker.stories.tsx +1 -1
  146. package/src/stories/{components/form → molecules}/FormControlWrapper.stories.tsx +1 -1
  147. package/src/stories/{components/display → molecules}/ImageCard.stories.tsx +1 -1
  148. package/src/stories/{components/display → molecules}/ListWithIcons.stories.tsx +1 -1
  149. package/src/stories/{components/inputs → molecules}/PhoneInputFormControl.stories.tsx +1 -1
  150. package/src/stories/{components/overlays → molecules}/Popover.stories.tsx +1 -1
  151. package/src/stories/{components/inputs → molecules}/RadioButtonGroup.stories.tsx +2 -2
  152. package/src/stories/{components/inputs → molecules}/SearchableField.stories.tsx +1 -1
  153. package/src/stories/{components/display → molecules}/SegmentedControl.stories.tsx +2 -2
  154. package/src/stories/{components/feedback → molecules}/Snackbar.stories.tsx +3 -3
  155. package/src/stories/{components/tabs → molecules}/TabPanel.stories.tsx +1 -1
  156. package/src/stories/{components/tabs → molecules}/Tabs.stories.tsx +1 -1
  157. package/src/stories/{components/tabs → molecules}/TabsWrapper.stories.tsx +1 -1
  158. package/src/stories/{components/display → molecules}/TitleBlock.stories.tsx +65 -3
  159. package/src/stories/{components/navigation → organisms}/Accordion.stories.tsx +1 -1
  160. package/src/stories/{components/display → organisms}/AdvancedList.stories.tsx +5 -5
  161. package/src/stories/{components/display → organisms}/AdvancedListItem.stories.tsx +1 -1
  162. package/src/stories/{components/form → organisms}/CardFormContainer.stories.tsx +1 -1
  163. package/src/stories/{components/navigation → organisms}/DataPagination.stories.tsx +1 -1
  164. package/src/stories/{components/overlays → organisms}/Dialog.stories.tsx +1 -1
  165. package/src/stories/{components/inputs → organisms}/FileDropzone.stories.tsx +2 -2
  166. package/src/stories/{components/inputs → organisms}/FileUpload.stories.tsx +2 -2
  167. package/src/stories/{components/layout → organisms}/Footer.stories.tsx +1 -1
  168. package/src/stories/{components/loaders → organisms}/FullPageLoader.stories.tsx +1 -1
  169. package/src/stories/{components/overlays → organisms}/Modal.stories.tsx +1 -1
  170. package/src/stories/{components/display → organisms}/SelectableCardList.stories.tsx +1 -1
  171. package/src/stories/{components/form → organisms}/ServiceFormActions.stories.tsx +1 -1
  172. package/src/stories/{components/form → organisms}/ServiceFormContainer.stories.tsx +1 -1
  173. package/src/stories/{components/layout → organisms}/ServiceHeader.stories.tsx +1 -1
  174. package/src/stories/{components/display → organisms}/ServiceLinks.stories.tsx +1 -1
  175. package/src/stories/{components/navigation → organisms}/ServiceWizardStepper.stories.tsx +3 -3
  176. package/src/stories/{components/navigation → organisms}/SideNav.stories.tsx +37 -4
  177. package/src/stories/{components/layout → templates}/ServicePage.stories.tsx +1 -1
  178. package/src/stubs/Component.tsx +4 -4
  179. package/src/theme/cards.ts +2 -0
  180. package/src/types/assets/IconProps.tsx +1 -1
  181. package/src/types/cards/CardServiceProps.tsx +1 -1
  182. package/src/types/common/QuickLinkType.tsx +1 -1
  183. package/src/types/inputs/InputIconProps.tsx +1 -1
  184. package/src/types/lists/ListNewsItemType.tsx +1 -1
  185. package/src/types/lists/ListServicesItemType.tsx +2 -2
  186. package/src/vite-env.d.ts +2 -2
  187. package/dist/stories/assets/Logo.stories.d.ts +0 -12
  188. package/dist/stories/components/actions/Button.stories.d.ts +0 -107
  189. package/dist/stories/components/actions/ButtonWithPopover.stories.d.ts +0 -7
  190. package/dist/stories/components/display/AdvancedList.stories.d.ts +0 -33
  191. package/dist/stories/components/display/AdvancedListItem.stories.d.ts +0 -33
  192. package/dist/stories/components/display/Badge.stories.d.ts +0 -9
  193. package/dist/stories/components/display/Card.stories.d.ts +0 -8
  194. package/dist/stories/components/display/CardShell.stories.d.ts +0 -17
  195. package/dist/stories/components/display/ImageCard.stories.d.ts +0 -8
  196. package/dist/stories/components/display/ListWithIcons.stories.d.ts +0 -34
  197. package/dist/stories/components/display/SegmentedControl.stories.d.ts +0 -202
  198. package/dist/stories/components/display/SelectableCardList.stories.d.ts +0 -37
  199. package/dist/stories/components/display/ServiceLinks.stories.d.ts +0 -28
  200. package/dist/stories/components/display/TitleBlock.stories.d.ts +0 -21
  201. package/dist/stories/components/display/Tooltip.stories.d.ts +0 -48
  202. package/dist/stories/components/feedback/Alert.stories.d.ts +0 -14
  203. package/dist/stories/components/feedback/Snackbar.stories.d.ts +0 -143
  204. package/dist/stories/components/form/CardFormContainer.stories.d.ts +0 -7
  205. package/dist/stories/components/form/CheckboxFormControl.stories.d.ts +0 -9
  206. package/dist/stories/components/form/FormControlWrapper.stories.d.ts +0 -7
  207. package/dist/stories/components/form/ServiceFormActions.stories.d.ts +0 -6
  208. package/dist/stories/components/form/ServiceFormContainer.stories.d.ts +0 -15
  209. package/dist/stories/components/form/SimpleCheckbox.stories.d.ts +0 -19
  210. package/dist/stories/components/icons/IconWithCircularBackground.stories.d.ts +0 -6
  211. package/dist/stories/components/icons/IconWithSquareBackground.stories.d.ts +0 -7
  212. package/dist/stories/components/icons/Icons.stories.d.ts +0 -7
  213. package/dist/stories/components/inputs/Checkbox.stories.d.ts +0 -21
  214. package/dist/stories/components/inputs/DatePicker.stories.d.ts +0 -152
  215. package/dist/stories/components/inputs/FileDropzone.stories.d.ts +0 -6
  216. package/dist/stories/components/inputs/FileUpload.stories.d.ts +0 -18
  217. package/dist/stories/components/inputs/NumberStepper.stories.d.ts +0 -6
  218. package/dist/stories/components/inputs/PhoneInput.stories.d.ts +0 -10
  219. package/dist/stories/components/inputs/PhoneInputFormControl.stories.d.ts +0 -6
  220. package/dist/stories/components/inputs/RadioButtonGroup.stories.d.ts +0 -6
  221. package/dist/stories/components/inputs/SearchInput.stories.d.ts +0 -11
  222. package/dist/stories/components/inputs/SearchableField.stories.d.ts +0 -6
  223. package/dist/stories/components/inputs/Select.stories.d.ts +0 -7
  224. package/dist/stories/components/inputs/Switch.stories.d.ts +0 -17
  225. package/dist/stories/components/inputs/TextField.stories.d.ts +0 -6
  226. package/dist/stories/components/layout/Footer.stories.d.ts +0 -6
  227. package/dist/stories/components/layout/ServiceHeader.stories.d.ts +0 -7
  228. package/dist/stories/components/layout/ServicePage.stories.d.ts +0 -6
  229. package/dist/stories/components/loaders/FullPageLoader.stories.d.ts +0 -37
  230. package/dist/stories/components/loaders/Loader.stories.d.ts +0 -36
  231. package/dist/stories/components/loaders/LoadingSpinner.stories.d.ts +0 -62
  232. package/dist/stories/components/navigation/Accordion.stories.d.ts +0 -18
  233. package/dist/stories/components/navigation/Breadcrumbs.stories.d.ts +0 -6
  234. package/dist/stories/components/navigation/DataPagination.stories.d.ts +0 -47
  235. package/dist/stories/components/navigation/ServiceWizardStepper.stories.d.ts +0 -7
  236. package/dist/stories/components/navigation/SideNav.stories.d.ts +0 -7
  237. package/dist/stories/components/overlays/Dialog.stories.d.ts +0 -15
  238. package/dist/stories/components/overlays/Modal.stories.d.ts +0 -10
  239. package/dist/stories/components/overlays/Popover.stories.d.ts +0 -12
  240. package/dist/stories/components/tabs/Tab.stories.d.ts +0 -8
  241. package/dist/stories/components/tabs/TabPanel.stories.d.ts +0 -7
  242. package/dist/stories/components/tabs/Tabs.stories.d.ts +0 -7
  243. package/dist/stories/components/tabs/TabsWrapper.stories.d.ts +0 -6
  244. package/dist/stories/theme/ThemedMuiComponents.stories.d.ts +0 -25
  245. package/src/stories/components/display/Card.test.tsx +0 -19
  246. /package/src/stories/{components/actions → atoms}/Button.test.ts +0 -0
  247. /package/src/stories/{Colors.mdx → foundations/Colors.mdx} +0 -0
@@ -4,19 +4,20 @@ import { useCallback, useEffect, useRef, useState } from 'react'
4
4
  import palette, { common } from '@/theme/palette'
5
5
 
6
6
  import { RcSesSideNavItem } from '../SideNav.types'
7
+ import useKeepActiveItemInView from '../hooks/useKeepActiveItemInView'
7
8
  import SideNavPill from './SideNavPill'
8
9
 
9
10
  const FADE_WIDTH = '2rem'
10
11
  const SCROLL_EPSILON = 1
11
12
 
12
- type Props = {
13
+ interface Props {
13
14
  items: RcSesSideNavItem[]
14
15
  activeItemId?: string
15
16
  onItemClick?: (id: string) => void
16
17
  getItemAriaLabel: (item: RcSesSideNavItem) => string | undefined
17
18
  }
18
19
 
19
- type ScrollState = {
20
+ interface ScrollState {
20
21
  hasOverflow: boolean
21
22
  showRightFade: boolean
22
23
  thumbWidth: number
@@ -89,27 +90,11 @@ function SideNavPillList({ items, activeItemId, onItemClick, getItemAriaLabel }:
89
90
  }
90
91
  }, [items, updateScrollState])
91
92
 
92
- useEffect(() => {
93
- if (!activeItemId) return
94
- const container = scrollRef.current
95
- const target = container?.querySelector<HTMLElement>(
96
- `[data-item-id="${activeItemId}"]`,
97
- )
98
- if (!container || !target) return
99
-
100
- // Viewport rects on both, so they agree: offsetLeft would be relative to the
101
- // positioned wrapper, not the scroll container.
102
- const containerRect = container.getBoundingClientRect()
103
- const targetRect = target.getBoundingClientRect()
104
- const overflowLeft = containerRect.left - targetRect.left
105
- const overflowRight = targetRect.right - containerRect.right
106
-
107
- if (overflowLeft > 0) {
108
- container.scrollLeft -= overflowLeft
109
- } else if (overflowRight > 0) {
110
- container.scrollLeft += overflowRight
111
- }
112
- }, [activeItemId])
93
+ useKeepActiveItemInView({
94
+ containerRef: scrollRef,
95
+ activeItemId,
96
+ axis: 'horizontal',
97
+ })
113
98
 
114
99
  return (
115
100
  <Box>
@@ -4,7 +4,8 @@ import palette from '@/theme/palette'
4
4
 
5
5
  const BORDER_WIDTH = '0.125rem'
6
6
 
7
- type Props = {
7
+ interface Props {
8
+ itemId: string
8
9
  label: string
9
10
  count?: number
10
11
  ariaLabel?: string
@@ -12,12 +13,13 @@ type Props = {
12
13
  onClick?: () => void
13
14
  }
14
15
 
15
- function SideNavRow({ label, count, ariaLabel, active, onClick }: Props) {
16
+ function SideNavRow({ itemId, label, count, ariaLabel, active, onClick }: Props) {
16
17
  return (
17
18
  <Box
18
19
  component={onClick ? 'button' : 'div'}
19
20
  type={onClick ? 'button' : undefined}
20
21
  onClick={onClick}
22
+ data-item-id={itemId}
21
23
  aria-current={active ? 'page' : undefined}
22
24
  aria-label={ariaLabel}
23
25
  sx={{
@@ -32,6 +34,8 @@ function SideNavRow({ label, count, ariaLabel, active, onClick }: Props) {
32
34
  backgroundColor: active ? palette.primary[50] : 'transparent',
33
35
  padding: '0.75rem 1rem',
34
36
  textAlign: 'left',
37
+ // A scrolling list (overflow='scroll') must not shrink its rows to fit.
38
+ flexShrink: 0,
35
39
  cursor: onClick ? 'pointer' : 'default',
36
40
  '&:hover': onClick && !active ? { backgroundColor: palette.grey[50] } : undefined,
37
41
  '&:focus-visible': {
@@ -0,0 +1,258 @@
1
+ import { renderHook } from '@testing-library/react'
2
+ import { RefObject } from 'react'
3
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
4
+
5
+ import useKeepActiveItemInView from './useKeepActiveItemInView'
6
+
7
+ interface Rect {
8
+ top: number
9
+ bottom: number
10
+ left: number
11
+ right: number
12
+ }
13
+
14
+ const CONTAINER_RECT: Rect = { top: 100, bottom: 400, left: 100, right: 400 }
15
+
16
+ // jsdom has no layout, so every rect the hook reads has to be supplied here.
17
+ const stubRect = (element: HTMLElement, rect: Rect) => {
18
+ element.getBoundingClientRect = () => rect as DOMRect
19
+ }
20
+
21
+ const setup = (itemRect: Rect, itemId = 'documents') => {
22
+ const container = document.createElement('div')
23
+ const item = document.createElement('div')
24
+ item.setAttribute('data-item-id', itemId)
25
+ container.appendChild(item)
26
+ document.body.appendChild(container)
27
+
28
+ stubRect(container, CONTAINER_RECT)
29
+ stubRect(item, itemRect)
30
+
31
+ // Element.scrollTo is not implemented in jsdom; the hook falls back to the
32
+ // scrollTop/scrollLeft assignment without it, which would hide the smooth path.
33
+ const scrollTo = vi.fn()
34
+ container.scrollTo = scrollTo
35
+
36
+ let scrollTop = 0
37
+ let scrollLeft = 0
38
+ Object.defineProperty(container, 'scrollTop', {
39
+ get: () => scrollTop,
40
+ set: (value: number) => {
41
+ scrollTop = value
42
+ },
43
+ configurable: true,
44
+ })
45
+ Object.defineProperty(container, 'scrollLeft', {
46
+ get: () => scrollLeft,
47
+ set: (value: number) => {
48
+ scrollLeft = value
49
+ },
50
+ configurable: true,
51
+ })
52
+
53
+ return {
54
+ containerRef: { current: container } as RefObject<HTMLElement>,
55
+ scrollTo,
56
+ getScrollTop: () => scrollTop,
57
+ getScrollLeft: () => scrollLeft,
58
+ }
59
+ }
60
+
61
+ const prefersReducedMotion = (matches: boolean) =>
62
+ vi.stubGlobal(
63
+ 'matchMedia',
64
+ vi.fn(() => ({ matches })),
65
+ )
66
+
67
+ beforeEach(() => {
68
+ document.body.innerHTML = ''
69
+ prefersReducedMotion(false)
70
+ })
71
+
72
+ afterEach(() => {
73
+ vi.unstubAllGlobals()
74
+ })
75
+
76
+ describe('useKeepActiveItemInView', () => {
77
+ it('scrolls up by exactly the amount the item overflows the top edge', () => {
78
+ const { containerRef, getScrollTop } = setup({
79
+ top: 60,
80
+ bottom: 100,
81
+ left: 100,
82
+ right: 400,
83
+ })
84
+
85
+ renderHook(() =>
86
+ useKeepActiveItemInView({
87
+ containerRef,
88
+ activeItemId: 'documents',
89
+ axis: 'vertical',
90
+ }),
91
+ )
92
+
93
+ expect(getScrollTop()).toBe(-40)
94
+ })
95
+
96
+ it('scrolls down by exactly the amount the item overflows the bottom edge', () => {
97
+ const { containerRef, getScrollTop } = setup({
98
+ top: 380,
99
+ bottom: 425,
100
+ left: 100,
101
+ right: 400,
102
+ })
103
+
104
+ renderHook(() =>
105
+ useKeepActiveItemInView({
106
+ containerRef,
107
+ activeItemId: 'documents',
108
+ axis: 'vertical',
109
+ }),
110
+ )
111
+
112
+ expect(getScrollTop()).toBe(25)
113
+ })
114
+
115
+ it('leaves the scroll position alone when the item is already visible', () => {
116
+ const { containerRef, getScrollTop, scrollTo } = setup({
117
+ top: 200,
118
+ bottom: 240,
119
+ left: 100,
120
+ right: 400,
121
+ })
122
+
123
+ renderHook(() =>
124
+ useKeepActiveItemInView({
125
+ containerRef,
126
+ activeItemId: 'documents',
127
+ axis: 'vertical',
128
+ }),
129
+ )
130
+
131
+ expect(getScrollTop()).toBe(0)
132
+ expect(scrollTo).not.toHaveBeenCalled()
133
+ })
134
+
135
+ it('scrolls the horizontal axis by scrollLeft', () => {
136
+ const { containerRef, getScrollLeft } = setup({
137
+ top: 100,
138
+ bottom: 140,
139
+ left: 380,
140
+ right: 460,
141
+ })
142
+
143
+ renderHook(() =>
144
+ useKeepActiveItemInView({
145
+ containerRef,
146
+ activeItemId: 'documents',
147
+ axis: 'horizontal',
148
+ }),
149
+ )
150
+
151
+ expect(getScrollLeft()).toBe(60)
152
+ })
153
+
154
+ it('animates when asked to and the user has no reduced-motion preference', () => {
155
+ const { containerRef, scrollTo } = setup({
156
+ top: 380,
157
+ bottom: 425,
158
+ left: 100,
159
+ right: 400,
160
+ })
161
+
162
+ renderHook(() =>
163
+ useKeepActiveItemInView({
164
+ containerRef,
165
+ activeItemId: 'documents',
166
+ axis: 'vertical',
167
+ behavior: 'smooth',
168
+ }),
169
+ )
170
+
171
+ expect(scrollTo).toHaveBeenCalledWith({ top: 25, behavior: 'smooth' })
172
+ })
173
+
174
+ it('jumps instead of animating under prefers-reduced-motion', () => {
175
+ prefersReducedMotion(true)
176
+ const { containerRef, scrollTo, getScrollTop } = setup({
177
+ top: 380,
178
+ bottom: 425,
179
+ left: 100,
180
+ right: 400,
181
+ })
182
+
183
+ renderHook(() =>
184
+ useKeepActiveItemInView({
185
+ containerRef,
186
+ activeItemId: 'documents',
187
+ axis: 'vertical',
188
+ behavior: 'smooth',
189
+ }),
190
+ )
191
+
192
+ expect(scrollTo).not.toHaveBeenCalled()
193
+ expect(getScrollTop()).toBe(25)
194
+ })
195
+
196
+ it('does nothing while disabled', () => {
197
+ const { containerRef, getScrollTop } = setup({
198
+ top: 380,
199
+ bottom: 425,
200
+ left: 100,
201
+ right: 400,
202
+ })
203
+
204
+ renderHook(() =>
205
+ useKeepActiveItemInView({
206
+ containerRef,
207
+ activeItemId: 'documents',
208
+ axis: 'vertical',
209
+ enabled: false,
210
+ }),
211
+ )
212
+
213
+ expect(getScrollTop()).toBe(0)
214
+ })
215
+
216
+ it('does not throw when no item matches the active id', () => {
217
+ const { containerRef, getScrollTop } = setup({
218
+ top: 380,
219
+ bottom: 425,
220
+ left: 100,
221
+ right: 400,
222
+ })
223
+
224
+ expect(() =>
225
+ renderHook(() =>
226
+ useKeepActiveItemInView({
227
+ containerRef,
228
+ activeItemId: 'missing',
229
+ axis: 'vertical',
230
+ }),
231
+ ),
232
+ ).not.toThrow()
233
+ expect(getScrollTop()).toBe(0)
234
+ })
235
+
236
+ // An id is an arbitrary string, not a CSS identifier, so quotes and
237
+ // backslashes have to survive the lookup.
238
+ it.each(['te"ma 1', 'tema\\1', 'trailing\\'])(
239
+ 'still finds the item for the awkward id %j',
240
+ (itemId) => {
241
+ const { containerRef, getScrollTop } = setup(
242
+ { top: 380, bottom: 425, left: 100, right: 400 },
243
+ itemId,
244
+ )
245
+
246
+ expect(() =>
247
+ renderHook(() =>
248
+ useKeepActiveItemInView({
249
+ containerRef,
250
+ activeItemId: itemId,
251
+ axis: 'vertical',
252
+ }),
253
+ ),
254
+ ).not.toThrow()
255
+ expect(getScrollTop()).toBe(25)
256
+ },
257
+ )
258
+ })
@@ -0,0 +1,80 @@
1
+ import { RefObject, useEffect } from 'react'
2
+
3
+ interface UseKeepActiveItemInViewOptions {
4
+ // The element with `overflow: auto`. Its items are matched by `data-item-id`.
5
+ containerRef: RefObject<HTMLElement>
6
+ activeItemId?: string
7
+ axis: 'horizontal' | 'vertical'
8
+ // Off while the container cannot scroll at all, so no work is done for the
9
+ // variant that hugs its content.
10
+ enabled?: boolean
11
+ // 'smooth' is downgraded to 'auto' under prefers-reduced-motion.
12
+ behavior?: ScrollBehavior
13
+ }
14
+
15
+ /**
16
+ * Scrolls the container the minimum amount needed to bring the active item into
17
+ * view - the nav's own equivalent of `scrollIntoView({ block: 'nearest' })`.
18
+ *
19
+ * Deliberately not `scrollIntoView`: that also scrolls every scrollable
20
+ * ancestor, so bringing a nav item into view would drag the page along with it
21
+ * and fight the scroll-spy that picked the item in the first place.
22
+ */
23
+ function useKeepActiveItemInView({
24
+ containerRef,
25
+ activeItemId,
26
+ axis,
27
+ enabled = true,
28
+ behavior = 'auto',
29
+ }: UseKeepActiveItemInViewOptions) {
30
+ useEffect(() => {
31
+ if (!enabled || !activeItemId) return
32
+
33
+ const container = containerRef.current
34
+ // Compared as an attribute value rather than interpolated into a selector:
35
+ // ids are arbitrary strings, and quotes or backslashes break a selector.
36
+ const target = Array.from(
37
+ container?.querySelectorAll<HTMLElement>('[data-item-id]') ?? [],
38
+ ).find((element) => element.dataset.itemId === activeItemId)
39
+ if (!container || !target) return
40
+
41
+ // Viewport rects on both, so they agree: offsetTop/offsetLeft would be
42
+ // relative to the nearest positioned ancestor, not the scroll container.
43
+ const containerRect = container.getBoundingClientRect()
44
+ const targetRect = target.getBoundingClientRect()
45
+ const isVertical = axis === 'vertical'
46
+ const overflowStart = isVertical
47
+ ? containerRect.top - targetRect.top
48
+ : containerRect.left - targetRect.left
49
+ const overflowEnd = isVertical
50
+ ? targetRect.bottom - containerRect.bottom
51
+ : targetRect.right - containerRect.right
52
+
53
+ let delta = 0
54
+ if (overflowStart > 0) delta = -overflowStart
55
+ else if (overflowEnd > 0) delta = overflowEnd
56
+ if (delta === 0) return
57
+
58
+ const property = isVertical ? 'scrollTop' : 'scrollLeft'
59
+ const position = container[property] + delta
60
+ const prefersReducedMotion = window.matchMedia?.(
61
+ '(prefers-reduced-motion: reduce)',
62
+ ).matches
63
+
64
+ // The direct assignment is both what an instant scroll wants and the only
65
+ // path available in layout-less environments, where Element.scrollTo is absent.
66
+ if (
67
+ behavior === 'smooth' &&
68
+ !prefersReducedMotion &&
69
+ typeof container.scrollTo === 'function'
70
+ ) {
71
+ container.scrollTo({ [isVertical ? 'top' : 'left']: position, behavior: 'smooth' })
72
+ } else {
73
+ container[property] = position
74
+ }
75
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- containerRef is a ref, its identity is stable
76
+ }, [activeItemId, axis, behavior, enabled])
77
+ }
78
+
79
+ export default useKeepActiveItemInView
80
+ export type { UseKeepActiveItemInViewOptions }
@@ -3,8 +3,15 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
3
3
 
4
4
  import useSideNavScrollSpy from './useSideNavScrollSpy'
5
5
 
6
- type Viewport = { scrollY: number; innerHeight: number; scrollHeight: number }
7
- type SectionTop = { id: string; top: number }
6
+ interface Viewport {
7
+ scrollY: number
8
+ innerHeight: number
9
+ scrollHeight: number
10
+ }
11
+ interface SectionTop {
12
+ id: string
13
+ top: number
14
+ }
8
15
 
9
16
  const setViewport = ({ scrollY, innerHeight, scrollHeight }: Viewport) => {
10
17
  Object.defineProperty(window, 'scrollY', { value: scrollY, configurable: true })
@@ -6,7 +6,7 @@ const ACTIVATION_LINE_EPSILON = 1
6
6
  // long document).
7
7
  const PROGRAMMATIC_SCROLL_SETTLE_MS = 600
8
8
 
9
- type UseSideNavScrollSpyOptions = {
9
+ interface UseSideNavScrollSpyOptions {
10
10
  itemIds: string[]
11
11
  offset?: number
12
12
  // Bounds id resolution to this subtree so an id collision elsewhere on the page
@@ -16,8 +16,9 @@ type UseSideNavScrollSpyOptions = {
16
16
 
17
17
  function findScopedElement(root: Document | HTMLElement, id: string): HTMLElement | null {
18
18
  if (root instanceof Document) return root.getElementById(id)
19
- // Attribute selector, so an id that is not a valid CSS selector cannot throw.
20
- return root.querySelector<HTMLElement>(`[id="${id.replace(/"/g, '\\"')}"]`)
19
+ // Attribute selector, so an id that is not a valid CSS identifier still
20
+ // resolves. Escapes both characters a CSS string cannot hold raw.
21
+ return root.querySelector<HTMLElement>(`[id="${id.replace(/["\\]/g, '\\$&')}"]`)
21
22
  }
22
23
 
23
24
  function useSideNavScrollSpy({ itemIds, offset = 0, scope }: UseSideNavScrollSpyOptions) {
@@ -25,6 +25,12 @@ const items: RcSesSideNavItem[] = [
25
25
  const renderSideNav = (ui: ReactElement) =>
26
26
  render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
27
27
 
28
+ // The desktop column and its scrolling row list carry no role of their own; the
29
+ // nav landmark is the only stable handle into that part of the tree.
30
+ const getDesktopColumn = () =>
31
+ screen.getByRole('navigation').firstElementChild as HTMLElement
32
+ const getRowList = () => getDesktopColumn().lastElementChild as HTMLElement
33
+
28
34
  describe('RcSesSideNav', () => {
29
35
  beforeEach(async () => {
30
36
  await i18n.changeLanguage('lt')
@@ -90,6 +96,51 @@ describe('RcSesSideNav', () => {
90
96
  expect(screen.queryAllByRole('button')).toHaveLength(0)
91
97
  })
92
98
 
99
+ it('lets the desktop list grow as tall as it needs by default', () => {
100
+ renderSideNav(<RcSesSideNav items={items} />)
101
+
102
+ expect(getRowList()).not.toHaveStyle({ overflowY: 'auto' })
103
+ expect(window.getComputedStyle(getDesktopColumn()).maxHeight).not.toContain('100vh')
104
+ })
105
+
106
+ it("caps the desktop list to the viewport and scrolls it inside itself with overflow='scroll'", () => {
107
+ renderSideNav(<RcSesSideNav items={items} overflow='scroll' offset={96} />)
108
+
109
+ expect(window.getComputedStyle(getDesktopColumn()).maxHeight).toBe(
110
+ 'calc(100vh - 96px)',
111
+ )
112
+ expect(getRowList()).toHaveStyle({ overflowY: 'auto' })
113
+ })
114
+
115
+ it('scrolls an active item that sits past the bottom of the list into view', () => {
116
+ const { rerender } = renderSideNav(
117
+ <RcSesSideNav items={items} overflow='scroll' offset={96} />,
118
+ )
119
+
120
+ const list = getRowList()
121
+ const scrollTo = vi.fn()
122
+ list.scrollTo = scrollTo
123
+ // jsdom has no layout: the list ends at 300, the row runs on to 360.
124
+ list.getBoundingClientRect = () =>
125
+ ({ top: 100, bottom: 300, left: 0, right: 200 }) as DOMRect
126
+ const row = list.querySelector<HTMLElement>('[data-item-id="signature"]')!
127
+ row.getBoundingClientRect = () =>
128
+ ({ top: 320, bottom: 360, left: 0, right: 200 }) as DOMRect
129
+
130
+ rerender(
131
+ <ThemeProvider theme={theme}>
132
+ <RcSesSideNav
133
+ items={items}
134
+ overflow='scroll'
135
+ offset={96}
136
+ activeItemId='signature'
137
+ />
138
+ </ThemeProvider>,
139
+ )
140
+
141
+ expect(scrollTo).toHaveBeenCalledWith({ top: 60, behavior: 'smooth' })
142
+ })
143
+
93
144
  it('renders in English when the language is changed', async () => {
94
145
  await i18n.changeLanguage('en')
95
146
  renderSideNav(<RcSesSideNav items={items} />)
@@ -1,4 +1,5 @@
1
1
  import { Box, Typography } from '@mui/material'
2
+ import { useRef } from 'react'
2
3
  import { useTranslation } from 'react-i18next'
3
4
 
4
5
  import normalizeSx from '@/components/utils/normalizeSx'
@@ -7,16 +8,31 @@ import palette, { common } from '@/theme/palette'
7
8
  import { RcSesSideNavItem, RcSesSideNavProps } from './SideNav.types'
8
9
  import SideNavPillList from './components/SideNavPillList'
9
10
  import SideNavRow from './components/SideNavRow'
11
+ import useKeepActiveItemInView from './hooks/useKeepActiveItemInView'
12
+
13
+ const ROW_GAP = '0.25rem'
10
14
 
11
15
  function RcSesSideNav({
12
16
  items,
13
17
  activeItemId,
14
18
  onItemClick,
15
19
  title,
20
+ overflow = 'fit',
21
+ offset = 0,
16
22
  sx,
17
23
  }: RcSesSideNavProps) {
18
24
  const { t } = useTranslation('common', { keyPrefix: 'components.RcSesSideNav' })
19
25
  const navTitle = title ?? t('title')
26
+ const rowListRef = useRef<HTMLDivElement>(null)
27
+
28
+ const isScrollable = overflow === 'scroll'
29
+ useKeepActiveItemInView({
30
+ containerRef: rowListRef,
31
+ activeItemId,
32
+ axis: 'vertical',
33
+ enabled: isScrollable,
34
+ behavior: 'smooth',
35
+ })
20
36
 
21
37
  const getItemAriaLabel = (item: RcSesSideNavItem) =>
22
38
  item.count !== undefined
@@ -42,7 +58,11 @@ function RcSesSideNav({
42
58
  sx={{
43
59
  display: { xs: 'none', md: 'flex' },
44
60
  flexDirection: 'column',
45
- gap: '0.25rem',
61
+ gap: ROW_GAP,
62
+ // Capped to what is left of the viewport below the sticky header, so
63
+ // the list can never run past the bottom of the screen. The title stays
64
+ // put and only the rows scroll, hence minHeight: 0 on this flex column.
65
+ ...(isScrollable && { maxHeight: `calc(100vh - ${offset}px)`, minHeight: 0 }),
46
66
  }}
47
67
  >
48
68
  <Typography
@@ -55,16 +75,27 @@ function RcSesSideNav({
55
75
  >
56
76
  {navTitle}
57
77
  </Typography>
58
- {items.map((item) => (
59
- <SideNavRow
60
- key={item.id}
61
- label={item.label}
62
- count={item.count}
63
- ariaLabel={getItemAriaLabel(item)}
64
- active={item.id === activeItemId}
65
- onClick={onItemClick ? () => onItemClick(item.id) : undefined}
66
- />
67
- ))}
78
+ <Box
79
+ ref={rowListRef}
80
+ sx={{
81
+ display: 'flex',
82
+ flexDirection: 'column',
83
+ gap: ROW_GAP,
84
+ ...(isScrollable && { overflowY: 'auto', minHeight: 0 }),
85
+ }}
86
+ >
87
+ {items.map((item) => (
88
+ <SideNavRow
89
+ key={item.id}
90
+ itemId={item.id}
91
+ label={item.label}
92
+ count={item.count}
93
+ ariaLabel={getItemAriaLabel(item)}
94
+ active={item.id === activeItemId}
95
+ onClick={onItemClick ? () => onItemClick(item.id) : undefined}
96
+ />
97
+ ))}
98
+ </Box>
68
99
  </Box>
69
100
 
70
101
  <Box sx={{ display: { xs: 'block', md: 'none' } }}>
@@ -80,4 +111,8 @@ function RcSesSideNav({
80
111
  }
81
112
 
82
113
  export default RcSesSideNav
83
- export type { RcSesSideNavItem, RcSesSideNavProps } from './SideNav.types'
114
+ export type {
115
+ RcSesSideNavItem,
116
+ RcSesSideNavOverflow,
117
+ RcSesSideNavProps,
118
+ } from './SideNav.types'
@@ -115,6 +115,46 @@ describe('RcSesSnackbar', () => {
115
115
  expect(screen.queryByRole('button', { name: 'Undo' })).not.toBeInTheDocument()
116
116
  })
117
117
 
118
+ test('follows the open prop when the parent toggles it', () => {
119
+ const { rerender } = renderSnackbar(<RcSesSnackbar {...DEFAULT_PROPS} open />)
120
+ expect(screen.getByText('Test')).toBeInTheDocument()
121
+
122
+ rerender(
123
+ <ThemeProvider theme={theme}>
124
+ <RcSesSnackbar {...DEFAULT_PROPS} open={false} />
125
+ </ThemeProvider>,
126
+ )
127
+ act(() => {
128
+ vi.runOnlyPendingTimers()
129
+ })
130
+ expect(screen.queryByText('Test')).not.toBeInTheDocument()
131
+
132
+ rerender(
133
+ <ThemeProvider theme={theme}>
134
+ <RcSesSnackbar {...DEFAULT_PROPS} open />
135
+ </ThemeProvider>,
136
+ )
137
+ expect(screen.getByText('Test')).toBeInTheDocument()
138
+ })
139
+
140
+ test('still closes from the inside while the parent holds open at true', () => {
141
+ const { rerender } = renderSnackbar(<RcSesSnackbar {...DEFAULT_PROPS} open />)
142
+ fireEvent.keyDown(getMuiSnackbar(), { key: 'Escape', code: 'Escape' })
143
+ act(() => {
144
+ vi.runOnlyPendingTimers()
145
+ })
146
+ expect(screen.queryByText('Test')).not.toBeInTheDocument()
147
+
148
+ // A re-render with `open` unchanged must not resurrect it - only an actual
149
+ // false -> true transition of the prop may reopen the snackbar.
150
+ rerender(
151
+ <ThemeProvider theme={theme}>
152
+ <RcSesSnackbar {...DEFAULT_PROPS} open />
153
+ </ThemeProvider>,
154
+ )
155
+ expect(screen.queryByText('Test')).not.toBeInTheDocument()
156
+ })
157
+
118
158
  test('has correct accessibility attributes', () => {
119
159
  renderSnackbar(<RcSesSnackbar {...DEFAULT_PROPS} />)
120
160
  const status = screen.getByRole('status')