@registrucentras/rc-ses-react-components 2.0.0-rc.7 → 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 (199) 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 +1631 -1589
  44. package/dist/types/assets/IconProps.d.ts +2 -2
  45. package/dist/types/cards/CardServiceProps.d.ts +2 -2
  46. package/dist/types/common/QuickLinkType.d.ts +2 -2
  47. package/dist/types/inputs/InputIconProps.d.ts +2 -2
  48. package/dist/types/lists/ListNewsItemType.d.ts +2 -2
  49. package/dist/types/lists/ListServicesItemType.d.ts +3 -3
  50. package/package.json +2 -1
  51. package/src/components/common/Accordion/hooks/useAccordionController.tsx +1 -1
  52. package/src/components/common/Accordion/index.tsx +1 -4
  53. package/src/components/common/Accordion/types/AccordionControllerState.ts +1 -1
  54. package/src/components/common/AdvancedList/components/AdvancedListItem/AdvancedListItem.types.ts +1 -1
  55. package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemLeading.tsx +1 -1
  56. package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemTrailing.tsx +1 -1
  57. package/src/components/common/AdvancedList/components/AdvancedListItem/index.test.tsx +2 -2
  58. package/src/components/common/Badge/index.tsx +3 -3
  59. package/src/components/common/Breadcrumbs/index.tsx +5 -2
  60. package/src/components/common/Card/index.tsx +1 -1
  61. package/src/components/common/CardShell/CardFooter/index.tsx +6 -13
  62. package/src/components/common/CardShell/CardFooter/types.ts +2 -7
  63. package/src/components/common/CardShell/types.ts +2 -2
  64. package/src/components/common/IconWithCircularBackground.tsx +7 -8
  65. package/src/components/common/IconWithSquareBackground/index.tsx +7 -8
  66. package/src/components/common/ImageCard/index.tsx +1 -1
  67. package/src/components/common/SegmentedControl/components/SegmentButton/index.tsx +18 -19
  68. package/src/components/common/SelectableCardList/components/SelectableCardListItem.tsx +1 -1
  69. package/src/components/common/SelectableCardList/index.tsx +1 -1
  70. package/src/components/common/ServiceLinks/types.ts +3 -3
  71. package/src/components/common/SideNav/SideNav.types.ts +11 -3
  72. package/src/components/common/SideNav/SideNavLayout.tsx +3 -0
  73. package/src/components/common/SideNav/components/SideNavPill.tsx +1 -1
  74. package/src/components/common/SideNav/components/SideNavPillList.tsx +8 -23
  75. package/src/components/common/SideNav/components/SideNavRow.tsx +6 -2
  76. package/src/components/common/SideNav/hooks/useKeepActiveItemInView.test.ts +258 -0
  77. package/src/components/common/SideNav/hooks/useKeepActiveItemInView.ts +80 -0
  78. package/src/components/common/SideNav/hooks/useSideNavScrollSpy.test.ts +9 -2
  79. package/src/components/common/SideNav/hooks/useSideNavScrollSpy.ts +4 -3
  80. package/src/components/common/SideNav/index.test.tsx +51 -0
  81. package/src/components/common/SideNav/index.tsx +47 -12
  82. package/src/components/common/Snackbar/index.test.tsx +40 -0
  83. package/src/components/common/Snackbar/index.tsx +9 -3
  84. package/src/components/common/Tabs/TabPanel.tsx +1 -1
  85. package/src/components/common/Tabs/TabsWrapper.tsx +1 -1
  86. package/src/components/common/TitleBlock/index.test.tsx +9 -7
  87. package/src/components/common/TitleBlock/index.tsx +13 -9
  88. package/src/components/common/TitleBlock/types.ts +2 -2
  89. package/src/components/form/components/FormControlWrapper/components/FieldSuffix.tsx +1 -1
  90. package/src/components/form/components/FormControlWrapper/index.tsx +1 -1
  91. package/src/components/form/inputs/Datepicker/index.test.tsx +1 -1
  92. package/src/components/form/inputs/FileDropzone.tsx +1 -4
  93. package/src/components/form/inputs/NumberStepper.test.tsx +83 -0
  94. package/src/components/form/inputs/NumberStepper.tsx +7 -8
  95. package/src/components/form/inputs/RadioButtonGroup.test.tsx +1 -1
  96. package/src/components/form/inputs/RadioButtonGroup.tsx +2 -2
  97. package/src/components/form/inputs/SearchInput/index.tsx +1 -1
  98. package/src/components/form/inputs/SearchableField.test.tsx +2 -2
  99. package/src/components/form/inputs/SearchableField.tsx +1 -1
  100. package/src/components/form/inputs/Select/Select.types.ts +1 -1
  101. package/src/components/form/inputs/Select/index.test.tsx +3 -3
  102. package/src/components/layout/Footer/index.tsx +1 -1
  103. package/src/components/layout/ServiceFormActions.tsx +1 -1
  104. package/src/components/layout/ServiceFormContainer/AccordionFormContainer/components/AccordionCollapseControls.tsx +1 -1
  105. package/src/components/layout/ServiceFormContainer/AccordionFormContainer/index.tsx +1 -1
  106. package/src/components/layout/ServiceHeader.tsx +1 -1
  107. package/src/components/layout/ServicePage.tsx +1 -1
  108. package/src/components/utils/normalizeSx.ts +2 -4
  109. package/src/examples/ListWithPagination/index.tsx +0 -2
  110. package/src/examples/MultipleStepForm/components/AdditionalServicesForm.tsx +1 -1
  111. package/src/examples/MultipleStepForm/components/ServiceIssuanceForm.tsx +1 -1
  112. package/src/examples/MultipleStepForm/components/TermsAndConditionsForm.tsx +1 -1
  113. package/src/examples/MultipleStepForm/types/MultiStepFormModel.ts +1 -1
  114. package/src/examples/SingleStepForm/components/ObjectIdentifierSearchModal.tsx +2 -2
  115. package/src/examples/SingleStepForm/types/SingleStepFormModel.ts +1 -1
  116. package/src/library/types.ts +2 -1
  117. package/src/stories/atoms/Button.stories.tsx +9 -14
  118. package/src/stories/atoms/Checkbox.stories.tsx +1 -1
  119. package/src/stories/atoms/Icons.stories.tsx +1 -1
  120. package/src/stories/atoms/NumberStepper.stories.tsx +1 -1
  121. package/src/stories/atoms/PhoneInput.stories.tsx +1 -1
  122. package/src/stories/atoms/Select.stories.tsx +7 -9
  123. package/src/stories/atoms/Switch.stories.tsx +1 -1
  124. package/src/stories/molecules/Alert.stories.tsx +2 -2
  125. package/src/stories/molecules/CardShell.stories.tsx +4 -4
  126. package/src/stories/molecules/CheckboxFormControl.stories.tsx +13 -21
  127. package/src/stories/molecules/RadioButtonGroup.stories.tsx +1 -1
  128. package/src/stories/molecules/Snackbar.stories.tsx +2 -2
  129. package/src/stories/molecules/TitleBlock.stories.tsx +40 -1
  130. package/src/stories/organisms/AdvancedList.stories.tsx +4 -4
  131. package/src/stories/organisms/FileDropzone.stories.tsx +1 -1
  132. package/src/stories/organisms/FileUpload.stories.tsx +1 -1
  133. package/src/stories/organisms/SideNav.stories.tsx +36 -3
  134. package/src/stubs/Component.tsx +4 -4
  135. package/src/types/assets/IconProps.tsx +1 -1
  136. package/src/types/cards/CardServiceProps.tsx +1 -1
  137. package/src/types/common/QuickLinkType.tsx +1 -1
  138. package/src/types/inputs/InputIconProps.tsx +1 -1
  139. package/src/types/lists/ListNewsItemType.tsx +1 -1
  140. package/src/types/lists/ListServicesItemType.tsx +2 -2
  141. package/src/vite-env.d.ts +2 -2
  142. package/dist/stories/atoms/Badge.stories.d.ts +0 -9
  143. package/dist/stories/atoms/Button.stories.d.ts +0 -107
  144. package/dist/stories/atoms/Checkbox.stories.d.ts +0 -21
  145. package/dist/stories/atoms/IconWithCircularBackground.stories.d.ts +0 -6
  146. package/dist/stories/atoms/IconWithSquareBackground.stories.d.ts +0 -7
  147. package/dist/stories/atoms/Icons.stories.d.ts +0 -7
  148. package/dist/stories/atoms/Loader.stories.d.ts +0 -36
  149. package/dist/stories/atoms/LoadingSpinner.stories.d.ts +0 -62
  150. package/dist/stories/atoms/Logo.stories.d.ts +0 -12
  151. package/dist/stories/atoms/NumberStepper.stories.d.ts +0 -6
  152. package/dist/stories/atoms/PhoneInput.stories.d.ts +0 -10
  153. package/dist/stories/atoms/SearchInput.stories.d.ts +0 -11
  154. package/dist/stories/atoms/Select.stories.d.ts +0 -7
  155. package/dist/stories/atoms/SimpleCheckbox.stories.d.ts +0 -19
  156. package/dist/stories/atoms/Switch.stories.d.ts +0 -17
  157. package/dist/stories/atoms/Tab.stories.d.ts +0 -8
  158. package/dist/stories/atoms/TextField.stories.d.ts +0 -6
  159. package/dist/stories/atoms/Tooltip.stories.d.ts +0 -48
  160. package/dist/stories/foundations/ThemedMuiComponents.stories.d.ts +0 -25
  161. package/dist/stories/molecules/Alert.stories.d.ts +0 -14
  162. package/dist/stories/molecules/Breadcrumbs.stories.d.ts +0 -6
  163. package/dist/stories/molecules/ButtonWithPopover.stories.d.ts +0 -7
  164. package/dist/stories/molecules/Card.stories.d.ts +0 -8
  165. package/dist/stories/molecules/CardShell.stories.d.ts +0 -18
  166. package/dist/stories/molecules/CheckboxFormControl.stories.d.ts +0 -9
  167. package/dist/stories/molecules/DatePicker.stories.d.ts +0 -152
  168. package/dist/stories/molecules/FormControlWrapper.stories.d.ts +0 -7
  169. package/dist/stories/molecules/ImageCard.stories.d.ts +0 -8
  170. package/dist/stories/molecules/ListWithIcons.stories.d.ts +0 -34
  171. package/dist/stories/molecules/PhoneInputFormControl.stories.d.ts +0 -6
  172. package/dist/stories/molecules/Popover.stories.d.ts +0 -12
  173. package/dist/stories/molecules/RadioButtonGroup.stories.d.ts +0 -6
  174. package/dist/stories/molecules/SearchableField.stories.d.ts +0 -6
  175. package/dist/stories/molecules/SegmentedControl.stories.d.ts +0 -202
  176. package/dist/stories/molecules/Snackbar.stories.d.ts +0 -143
  177. package/dist/stories/molecules/TabPanel.stories.d.ts +0 -7
  178. package/dist/stories/molecules/Tabs.stories.d.ts +0 -7
  179. package/dist/stories/molecules/TabsWrapper.stories.d.ts +0 -6
  180. package/dist/stories/molecules/TitleBlock.stories.d.ts +0 -22
  181. package/dist/stories/organisms/Accordion.stories.d.ts +0 -18
  182. package/dist/stories/organisms/AdvancedList.stories.d.ts +0 -33
  183. package/dist/stories/organisms/AdvancedListItem.stories.d.ts +0 -33
  184. package/dist/stories/organisms/CardFormContainer.stories.d.ts +0 -7
  185. package/dist/stories/organisms/DataPagination.stories.d.ts +0 -47
  186. package/dist/stories/organisms/Dialog.stories.d.ts +0 -15
  187. package/dist/stories/organisms/FileDropzone.stories.d.ts +0 -6
  188. package/dist/stories/organisms/FileUpload.stories.d.ts +0 -18
  189. package/dist/stories/organisms/Footer.stories.d.ts +0 -6
  190. package/dist/stories/organisms/FullPageLoader.stories.d.ts +0 -37
  191. package/dist/stories/organisms/Modal.stories.d.ts +0 -10
  192. package/dist/stories/organisms/SelectableCardList.stories.d.ts +0 -37
  193. package/dist/stories/organisms/ServiceFormActions.stories.d.ts +0 -6
  194. package/dist/stories/organisms/ServiceFormContainer.stories.d.ts +0 -15
  195. package/dist/stories/organisms/ServiceHeader.stories.d.ts +0 -7
  196. package/dist/stories/organisms/ServiceLinks.stories.d.ts +0 -28
  197. package/dist/stories/organisms/ServiceWizardStepper.stories.d.ts +0 -7
  198. package/dist/stories/organisms/SideNav.stories.d.ts +0 -7
  199. package/dist/stories/templates/ServicePage.stories.d.ts +0 -6
