Skip to content

Commit 403f28d

Browse files
committed
MC-14994: Heading (& Text, Banner, Slide) toolbar menu is positioned incorrectly on first drop on stage
- fix toolbar race condition for first time drop from panel
1 parent be5fa8e commit 403f28d

File tree

2 files changed

+40
-17
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web

2 files changed

+40
-17
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/heading/preview.js

Lines changed: 20 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/heading/preview.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import $ from "jquery";
7+
import events from "Magento_PageBuilder/js/events";
78
import _ from "underscore";
89
import ContentTypeConfigInterface from "../../content-type-config.types";
910
import HideShowOption from "../../content-type-menu/hide-show-option";
@@ -12,6 +13,7 @@ import Toolbar, {ContentTypeToolbarPreviewInterface} from "../../content-type-to
1213
import {OptionInterface} from "../../content-type-toolbar.types";
1314
import ContentTypeInterface from "../../content-type.types";
1415
import deferred, {DeferredInterface} from "../../utils/promise-deferred";
16+
import {ContentTypeDroppedCreateEventParamsInterface} from "../content-type-events.types";
1517
import ObservableUpdater from "../observable-updater";
1618
import BasePreview from "../preview";
1719

@@ -38,15 +40,6 @@ export default class Preview extends BasePreview implements ContentTypeToolbarPr
3840
this,
3941
this.getToolbarOptions(),
4042
);
41-
42-
Promise.all([
43-
this.afterRenderDeferred.promise,
44-
this.toolbar.afterRenderDeferred.promise,
45-
]).then(([element]) => {
46-
_.defer(() => {
47-
$(element).focus();
48-
});
49-
});
5043
}
5144

5245
/**
@@ -79,6 +72,24 @@ export default class Preview extends BasePreview implements ContentTypeToolbarPr
7972
this.afterRenderDeferred.resolve(element);
8073
}
8174

75+
public bindEvents() {
76+
super.bindEvents();
77+
78+
// When a heading is dropped for the first time show heading toolbar
79+
events.on("heading:dropAfter", (args: ContentTypeDroppedCreateEventParamsInterface) => {
80+
if (args.id === this.contentType.id) {
81+
Promise.all([
82+
this.afterRenderDeferred.promise,
83+
this.toolbar.afterRenderDeferred.promise,
84+
]).then(([element]) => {
85+
_.defer(() => {
86+
$(element).focus();
87+
});
88+
});
89+
}
90+
});
91+
}
92+
8293
/**
8394
* Build and return the tool bar options for heading
8495
*

0 commit comments

Comments
 (0)