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

Dropdown - autoclose on outside click option #1022

Closed
NgxDev opened this issue Nov 9, 2016 · 6 comments
Closed

Dropdown - autoclose on outside click option #1022

NgxDev opened this issue Nov 9, 2016 · 6 comments

Comments

@NgxDev
Copy link

NgxDev commented Nov 9, 2016

Feature request

It would be a useful addition to have another autoClose option: onOutsideClick (or another meaningful name), so we can keep the dropdown open as long as we click somewhere inside it.

@NgxDev NgxDev mentioned this issue Nov 9, 2016
4 tasks
@forrestab
Copy link

Since this project uses Typescript and Typescript supports enums, you all may want to consider changing autoClose to accept an enum instead of a boolean.

@pkozlowski-opensource
Copy link
Member

so we can keep the dropdown open as long as we click somewhere inside it.

This can be easily achieved by stopping propagation of click events triggered on menu item elements.

@pkozlowski-opensource
Copy link
Member

This can be easily achieved by stopping propagation of click events triggered on menu item elements.

Scratch this - it won't work properly with multiple dropdowns...

@pkozlowski-opensource
Copy link
Member

pkozlowski-opensource commented Aug 9, 2017

Since this project uses Typescript and Typescript supports enums, you all may want to consider changing autoClose to accept an enum instead of a boolean.

@forrestab enums are not ideal since you would have to expose an enum on a component's instance. In practice to achieve the following:

<div ngbDropdown [autoClose]="CloseEnum.INSIDE">
...html
</div>

You would have to have CloseEnum on the component's instance which is too much pain in practice, IMO. How about the following API:

@Input() autoClose: boolean | 'inside' | 'outside';

@mscudlik
Copy link

mscudlik commented Aug 12, 2017

The document click listener currently runs in the zone

'(document:click)': 'closeFromOutsideClick($event)'

This means each click will trigger an angular change detection.
If you have one dropdown thats not a problem. If you have lots of dropdowns (for example in a large table) it will become a performance problem. You should replace the event listener to run outside of the angular zone with ngZone.runOutsideAngular() and do the change detection manually only if required

@pkozlowski-opensource
Copy link
Member

@matthiasscudlik you are right, we are planning to change it. The issue is already tracked via #900

rmeans pushed a commit to fcsa-teamhammer/ng-bootstrap that referenced this issue Oct 18, 2017
Closes ng-bootstrap#1022

BREAKING CHANGE:

Dropdown menu now requires usage of the new `ngbDropdownMenu` directive.

Before:

```html
<div ngbDropdown>
  <button ngbDropdownToggle>Toggle dropdown</button>
  <div class="dropdown-menu">
    <a class="dropdown-item">Action</a>
  </div>
</div>
```

After (notice **ngbDropdownMenu**):

```html
<div ngbDropdown>
  <button ngbDropdownToggle>Toggle dropdown</button>
  <div ngbDropdownMenu>
    <a class="dropdown-item">Action</a>
  </div>
</div>
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants