Skip to content

Commit dc832ec

Browse files
committed
MC-3775: Button editable state is not consistent with the options panel appearing
- Fix focusing issues on load
1 parent 50905c9 commit dc832ec

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

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

Lines changed: 9 additions & 3 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/js/utils/delay-until.js

Lines changed: 30 additions & 0 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/buttons/preview.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import ContentTypeMountEventParamsInterface from "../content-type-mount-event-pa
2424
import ContentTypeRedrawAfterEventParamsInterface from "../content-type-redraw-after-event-params";
2525
import ObservableUpdater from "../observable-updater";
2626
import PreviewCollection from "../preview-collection";
27+
import delayUntil from "../../utils/delay-until";
2728

2829
/**
2930
* @api
@@ -63,6 +64,12 @@ export default class Preview extends PreviewCollection {
6364
this.focusedButton.subscribe(_.debounce((index: number) => {
6465
if (index !== null) {
6566
events.trigger("stage:interactionStart");
67+
const focusedButton = this.parent.children()[index];
68+
delayUntil(
69+
() => $(focusedButton.preview.wrapperElement).find("[contenteditable]").focus(),
70+
() => typeof focusedButton.preview.wrapperElement !== "undefined",
71+
10,
72+
);
6673
} else {
6774
// We have to force the stop as the event firing is inconsistent for certain operations
6875
events.trigger("stage:interactionStop", {force : true});
@@ -114,7 +121,6 @@ export default class Preview extends PreviewCollection {
114121
events.on("button-item:mountAfter", (args: ContentTypeMountEventParamsInterface) => {
115122
if (duplicatedButton && args.id === duplicatedButton.id) {
116123
this.focusedButton(duplicatedButtonIndex);
117-
$(duplicatedButton.preview.wrapperElement).find("[contenteditable]").focus();
118124
}
119125
});
120126
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/**
7+
* Delay until a condition is met
8+
*
9+
* @param {() => void} callback
10+
* @param {() => boolean} condition
11+
* @param {number} interval
12+
*/
13+
export default function delayUntil(
14+
callback: () => void,
15+
condition: () => boolean,
16+
interval: number = 50,
17+
) {
18+
const delayInterval = setInterval(() => {
19+
if (condition()) {
20+
clearInterval(delayInterval);
21+
callback();
22+
}
23+
}, interval);
24+
}

0 commit comments

Comments
 (0)