Skip to content

Commit 1722432

Browse files
MC-3314: Cannot sort slides on slider
1 parent 2014962 commit 1722432

File tree

9 files changed

+96
-17
lines changed

9 files changed

+96
-17
lines changed

app/code/Magento/PageBuilder/Test/Mftf/Section/PageBuilderSliderSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<element name="firstSlideNavigationDot" type="button" selector="(//div[contains(@class, 'navigation-dot')])[1]"/>
3333
<element name="activeSlideTooltip" type="button" selector="//div[contains(@class, 'navigation-dot')]//span[contains(@role, 'tooltip')]"/>
3434
<element name="slideNavigationDot" type="button" selector="(//div[contains(@class, 'navigation-dot')])[{{arg1}}]" parameterized="true"/>
35+
<element name="slideNavigationDragHandle" type="button" selector="a.navigation-dot-anchor"/>
36+
<element name="slideNavigationDragHandleArgs" type="button" selector="(//a[contains(@class, 'navigation-dot-anchor')])[{{arg1}}]" parameterized="true"/>
3537
<element name="allNavigationDots" type="button" selector="(//div[contains(@class, 'navigation-dot')])"/>
3638
<element name="activeSlideNavigationDot" type="button" selector="//div[contains(@class, 'navigation-dot active')]"/>
3739
<element name="slideNavigationDotNameTooltip" type="button" selector="(//span[contains(@class, 'tooltip-content')])"/>

app/code/Magento/PageBuilder/Test/Mftf/Test/AdminPageBuilderSlideCommonTest.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,19 @@
696696
<see userInput="{{PageBuilderSlideItemName2.value}}" selector="{{SliderInAdmin.slideNavigationDotNameTooltip}}" stepKey="seeSlideName2InTooltip"/>
697697
<moveMouseOver selector="{{SliderInAdmin.slideNavigationDot('1')}}" stepKey="moveMouseOverFirstSlideNavigationDot"/>
698698
<see userInput="{{PageBuilderSlideItemName1.value}}" selector="{{SliderInAdmin.slideNavigationDotNameTooltip}}" stepKey="seeSlideName1InTooltip"/>
699+
<comment userInput="User sorts slides using drag and drop" stepKey="AC16"/>
700+
<executeJS function="return document.querySelectorAll('{{SliderInAdmin.slideNavigationDragHandle}}')[0].clientWidth / 4" stepKey="xCoordinateToMoveTo"/>
701+
<comment userInput="xCoordinateToMoveTo: $xCoordinateToMoveTo" stepKey="commentXCoordinate"/>
702+
<executeJS function="return document.querySelectorAll('{{SliderInAdmin.slideNavigationDragHandle}}')[1].clientHeight / 2" stepKey="yCoordinateToMoveTo"/>
703+
<comment userInput="yCoordinateToMoveTo: $yCoordinateToMoveTo" stepKey="commentYCoordinate"/>
704+
<click selector="{{SliderInAdmin.slideNavigationDot('2')}}" stepKey="clickButton"/>
705+
<dragAndDrop selector1="{{SliderInAdmin.slideNavigationDragHandleArgs('2')}}" selector2="{{SliderInAdmin.slideNavigationDot('1')}}" x="$xCoordinateToMoveTo" y="$yCoordinateToMoveTo" stepKey="dragAndDropSlide"/>
706+
<comment userInput="User hovers each slide dot, user sees tooltip displayed with Slide name after sorting" stepKey="AC17"/>
707+
<click selector="{{SliderInAdmin.sliderContainer}}" stepKey="unfocusNavigationAfterSort"/>
708+
<moveMouseOver selector="{{SliderInAdmin.activeSlideNavigationDot}}" stepKey="mouseOverActiveSlide2AfterSort"/>
709+
<see userInput="{{PageBuilderSlideItemName2.value}}" selector="{{SliderInAdmin.slideNavigationDotNameTooltip}}" stepKey="seeSlideName2InTooltipAfterSort"/>
710+
<moveMouseOver selector="{{SliderInAdmin.slideNavigationDot('2')}}" stepKey="moveMouseOverSecondSlideNavigationDot"/>
711+
<see userInput="{{PageBuilderSlideItemName1.value}}" selector="{{SliderInAdmin.slideNavigationDotNameTooltip}}" stepKey="seeSlideName1InTooltipAfterSort"/>
699712
</test>
700713
<test name="SliderDelete">
701714
<annotations>

app/code/Magento/PageBuilder/view/adminhtml/web/css/source/content-type/_preview.less

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292
opacity: 1;
293293
transform: translate(-50%, -50%);
294294
transition-delay: 200ms;
295-
visibility: visible;
295+
z-index: 30;
296296
}
297297

298298
.pagebuilder-options {
@@ -307,8 +307,7 @@
307307
top: 0;
308308
transform: translate(-50%, -50%);
309309
transition: opacity 200ms, visibility 200ms;
310-
visibility: hidden;
311-
z-index: 30;
310+
z-index: -1;
312311

313312
&.pagebuilder-options-visible {
314313
.pagebuilder-options-visible;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
}
208208
}
209209

