Skip to content
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

Merged
merged 2 commits into from
Jun 17, 2021
Merged

Added autoClose behaviour for dropdowns #5873

merged 2 commits into from
Jun 17, 2021

Conversation

jotoh98
Copy link
Contributor

@jotoh98 jotoh98 commented Jun 9, 2021

More about the autoClose behaviour here.

Additionally to the implementation, I've added

  • a playground example
  • a documentation section
  • unit-tests

Preview: https://deploy-preview-5873--react-bootstrap.netlify.app/

Copy link
Member

@kyletsang kyletsang left a 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';
Copy link
Member

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

Copy link
Contributor Author

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 =
Copy link
Member

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

@@ -333,4 +333,141 @@ describe('<Dropdown>', () => {
).assertSingle('div.dropdown-menu');
});
});

describe('autoClose behaviour', () => {
const createDocumentListenersMock = () => {
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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?

@jotoh98 jotoh98 marked this pull request as ready for review June 14, 2021 22:37
@@ -0,0 +1,15 @@
<>
{[true, 'outside', 'inside', false].map((autoClose, index) => (
Copy link
Member

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.

@kyletsang kyletsang requested a review from jquense June 15, 2021 00:18
@kyletsang
Copy link
Member

Looks good to me - left 1 comment regarding docs demo.

@jquense, would be good to get your eyes on this.

@kyletsang kyletsang added this to In Progress in v5 support via automation Jun 15, 2021
Copy link
Member

@jquense jquense left a 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

@kyletsang kyletsang merged commit f5b511c into react-bootstrap:master Jun 17, 2021
v5 support automation moved this from In Progress to Done Jun 17, 2021
@kyletsang
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
v5 support
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants