Skip to content

Commit a4f564d

Browse files
committed
MC-3775: Button editable state is not consistent with the options panel appearing
- Align button focusing and interaction with slider and tabs content types
1 parent 7e43bb1 commit a4f564d

File tree

8 files changed

+191
-178
lines changed

8 files changed

+191
-178
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/css/source/content-type/button-item/_default.less

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,21 @@
1010
.pagebuilder-content-type {
1111
.pagebuilder-button-item {
1212
font-size: 0;
13+
margin: 0 10px 10px 0;
1314
max-width: 100%;
1415
width: auto;
1516
z-index: auto;
16-
.pagebuilder-options {
17-
bottom: 0;
18-
left: calc(50% - 5px);
19-
transform: translate(-50%, -50%);
20-
li.pagebuilder-options-link {
21-
margin: 0;
22-
}
23-
}
17+
2418
[contenteditable=true] {
2519
display: inline-block;
2620
min-height: 18px;
2721
min-width: 20px;
2822
}
23+
24+
a {
25+
margin: 0;
26+
}
27+
2928
a[data-element='link'] {
3029
max-width: 100%;
3130
min-width: 0;
@@ -37,42 +36,60 @@
3736
}
3837
}
3938

40-
&.pagebuilder-content-type-active {
41-
.pagebuilder-button-primary {
42-
.button-item-drag-handle {
43-
color: rgba(255, 255, 255, .8);
44-
}
39+
.button-item-drag-handle {
40+
height: 100%;
41+
left: 1px;
42+
opacity: 0;
43+
position: absolute;
44+
top: 0;
45+
transition: all .3s;
46+
visibility: hidden;
47+
width: 14px;
48+
49+
&.disabled:before {
50+
color: @color-light-gray;
51+
cursor: not-allowed;
4552
}
4653

47-
.button-item-drag-handle {
54+
&.disabled:active:before {
55+
cursor: not-allowed;
56+
}
57+
58+
&:before {
59+
.abs-icon;
4860
color: @color-dark-gray0;
61+
content: @icon-gripper__content;
4962
cursor: move; /* fallback if grab cursor is unsupported */
5063
cursor: grab;
5164
cursor: -moz-grab;
5265
cursor: -webkit-grab;
53-
left: 0;
54-
margin-top: -(@pagebuilder-button__font-size/2);
66+
display: block;
67+
font-size: 16px;
5568
position: absolute;
5669
top: 50%;
70+
transform: translateY(-50%);
71+
}
72+
73+
&:active:before {
74+
cursor: grabbing;
75+
cursor: -moz-grabbing;
76+
cursor: -webkit-grabbing;
77+
}
78+
}
5779

58-
&:active {
59-
cursor: grabbing;
60-
cursor: -moz-grabbing;
61-
cursor: -webkit-grabbing;
62-
}
80+
.pagebuilder-button-primary .button-item-drag-handle:before {
81+
color: @color-white;
82+
opacity: .7;
83+
}
6384

64-
&:before {
65-
.abs-icon;
66-
content: @icon-gripper__content;
67-
display: inline-block;
68-
font-size: @pagebuilder-button__font-size;
69-
position: absolute;
70-
}
85+
&.focused {
86+
.button-item-drag-handle {
87+
opacity: 1;
88+
visibility: visible;
89+
}
7190

72-
&.disabled {
73-
color: rgba(221, 221, 221, .4);
74-
cursor: not-allowed;
75-
}
91+
.pagebuilder-options {
92+
.pagebuilder-options-visible;
7693
}
7794
}
7895
}

app/code/Magento/PageBuilder/view/adminhtml/web/js/binding/live-edit.js

Lines changed: 8 additions & 11 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/content-type/button-item/preview.js

Lines changed: 6 additions & 44 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/content-type/buttons/preview.js

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@
55
*/
66
-->
77

8-
<div attr="data.main.attributes" ko-style="data.main.style" css="data.main.css" class="pagebuilder-content-type pagebuilder-button-item no-system-border focus-options" event="{ click: onButtonClick, focusout: onBlur }">
8+
<div attr="data.main.attributes"
9+
ko-style="data.main.style"
10+
css="Object.assign({focused: $parent.parent.preview.focusedButton() === $index()}, data.main.css)"
11+
class="pagebuilder-content-type pagebuilder-button-item no-system-border focus-options">
912
<render args="getOptions().template" />
10-
<a attr="data.link.attributes" ko-style="data.link.style" css="data.link.css">
13+
<a attr="data.link.attributes"
14+
ko-style="data.link.style"
15+
css="data.link.css"
16+
click="function (context, event) { onClick($index(), event); }">
1117
<span class="button-item-drag-handle" css="{disabled: parent.parent.children().length <= 1}"></span>
12-
<span attr="data.link_text.attributes" data-bind="liveEdit: { field: 'button_text', placeholder: buttonPlaceholder, selectAll: true }, hasFocus: $parent.parent.preview.isLiveEditing() === $index()" event="{ focusout: onFocusOut.call($data) }"></span>
18+
<span attr="Object.assign({tabindex: $index()}, data.link_text.attributes)"
19+
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); } }">>
21+
</span>
1322
</a>
1423
</div>

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/binding/live-edit.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ ko.bindingHandlers.liveEdit = {
5656
*/
5757
const onFocus = () => {
5858
focusedValue = stripHtml(element.innerHTML);
59+
60+
if (selectAll && element.innerHTML !== "") {
61+
const selection = window.getSelection();
62+
const range = document.createRange();
63+
range.selectNodeContents(element);
64+
selection.removeAllRanges();
65+
selection.addRange(range);
66+
}
5967
};
6068

6169
/**
@@ -67,15 +75,6 @@ ko.bindingHandlers.liveEdit = {
6775
}
6876
};
6977

70-
/**
71-
* Click event on element
72-
*/
73-
const onClick = () => {
74-
if (selectAll && element.innerHTML !== "") {
75-
document.execCommand("selectAll", false, null);
76-
}
77-
};
78-
7978
/**
8079
* Mousedown event on element
8180
*
@@ -161,7 +160,6 @@ ko.bindingHandlers.liveEdit = {
161160
element.contentEditable = true;
162161
element.addEventListener("focus", onFocus);
163162
element.addEventListener("blur", onBlur);
164-
element.addEventListener("click", onClick);
165163
element.addEventListener("mousedown", onMouseDown);
166164
element.addEventListener("keydown", onKeyDown);
167165
element.addEventListener("input", onInput);

0 commit comments

Comments
 (0)