-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Added autoClose behaviour for dropdowns #5873
Added autoClose behaviour for dropdowns #5873
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, looks good. Thanks for taking this on. Left a few comments.
src/Dropdown.tsx
Outdated
@@ -47,6 +47,7 @@ export interface DropdownProps | |||
focusFirstItemOnShow?: boolean | 'keyboard'; | |||
onSelect?: SelectCallback; | |||
navbar?: boolean; | |||
autoClose: 'true' | 'outside' | 'inside' | 'false'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change the string true/false to a boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I thought of that as well. Wasn't sure about the consistency but I will change that.
src/Dropdown.tsx
Outdated
source = 'rootClose'; | ||
|
||
const noOuterCloseModes = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth leaving comments about click what elements triggers the closing of the dropdown so it's more clear
test/DropdownSpec.js
Outdated
@@ -333,4 +333,141 @@ describe('<Dropdown>', () => { | |||
).assertSingle('div.dropdown-menu'); | |||
}); | |||
}); | |||
|
|||
describe('autoClose behaviour', () => { | |||
const createDocumentListenersMock = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this? We have other methods in other tests to trigger click events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't notice any method concerned with simulating clicks outside of the component. Correct me if I'm wrong. Should we keep the outside click methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We did use simulant.fire(document.body, 'click');
inside an Offcanvas test. Can we try that and see if it works for your test?
@@ -0,0 +1,15 @@ | |||
<> | |||
{[true, 'outside', 'inside', false].map((autoClose, index) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if we should rearrange/reword the examples so it mirrors upstream Bootstrap examples:
https://getbootstrap.com/docs/5.0/components/dropdowns/#auto-close-behavior
I got thrown off with the autoclose behavior for "inside" and "outside" differing from Bootstrap's docs, but turns out it was an issue of ordering/wording.
Looks good to me - left 1 comment regarding docs demo. @jquense, would be good to get your eyes on this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, happy with how this was relatively straightforward to implement outside of react-overlays this is
Thanks! |
More about the autoClose behaviour here.
Additionally to the implementation, I've added
Preview: https://deploy-preview-5873--react-bootstrap.netlify.app/