Skip to content

Commit

Permalink
Drop selected element on mousedown elsewhere
Browse files Browse the repository at this point in the history
Resolves #13123
  • Loading branch information
brandonkelly committed Apr 26, 2023
1 parent f35c389 commit c509489
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Content Management
- Element slideouts now show their sidebar content full-screen for elements without a field layout, rather than having an empty body. ([#13056](https://github.com/craftcms/cms/pull/13056), [#13053](https://github.com/craftcms/cms/issues/13053))
- Relational fields no longer track the previously-selected element(s) when something outside the field is clicked on. ([#13123](https://github.com/craftcms/cms/issues/13123))

### Accessibility
- Image assets’ thumbnails and `<img>` tags generated via `craft\element\Asset::getImg()` no longer use the assets’ titles as `alt` fallback values. ([#12854](https://github.com/craftcms/cms/pull/12854))
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/web/assets/cp/src/js/BaseElementSelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ Craft.BaseElementSelectInput = Garnish.Base.extend(
Garnish.requestAnimationFrame(() => {
this._initialized = true;
});

if (this.elementSelect) {
this.addListener(Garnish.$win, 'mousedown', (ev) => {
if (
!this.$container.is(ev.target) &&
!this.$container.find(ev.target).length
) {
this.elementSelect.deselectAll();
}
});
}
},

get totalSelected() {
Expand Down

0 comments on commit c509489

Please sign in to comment.