Skip to content

Don't toggle the dropdown when clearing or unselecting - #6450

Open
omergorur wants to merge 1 commit into
select2:developfrom
omergorur:develop
Open

omergorur wants to merge 1 commit into
select2:developfrom
omergorur:develop

Conversation

@omergorur

@omergorur omergorur commented Aug 28, 2026

Copy link
Copy Markdown

This pull request includes a

  • Bug fix
  • New feature
  • Translation

The following changes were made

  • MultipleSelection: the delegated click handler for .select2-selection__choice__remove now calls evt.stopPropagation(), so removing a choice doesn't bubble up to the selection's toggle handler and open the dropdown. The keydown handler for the same selector already does this.
  • AllowClear._handleClear: removed the trailing this.trigger('toggle', {}), so clearing a selection no longer opens the dropdown (and no longer triggers an unwanted ajax query via open(), see Ajax is requested when clear button is pressed and dropdown has been kept closed #6116).

In both cases the user is just removing a selection, but the dropdown opens as a side effect. This has been reported a few times over the years (#3632, #4281, #3320) and is usually worked around with the select2:unselecting + select2:opening preventDefault trick.

No new options or API changes. Test suite passes (1088 tests, 0 failed, all four jQuery matrices). Note this does change behavior for anyone relying on the clear button also opening the dropdown.

Fixes #6389, fixes #6116

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.

Prevent Select2 dropdown opening when clicking the remove button Ajax is requested when clear button is pressed and dropdown has been kept closed

1 participant