agroptima-design-system 1.2.38 → 1.2.39-beta.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agroptima-design-system",
3
- "version": "1.2.38",
3
+ "version": "1.2.39-beta.1",
4
4
  "scripts": {
5
5
  "dev": "npm run storybook",
6
6
  "storybook": "storybook dev -p 6006 --ci",
@@ -29,14 +29,14 @@ export function ModalDialog({
29
29
  }
30
30
 
31
31
  useEffect(() => {
32
+ if (!isOpen) return
33
+
32
34
  keepScrollbarSpace()
33
- window.addEventListener('resize', keepScrollbarSpace)
34
35
 
35
36
  return () => {
36
37
  removeScrollbarSpace()
37
- window.removeEventListener('resize', keepScrollbarSpace)
38
38
  }
39
- }, [])
39
+ }, [isOpen])
40
40
 
41
41
  useEffect(() => {
42
42
  const dialog = dialogRef.current
@@ -4,6 +4,11 @@ import { Meta } from "@storybook/addon-docs/blocks";
4
4
 
5
5
  # Changelog
6
6
 
7
+ ## 1.2.39
8
+
9
+ * Fix Modal scroll lock not being cleared when the component stays mounted and `isOpen` toggles to `false`
10
+ * Fix Modal scroll lock width flickering on window resize while open, caused by recalculating the scrollbar width after `overflow: hidden` had already removed it
11
+
7
12
  ## 1.2.38
8
13
 
9
14
  * Add CheckboxWithDivider component
@@ -37,7 +37,7 @@ const meta = {
37
37
  ' <li>Require a response from the user</li>' +
38
38
  ' <li>Notify the user of any related information</li>' +
39
39
  ' <li>Confirm a user decision</li>' +
40
- " <li>It's opened/closed through `isOpen` prop. If we don't want it to be part of the DOM, we can also add a conditional render on the frontend project.</li>" +
40
+ " <li>It's opened/closed through `isOpen` prop — the component can be left mounted and toggled. If we don't want it to be part of the DOM at all (e.g. to avoid rendering its contents until needed), we can also add a conditional render on the frontend project.</li>" +
41
41
  ' <li>Natively, focus is set on the first nested focusable element and explicitly indicated by default by the browser</li>' +
42
42
  " <li>When nesting a Form inside Modal component, remember to add `type='button'` to all Cancel buttons to not to be considered as submitable</li>" +
43
43
  '</ul>',
@@ -145,4 +145,50 @@ describe('Modal', () => {
145
145
  expect(screen.queryAllByRole('option')).toHaveLength(3)
146
146
  expect(screen.getByRole('option', { name: 'Item 3' })).toBeInTheDocument()
147
147
  })
148
+
149
+ it('clears the scroll lock when isOpen toggles to false while the modal stays mounted', async () => {
150
+ const originalInnerWidth = window.innerWidth
151
+ Object.defineProperty(window, 'innerWidth', {
152
+ configurable: true,
153
+ value: 1024,
154
+ })
155
+ Object.defineProperty(document.documentElement, 'clientWidth', {
156
+ configurable: true,
157
+ value: 1000,
158
+ })
159
+
160
+ const user = userEvent.setup()
161
+ const ToggleableModal = () => {
162
+ const [isOpen, setIsOpen] = React.useState(true)
163
+
164
+ return (
165
+ <Modal
166
+ id="scroll-lock-modal"
167
+ isOpen={isOpen}
168
+ title="Scroll lock modal"
169
+ buttons={[
170
+ {
171
+ label: 'Close',
172
+ onClick: () => setIsOpen(false),
173
+ },
174
+ ]}
175
+ >
176
+ content
177
+ </Modal>
178
+ )
179
+ }
180
+
181
+ render(<ToggleableModal />)
182
+
183
+ expect(document.documentElement).toHaveClass('modal-scroll')
184
+
185
+ await user.click(screen.getByRole('button', { name: 'Close' }))
186
+
187
+ expect(document.documentElement).not.toHaveClass('modal-scroll')
188
+
189
+ Object.defineProperty(window, 'innerWidth', {
190
+ configurable: true,
191
+ value: originalInnerWidth,
192
+ })
193
+ })
148
194
  })