Skip to content

Commit 50905c9

Browse files
committed
MC-3775: Button editable state is not consistent with the options panel appearing
- Improve focusing and tabbing on buttons
1 parent f159adb commit 50905c9

File tree

4 files changed

+86
-5
lines changed

4 files changed

+86
-5
lines changed

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

Lines changed: 43 additions & 1 deletion
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/template/content-type/button-item/default/preview.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
css="data.link.css"
1616
click="function (context, event) { onClick($index(), event); }">
1717
<span class="button-item-drag-handle" css="{disabled: parent.parent.children().length <= 1}"></span>
18-
<span attr="Object.assign({tabindex: $index()}, data.link_text.attributes)"
18+
<span attr="data.link_text.attributes"
1919
data-bind="liveEdit: { field: 'button_text', placeholder: buttonPlaceholder, selectAll: true }, hasFocusNoScroll: $parent.parent.preview.focusedButton() === $index()"
20-
event="{ focusin: function () { $parent.parent.preview.focusedButton($index()) }, focusout: function () { window.getSelection().removeAllRanges(); $parent.parent.preview.focusedButton(null); } }">>
20+
event="{ focusin: function (context, event) { onFocusIn($index(), event); }, focusout: function (context, event) { onFocusOut($index(), event); } }">
2121
</span>
2222
</a>
2323
</div>

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

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

66
import $ from "jquery";
7+
import ko from "knockout";
78
import $t from "mage/translate";
89
import ConditionalRemoveOption from "../../content-type-menu/conditional-remove-option";
910
import {OptionsInterface} from "../../content-type-menu/option.d";
@@ -43,6 +44,44 @@ export default class Preview extends BasePreview {
4344
event.stopPropagation();
4445
}
4546

47+
/**
48+
* On focus out
49+
*
50+
* @param {number} index
51+
* @param {Event} event
52+
*/
53+
public onFocusOut(index: number, event: JQueryEventObject): void {
54+
const parentPreview = this.parent.parent.preview as ButtonsPreview;
55+
if (!event.relatedTarget) {
56+
if (parentPreview.focusedButton() === index) {
57+
window.getSelection().removeAllRanges();
58+
parentPreview.focusedButton(null);
59+
}
60+
} else {
61+
// Have we moved the focus onto another button in the current group?
62+
if ($.contains(parentPreview.wrapperElement, event.relatedTarget)) {
63+
const buttonItem = ko.dataFor(event.relatedTarget) as Preview;
64+
if (buttonItem) {
65+
$(buttonItem.wrapperElement).find("[contenteditable]").focus();
66+
}
67+
} else {
68+
window.getSelection().removeAllRanges();
69+
parentPreview.focusedButton(null);
70+
}
71+
}
72+
}
73+
74+
/**
75+
* On focus in set the focused button
76+
*
77+
* @param {number} index
78+
* @param {Event} event
79+
*/
80+
public onFocusIn(index: number, event: Event): void {
81+
const parentPreview = this.parent.parent.preview as ButtonsPreview;
82+
parentPreview.focusedButton(index);
83+
}
84+
4685
/**
4786
* If the button is displayed we need to show the options menu on hover
4887
*

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import ContentTypeInterface from "../../content-type.d";
1919
import StageUpdateAfterParamsInterface from "../../stage-update-after-params.d";
2020
import ContentTypeAfterRenderEventParamsInterface from "../content-type-after-render-event-params.d";
2121
import ContentTypeDroppedCreateEventParamsInterface from "../content-type-dropped-create-event-params";
22+
import ContentTypeDuplicateEventParamsInterface from "../content-type-duplicate-event-params";
23+
import ContentTypeMountEventParamsInterface from "../content-type-mount-event-params";
2224
import ContentTypeRedrawAfterEventParamsInterface from "../content-type-redraw-after-event-params";
2325
import ObservableUpdater from "../observable-updater";
2426
import PreviewCollection from "../preview-collection";
25-
import ContentTypeMountEventParamsInterface from "../content-type-mount-event-params";
26-
import ContentTypeDuplicateEventParamsInterface from "../content-type-duplicate-event-params";
2727

2828
/**
2929
* @api

0 commit comments

Comments
 (0)