question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dropdown not closing inside a bootstrap modal

See original GitHub issue

I’m submitting a …

[x] bug report => search github for a similar issue or PR before submitting
[ ] support request/question

Current behavior When I use the tag-input-dropdown component inside a bootstrap (v 4.0.0+) modal, I can’t close the dropdown menu clicking inside the modal. If I change the appendToBody property to false, is possible to close it by clicking inside, but its position is changed, appearing outside the modal. Note: I found someone who had the same problem on StackOverflow, but without answers/comments.

Expected behavior There are 2 options here:

  • The dropdown would be successfully closed when clicking inside the modal without changing the value of appendToBody.
  • The dropdown would be successfully closed when clicking inside the modal afterchanging the value of appendToBody, but its position would stay the same as option 1.

Minimal reproduction of the problem with instructions (if applicable) https://stackblitz.com/edit/angular-jmsqe1 Note: The dropdown position problem can be better seen by clicking on “Open in New Window” option in StackBlitz.

What do you use to build your app?. Please specify the version angular-cli

Angular version: 6.0.7

ngx-chips version: 1.9.2

Browser: Tested on Chrome 67

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
cesariccommented, Jan 8, 2021

To get the dropdown to hide in a modal/pop-up, [appendToBody]="false" was messing up positioning of the tag-input-dropdown so I set it to:

<tag-input-dropdown
[appendToBody]="true"
[zIndex]="2000"
>

and then did the following in my modal component:

  @ViewChild(TagInputComponent)
  tagInput: TagInputComponent;
  @ViewChild(TagInputDropdown)
  tagInputDropdown: TagInputDropdown;
  

  @HostListener('click')
  onClick()
  {
    if (!this.tagInput.isInputFocused() && this.tagInputDropdown.isVisible) {
      this.tagInputDropdown.hide();
    }
  }

Hacky but it works (I couldn’t get a blur event fix sorted).

[Update] Here’s a simpler update to the above in case you have multiple ngx-chip controls in the same modal/pop-up:

@ViewChildren(TagInputComponent)
private tagInputs: QueryList<TagInputComponent>;


 @HostListener('click')
  onClick()
  {
    this.tagInputs.forEach(tagInput => {
      if (!tagInput.isInputFocused() && tagInput.dropdown.isVisible) {
        tagInput.dropdown.hide();
      }
    })
  }
3reactions
Tawsifcommented, Jul 30, 2018

@lucianojs @Gbuomprisco @lucas-carneiro I have a temporary fix for this issue:

add [appendToBody] = “false” to tag-input-dropdown and then add following css in global styles.css

.ng2-dropdown-menu { position: absolute !important; left: 2% !important; top: 100% !important; }

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found