@@ -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')
@@ -6,7 +6,7 @@ import {
6
6
  useMediaQuery,
7
7
  useTheme,
8
8
  } from '@mui/material'
9
- import { useEffect, useLayoutEffect, useRef, useState } from 'react'
9
+ import { useLayoutEffect, useRef, useState } from 'react'
10
10
  import { useTranslation } from 'react-i18next'
11
11
 
12
12
  import CloseIcon from '@/assets/icons/CloseIcon'
@@ -53,13 +53,19 @@ function RcSesSnackbar({
53
53
  const { t } = useTranslation('input')
54
54
  const [internalOpen, setInternalOpen] = useState(controlledOpen ?? true)
55
55
  const [isPaused, setIsPaused] = useState(false)
56
+ const [prevControlledOpen, setPrevControlledOpen] = useState(controlledOpen)
56
57
  const persist = controlledPersist ?? state === 'action-needed'
57
58
 
58
- useEffect(() => {
59
+ // The `open` prop drives the internal state, but closing from the inside
60
+ // (Escape, autohide, close button) has to keep working while the parent holds
61
+ // `open` at true. Adjusting the state during render instead of in an effect
62
+ // preserves both without the extra render pass an effect would cause.
63
+ if (controlledOpen !== prevControlledOpen) {
64
+ setPrevControlledOpen(controlledOpen)
59
65
  if (controlledOpen !== undefined) {
60
66
  setInternalOpen(controlledOpen)
61
67
  }
62
- }, [controlledOpen])
68
+ }
63
69
 
64
70
  const config = stateConfig[state]
65
71
  const StateIcon = config.icon
@@ -1,7 +1,7 @@
1
1
  import { Box } from '@mui/material'
2
2
  import React from 'react'
3
3
 
4
- type Props = {
4
+ interface Props {
5
5
  activeTab: number
6
6
  children?: React.ReactNode
7
7
  index: number
@@ -3,7 +3,7 @@ import React from 'react'
3
3
 
4
4
  import palette from '@/theme/palette'
5
5
 
6
- type Props = {
6
+ interface Props {
7
7
  children?: React.ReactNode
8
8
  heading?: React.ReactNode
9
9
  }
@@ -241,10 +241,9 @@ describe('RcSesTitleBlock', () => {
241
241
  )
242
242
  })
243
243
 
244
- test('actions slot stacks vertically on mobile (xs)', () => {
245
- // MUI's responsive `direction={{ xs: 'column', sm: 'row' }}` emits
246
- // `flex-direction: column` as the base (xs) rule; the sm breakpoint
247
- // override lives behind a media query and does not affect the base style.
244
+ test('actions slot renders as a wrapping row', () => {
245
+ // jsdom does not evaluate media queries or measure widths, so this only
246
+ // asserts the base flex styles — not the actual mobile wrap behaviour.
248
247
  renderTitleBlock(
249
248
  <RcSesTitleBlock
250
249
  actions={
@@ -258,10 +257,13 @@ describe('RcSesTitleBlock', () => {
258
257
  />,
259
258
  )
260
259
 
261
- expect(screen.getByTestId('actions')).toHaveStyle({ flexDirection: 'column' })
260
+ expect(screen.getByTestId('actions')).toHaveStyle({
261
+ flexDirection: 'row',
262
+ flexWrap: 'wrap',
263
+ })
262
264
  })
263
265
 
264
- test('actions slot stacks vertically on mobile even with a single action', () => {
266
+ test('actions slot renders as a row with a single action', () => {
265
267
  renderTitleBlock(
266
268
  <RcSesTitleBlock
267
269
  actions={<button type='button'>Užsakyti</button>}
@@ -270,7 +272,7 @@ describe('RcSesTitleBlock', () => {
270
272
  />,
271
273
  )
272
274
 
273
- expect(screen.getByTestId('actions')).toHaveStyle({ flexDirection: 'column' })
275
+ expect(screen.getByTestId('actions')).toHaveStyle({ flexDirection: 'row' })
274
276
  })
275
277
 
276
278
  test('omits the icon and actions slots when not provided', () => {