Cannot close Select2 by clicking outside its container.

See original GitHub issue

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate
  • The issue still exists against the latest master branch of Select2
  • This is not a usage question (Those should be directed to the community)
  • I have attempted to find the simplest possible steps to reproduce the issue

Steps to reproduce the issue

  1. Put a select2 item in a container
  2. Open the select2 item
  3. You can close the select2 by clicking in the container, but not outside of it.

Expected behavior and actual behavior

When I follow those steps, You’re unable to close the select2 when clicking outside of the container (For example when the select 2 overflows the container it’s in).

I was expecting the select2 to close if I clicked anywhere on the page.

Environment

Browsers

  • Google Chrome (Version 59.0.3071.82 (Official Build) beta (64-bit))
  • Mozilla Firefox (Version 52.0.1)
  • Internet Explorer (Version 11)

Operating System

  • Windows
  • Mac OS X

Libraries

  • jQuery version: 3.2.1
  • Select2 version: 4.0.3

Isolating the problem

  • The bug happens consistently across all tested browsers
  • The bug happens with just select2 and jQuery (See CodePen Below)
  • I can reproduce this bug in a CodePen
  • Example GIF

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
AshboDevcommented, Jun 5, 2017

Okay if anyone else is having this issue, it looks like you need to add:

html,
body {
  height: 100%;
}

I’ve updated the CodePen to show this too. Such a simple fix… I think it’s time for lunch. Been a long day!

1reaction
AshboDevcommented, May 6, 2019

Looks like a fix in issue #5499

Read more comments on GitHub >

github_iconTop Results From Across the Web

Select2 does not close the choices box on clicking outside it ...
When the choice box is open, if you try clicking anywhere outside on the level of the choice box, it doesn't get closed....
Read more >
Methods | Select2 - The jQuery replacement for select boxes
Methods handled directly by Select2 can be invoked by passing the name of the method ... The close method will cause the dropdown...
Read more >
Select2 problem - Laracasts
While I clicking outside without selecting an option then the select2 search bar and results are remaining!!! What is the problem? My Code:...
Read more >
How to avoid dropdown menu to close menu items on clicking ...
stopPropagation (): The stopPropagation() method is used to stop propagation of event calling i.e. the parent event is called we can stop the ......
Read more >
Select2 3.5.3
Initial value that is selected if no other selection is made. The placeholder can also be specified as a data-placeholder attribute on the...
Read more >

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