Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit e16a300

Browse files
committed
🐛 Koenig - Fixed clicking certain icons in /-menu not creating cards
refs TryGhost/Ghost#9724 - the click event from clicking on the /-menu items continued propagating after the card was initialised which meant it was picked up by the card as a "click off the card" so certain cards such as the Markdown/HTML cards would then remove themselves as if they were deselected with empty content - changed the icon click handler to use the DOM `onclick` syntax so that the click can be captured immediately rather than waiting for it to bubble up to Ember's global event handler - updated the /-menu `itemClicked` action to use the now-accessible MouseEvent to stop it propagating any further and triggering unwanted card behaviour
1 parent bad0bf6 commit e16a300

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/koenig-editor/addon/components/koenig-slash-menu.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,17 @@ export default Component.extend({
8888
},
8989

9090
actions: {
91-
itemClicked(item) {
91+
itemClicked(item, event) {
9292
let range = this._openRange.head.section.toRange();
9393
let [, ...params] = this._query.split(/\s/);
9494
let payload;
9595

96+
// make sure the click doesn't propagate and get picked up by the
97+
// newly inserted card which can then remove itself because it
98+
// looks like a click outside of an empty card
99+
event.preventDefault();
100+
event.stopImmediatePropagation();
101+
96102
// params are order-dependent and listed in CARD_MENU for each card
97103
if (!isEmpty(item.params) && !isEmpty(params)) {
98104
payload = {};

lib/koenig-editor/addon/templates/components/koenig-menu-content.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{{section.title}}
44
</div>
55
{{#each section.items as |item|}}
6-
<div class="{{if item.selected "kg-cardmenu-card-selected"}} {{kg-style "cardmenu-card"}}" {{action itemClicked item on="click"}} data-kg="cardmenu-card">
6+
<div class="{{if item.selected "kg-cardmenu-card-selected"}} {{kg-style "cardmenu-card"}}" onclick={{action itemClicked item}} data-kg="cardmenu-card">
77
<div class="{{kg-style "cardmenu-icon"}}">{{svg-jar item.icon class="w8 h8 stroke-midgrey"}}</div>
88
<div class="{{kg-style "cardmenu-label"}}">{{item.label}}</div>
99
</div>

0 commit comments

Comments
 (0)