Skip to content

Added autoClose behaviour for dropdowns - #5873

Merged
kyletsang merged 2 commits into
react-bootstrap:masterfrom
jotoh98:feature/dropdown-autoclose
Jun 17, 2021
Merged

Added autoClose behaviour for dropdowns#5873
kyletsang merged 2 commits into
react-bootstrap:masterfrom
jotoh98:feature/dropdown-autoclose

Conversation

@jotoh98

@jotoh98 jotoh98 commented Jun 9, 2021

Copy link
Copy Markdown
Contributor

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/

@kyletsang kyletsang left a comment

Copy link
Copy Markdown
Member

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.

Comment thread src/Dropdown.tsx Outdated
focusFirstItemOnShow?: boolean | 'keyboard';
onSelect?: SelectCallback;
navbar?: boolean;
autoClose: 'true' | 'outside' | 'inside' | 'false';

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/Dropdown.tsx Outdated
) {
source = 'rootClose';

const noOuterCloseModes =

Copy link
Copy Markdown
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

Comment thread test/DropdownSpec.js Outdated
});

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

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

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

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

@jquense jquense left a comment

Copy link
Copy Markdown
Member

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
@kyletsang

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants