Cannot close Select2 by clicking outside its container.
See original GitHub issuePrerequisites
- I have searched for similar issues in both open and closed tickets and cannot find a duplicate
- The issue still exists against the latest
masterbranch 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
- Put a select2 item in a container
- Open the select2 item
- 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:
- Created 6 years ago
- Comments:8 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Okay if anyone else is having this issue, it looks like you need to add:
I’ve updated the CodePen to show this too. Such a simple fix… I think it’s time for lunch. Been a long day!
Looks like a fix in issue #5499