210-
&:focus {
210+
&.focus {
211211
outline: 1px solid @color-blue-pure;
212212

213213
.pagebuilder-options {

app/code/Magento/PageBuilder/view/adminhtml/web/js/binding/sortable-children.js

Lines changed: 5 additions & 2 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/slider/preview.js

Lines changed: 33 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/slider/default/preview.html

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@
1616
<render args="previewChildTemplate" />
1717
</div>
1818
<div class="slider-controls focus-options">
19-
<div if="$parent.children().length > 0"
20-
class="slider-navigation"
19+
<div class="slider-navigation"
2120
each="$parent.getChildren()"
22-
data-bind="previewSortable: {handle: '.navigation-dot-anchor', containment: 'parent', placeholder: 'navigation-dot sortable-placeholder', tolerance: 'pointer', start: function () { onSortStart.apply($parent.preview, arguments); }, stop: function () { onSortStop.apply($parent.preview, arguments); } }">
21+
data-bind="sortableChildren: { handle: '.navigation-dot-anchor', containment: 'parent', placeholder: 'navigation-dot sortable-placeholder', tolerance: 'pointer', start: onSortStart.bind($parent.preview), stop: onSortStop.bind($parent.preview) }">
2322
<div class="navigation-dot"
24-
attr="{id: 'navigation-' + parent.id, tabindex: $index}"
25-
css="{active: $parent.activeSlide() === $index()}"
26-
data-bind="hasFocusNoScroll: $parent.focusedSlide() === $index(), event: { focusin: function () { $parent.setFocusedSlide($index()) }, focusout: function () { $parent.setFocusedSlide(null) } }">
23+
event="focusin: $parent.setFocusedSlide.bind($parent, $index(), false), focusout: $parent.setFocusedSlide.bind($parent, null, false)"
24+
css="active: $parent.activeSlide() === $index(), focus: $parent.focusedSlide() === $index()">
25+
<a class="navigation-dot-anchor" href="#" tabindex="0" click="$parent.onControlClick.bind($parent, $index())"/>
2726
<with args="preview">
2827
<render with="preview" args="getOptions().template" />
2928
</with>
30-
<a class="navigation-dot-anchor" href="#" data-bind="click: function () { $parent.navigateToSlide($index()); $parent.setFocusedSlide($index()); }"></a>
3129
<span if="preview.previewData.slide_name() !== ''"
3230
class="tooltip-content"
3331
role="tooltip"

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/binding/sortable-children.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ ko.bindingHandlers.sortableChildren = {
4040
ui,
4141
});
4242
})
43-
.on("sortstop", (event: Event, ui: JQueryUI.SortableUIParams) => {
43+
.on("sortstop", (event: JQueryEventObject, ui: JQueryUI.SortableUIParams) => {
4444
events.trigger("childContentType:sortStop", {
4545
instance,
4646
ui,
47+
originalPosition,
4748
});
4849
})
49-
.on("sortupdate", function(event: Event, ui: JQueryUI.SortableUIParams) {
50+
.on("sortupdate", function(event: JQueryEventObject, ui: JQueryUI.SortableUIParams) {
5051
if (this === ui.item.parent()[0]) {
5152
const index = ui.item.index();
5253
const targetParent = ko.dataFor(ui.item.parent()[0]).parent;
@@ -62,6 +63,7 @@ ko.bindingHandlers.sortableChildren = {
6263
newPosition: index,
6364
originalPosition,
6465
ui,
66+
event,
6567
});
6668
}
6769
}
@@ -74,4 +76,5 @@ export interface PreviewSortableSortUpdateEventParams {
7476
newPosition: number;
7577
originalPosition: number;
7678
ui: JQueryUI.SortableUIParams;
79+
event: JQueryEventObject;
7780
}

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,13 @@ export default class Preview extends PreviewCollection {
210210
* On sort stop ensure the focused slide and the active slide are in sync, as the focus can be lost in this
211211
* operation
212212
*/
213-
public onSortStop(): void {
213+
public onSortStop(event: JQueryEventObject, params: JQueryUI.SortableUIParams): void {
214214
if (this.activeSlide() !== this.focusedSlide()) {
215215
this.setFocusedSlide(this.activeSlide(), true);
216216
}
217+
if (params.item.index() !== -1) {
218+
_.defer(this.focusElement.bind(this, event, params.item.index()));
219+
}
217220
}
218221

219222
/**
@@ -247,6 +250,19 @@ export default class Preview extends PreviewCollection {
247250
return false;
248251
}
249252

253+
/**
254+
* Slider navigation click handler.
255+
*
256+
* @param {number} index
257+
* @param {Preview} context
258+
* @param {Event} event
259+
*/
260+
public onControlClick(index: number, context: Preview, event: Event) {
261+
$(event.target).focus();
262+
this.navigateToSlide(index);
263+
this.setFocusedSlide(index);
264+
}
265+
250266
/**
251267
* Bind events
252268
*/
@@ -265,6 +281,7 @@ export default class Preview extends PreviewCollection {
265281
if (args.instance.id === this.parent.id) {
266282
$(args.ui.item).remove(); // Remove the item as the container's children is controlled by knockout
267283
this.setActiveSlide(args.newPosition);
284+
_.defer(this.focusElement.bind(this, args.event, args.newPosition));
268285
}
269286
});
270287

@@ -336,6 +353,18 @@ export default class Preview extends PreviewCollection {
336353
});
337354
}
338355

356+
/**
357+
* Take dropped element on focus.
358+
*
359+
* @param {JQueryEventObject} event
360+
* @param {number} index
361+
*/
362+
private focusElement(event: JQueryEventObject, index: number) {
363+
const handleClassName = $(event.target).data("sortable").options.handle;
364+
365+
$($(event.target).find(handleClassName)[index]).focus();
366+
}
367+
339368
/**
340369
* To ensure smooth animations we need to lock the container height
341370
*/

0 commit comments

Comments
 (0)