-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Dropdown): prevent flickering on 'mousedown' rootCloseEvent (#6714)
* disabled mouseDown event on toggleButton of dropdown * added comments for handleToggle changes * test for rootCloseEvent
- Loading branch information
1 parent
6728619
commit a58a0cd
Showing
2 changed files
with
36 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { render, fireEvent, screen } from '@testing-library/react'; | ||
import Dropdown from '../src/Dropdown'; | ||
|
||
describe('<Dropdown.Menu rootCloseEvent="mousedown">', () => { | ||
it('does not flicker when rootCloseEvent is set to "mousedown" and toggle button is clicked', () => { | ||
const { container } = render( | ||
<Dropdown> | ||
<Dropdown.Toggle id="dropdown-basic" data-testid="dropdown-toggle"> | ||
Dropdown Button | ||
</Dropdown.Toggle> | ||
<Dropdown.Menu rootCloseEvent="mousedown"> | ||
<Dropdown.Item href="#/action-1">Action</Dropdown.Item> | ||
</Dropdown.Menu> | ||
</Dropdown>, | ||
); | ||
// Click the toggle button to open the menu | ||
fireEvent.click(screen.getByTestId('dropdown-toggle')); | ||
// The menu should now be in the DOM | ||
container.firstElementChild!.classList.contains('show').should.be.true; | ||
// Click the toggle button again to close the menu | ||
fireEvent.click(screen.getByTestId('dropdown-toggle')); | ||
// The menu should no longer be in the DOM | ||
container.firstElementChild!.classList.contains('show').should.be.false; | ||
}); | ||
}); |