-
-
Notifications
You must be signed in to change notification settings - Fork 921
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Drawer): fix the focus cannot be moved to elements outside the Dr…
…awer when `backdrop=false` (#3716)
- Loading branch information
Showing
6 changed files
with
187 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,37 @@ | ||
import React from 'react'; | ||
import Drawer from '../index'; | ||
import { render } from '@testing-library/react'; | ||
import { getStyle } from '@test/utils'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import '../styles/index.less'; | ||
|
||
describe('Drawer styles', () => { | ||
it('Should render the correct styles', () => { | ||
const instanceRef = React.createRef(); | ||
render(<Drawer open />); | ||
|
||
// FIXME Add missing `ref` delcaration for Drawer | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
render(<Drawer ref={instanceRef} open />); | ||
|
||
const drawer = (instanceRef.current as HTMLDivElement).querySelector( | ||
'.rs-drawer' | ||
) as HTMLElement; | ||
|
||
assert.equal(getStyle(drawer, 'position'), 'fixed'); | ||
assert.equal(getStyle(drawer, 'zIndex'), '1050'); | ||
assert.equal(getStyle(drawer, 'overflow'), 'visible'); | ||
expect(screen.getByRole('dialog')).to.have.style('z-index', '1050'); | ||
expect(screen.getByRole('dialog')).to.have.style('position', 'fixed'); | ||
expect(screen.getByRole('dialog')).to.have.style('overflow', 'visible'); | ||
}); | ||
|
||
it('Should have a wrapper that fills the window', () => { | ||
const instanceRef = React.createRef(); | ||
// FIXME Add missing `ref` delcaration for Drawer | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
render(<Drawer ref={instanceRef} open />); | ||
render(<Drawer open />); | ||
|
||
const wrapper = instanceRef.current as HTMLDivElement; | ||
const wrapper = screen.getByTestId('drawer-wrapper'); | ||
const windowHeight = window.innerHeight; | ||
const windowWidth = window.innerWidth; | ||
|
||
assert.equal(getStyle(wrapper, 'position'), 'fixed'); | ||
assert.equal(getStyle(wrapper, 'zIndex'), '1050'); | ||
assert.equal(getStyle(wrapper, 'width'), `${windowWidth}px`); | ||
assert.equal(getStyle(wrapper, 'height'), `${windowHeight}px`); | ||
assert.equal(getStyle(wrapper, 'left'), `0px`); | ||
assert.equal(getStyle(wrapper, 'top'), `0px`); | ||
expect(wrapper).to.have.style('position', 'fixed'); | ||
expect(wrapper).to.have.style('z-index', '1050'); | ||
expect(wrapper).to.have.style('width', `${windowWidth}px`); | ||
expect(wrapper).to.have.style('height', `${windowHeight}px`); | ||
expect(wrapper).to.have.style('left', `0px`); | ||
expect(wrapper).to.have.style('top', `0px`); | ||
}); | ||
|
||
it('Should not render backdrop', () => { | ||
render(<Drawer open backdrop={false} />); | ||
|
||
expect(screen.getByTestId('drawer-wrapper')).to.have.style('pointer-events', 'none'); | ||
expect(screen.getByRole('dialog')).to.have.style('pointer-events', 'auto'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.