|
1 | 1 | import { render } from '@testing-library/react'
|
2 |
| -import React, { createElement, Fragment, useCallback, useEffect, useRef, useState } from 'react' |
| 2 | +import React, { Fragment, createElement, useCallback, useEffect, useRef, useState } from 'react' |
3 | 3 | import { createPortal } from 'react-dom'
|
4 |
| -import { OpenClosedProvider, State } from '../../internal/open-closed' |
5 | 4 | import {
|
| 5 | + DialogState, |
| 6 | + PopoverState, |
6 | 7 | assertActiveElement,
|
7 | 8 | assertDialog,
|
8 | 9 | assertDialogDescription,
|
9 | 10 | assertDialogTitle,
|
10 | 11 | assertPopoverPanel,
|
11 |
| - DialogState, |
12 | 12 | getByText,
|
13 | 13 | getDialog,
|
14 | 14 | getDialogs,
|
15 | 15 | getPopoverButton,
|
16 |
| - PopoverState, |
17 | 16 | } from '../../test-utils/accessibility-assertions'
|
18 |
| -import { click, focus, Keys, mouseDrag, press, shift } from '../../test-utils/interactions' |
| 17 | +import { Keys, click, focus, mouseDrag, press, shift } from '../../test-utils/interactions' |
19 | 18 | import { suppressConsoleLogs } from '../../test-utils/suppress-console-logs'
|
20 | 19 | import type { PropsOf } from '../../types'
|
21 | 20 | import { Popover } from '../popover/popover'
|
@@ -498,25 +497,51 @@ describe('Rendering', () => {
|
498 | 497 | it(
|
499 | 498 | 'should remove the scroll lock when the open closed state is `Closing`',
|
500 | 499 | suppressConsoleLogs(async () => {
|
501 |
| - function Example({ value = State.Open }) { |
| 500 | + function Example({ open = true }) { |
| 501 | + return ( |
| 502 | + <Dialog transition autoFocus={false} open={open} onClose={() => {}}> |
| 503 | + <input id="a" type="text" /> |
| 504 | + <input id="b" type="text" /> |
| 505 | + <input id="c" type="text" /> |
| 506 | + </Dialog> |
| 507 | + ) |
| 508 | + } |
| 509 | + |
| 510 | + let { rerender } = render(<Example open={true} />) |
| 511 | + |
| 512 | + // The overflow should be there |
| 513 | + expect(document.documentElement.style.overflow).toBe('hidden') |
| 514 | + |
| 515 | + // Re-render but with an exit transition |
| 516 | + rerender(<Example open={false} />) |
| 517 | + |
| 518 | + // The moment the dialog is closing, the overflow should be gone |
| 519 | + expect(document.documentElement.style.overflow).toBe('') |
| 520 | + }) |
| 521 | + ) |
| 522 | + |
| 523 | + it( |
| 524 | + 'should remove the scroll lock when the open closed state is `Closing` (using Transition wrapper)', |
| 525 | + suppressConsoleLogs(async () => { |
| 526 | + function Example({ open = true }) { |
502 | 527 | return (
|
503 |
| - <OpenClosedProvider value={value}> |
504 |
| - <Dialog autoFocus={false} open={true} onClose={() => {}}> |
| 528 | + <Transition show={open}> |
| 529 | + <Dialog autoFocus={false} onClose={() => {}}> |
505 | 530 | <input id="a" type="text" />
|
506 | 531 | <input id="b" type="text" />
|
507 | 532 | <input id="c" type="text" />
|
508 | 533 | </Dialog>
|
509 |
| - </OpenClosedProvider> |
| 534 | + </Transition> |
510 | 535 | )
|
511 | 536 | }
|
512 | 537 |
|
513 |
| - let { rerender } = render(<Example value={State.Open} />) |
| 538 | + let { rerender } = render(<Example open={true} />) |
514 | 539 |
|
515 | 540 | // The overflow should be there
|
516 | 541 | expect(document.documentElement.style.overflow).toBe('hidden')
|
517 | 542 |
|
518 |
| - // Re-render but with the `Closing` state |
519 |
| - rerender(<Example value={State.Open | State.Closing} />) |
| 543 | + // Re-render but with an exit transition |
| 544 | + rerender(<Example open={false} />) |
520 | 545 |
|
521 | 546 | // The moment the dialog is closing, the overflow should be gone
|
522 | 547 | expect(document.documentElement.style.overflow).toBe('')
|
|
0 commit comments