-
-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(dropdown): close dropdown when item is selected #392
fix(dropdown): close dropdown when item is selected #392
Conversation
Close the dropdown menu whenever an instance of DropdownItem is clicked. fix #349
… callback Add comment to the method that attaches clsoeDropdown callback
Adds a tests to check that the dropdown is closed whenever an item is clicked. fix #349
…ng an additional prop Remove the additional closeDropdown props from DropdownItem, extend onClick props instead. fix #349
Fix prettier build error for Dropdown.spec.ts
Updates the Dropdown attachCloseListener comment to better reflect the changes
Hey, I would appreciate a little bit of help here. I'm not sure why the test is failing when it passes when tested locally. The weird part is, the tests pass too when I create a PR to the main branch of my fork. |
Well, it is also passing locally for me. Maybe some configuration/restriction to the CI? But... I don't actually see any big difference from other tests. 🤔 |
Ugh, I don't really want to spam this with commits. Let me try following React's warning about using |
Wrap dropdown's mouse interaction tests for item click with act
Description
Closes the dropdown floating menu whenever a DropdownItem is clicked.
Inside
Dropdown/index.tsx
, a mapping function is executed that extends theonClick
props of all instances of DropdownItem. The extended lines trigger a local state change tocloseRequestKey
that is passed to theFloating/index.tsx
component.setOpen(false)
is called inside the Floating component whenever the closeRequestKey is changed to a unique string generated by the UUID helper function.This emulates the Dropdown component requesting Floating to close itself. This is the only workaround that I can think of due to how the component is designed. Floating is contained with Dropdown, preventing other ways of passing control of the
open
state to Dropdown and its child.We can move this entirely in
Floating/index.tsx
to perform the mapping but since it is reused on other components, I opted to isolate most changes on the Dropdown components themselves.Fixes #349
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Checklist: