Skip to content

Commit e50d0b8

Browse files
authored
fix(ui5-dialog): fix RTL Dialog resizing to keep right edge anchored (#12313)
fixes: #12310
1 parent c5c44d8 commit e50d0b8

File tree

3 files changed

+96
-3
lines changed

3 files changed

+96
-3
lines changed

packages/main/cypress/specs/Dialog.cy.tsx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,66 @@ describe("Dialog general interaction", () => {
694694
});
695695
});
696696

697+
it("dialog remains anchored after resizing in RTL mode", () => {
698+
cy.mount(
699+
<>
700+
<div dir="rtl">
701+
<Dialog id="rtl-min-width-dialog" resizable>
702+
<div id="header-slot" slot="header">Header</div>
703+
<div>Content Content Content Content Content Content Content Content Content Content Content Content</div>
704+
<Button id="resizable-close">Close</Button>
705+
</Dialog>
706+
</div>
707+
</>
708+
);
709+
710+
// Open dialog
711+
cy.get("#rtl-min-width-dialog").invoke("attr", "open", true);
712+
cy.get<Dialog>("#rtl-min-width-dialog").ui5DialogOpened();
713+
714+
// Capture initial dimensions and position
715+
cy.get("#rtl-min-width-dialog").then(dialog => {
716+
const initialLeft = parseInt(dialog.css("left"));
717+
const initialWidth = parseInt(dialog.css("width"));
718+
const initialRightEdge = initialLeft + initialWidth;
719+
720+
// First resize to reach minimum width
721+
cy.get("#rtl-min-width-dialog")
722+
.shadow()
723+
.find(".ui5-popup-resize-handle")
724+
.realMouseDown()
725+
.realMouseMove(800, 0) // Large movement to ensure we hit min width
726+
.realMouseUp();
727+
728+
cy.get("#rtl-min-width-dialog").then(dialogAtMinWidth => {
729+
const leftAtMinWidth = parseInt(dialogAtMinWidth.css("left"));
730+
const widthAtMinWidth = parseInt(dialogAtMinWidth.css("width"));
731+
const rightEdgeAtMinWidth = leftAtMinWidth + widthAtMinWidth;
732+
733+
expect(widthAtMinWidth).to.equal(320);
734+
expect(rightEdgeAtMinWidth).to.equal(initialRightEdge);
735+
736+
cy.get("#rtl-min-width-dialog")
737+
.shadow()
738+
.find(".ui5-popup-resize-handle")
739+
.realMouseDown()
740+
.realMouseMove(150, 0) // Additional rightward movement beyond min width
741+
.realMouseUp();
742+
743+
cy.get("#rtl-min-width-dialog").then(dialogAfterExtraResize => {
744+
const finalLeft = parseInt(dialogAfterExtraResize.css("left"));
745+
const finalWidth = parseInt(dialogAfterExtraResize.css("width"));
746+
const finalRightEdge = finalLeft + finalWidth;
747+
748+
expect(finalLeft).to.equal(leftAtMinWidth, "Dialog left position should not change when at min width");
749+
expect(finalWidth).to.equal(widthAtMinWidth, "Dialog width should remain at min width");
750+
expect(finalRightEdge).to.equal(rightEdgeAtMinWidth, "Dialog right edge should remain fixed");
751+
expect(finalRightEdge).to.equal(initialRightEdge, "Dialog right edge should remain fixed from initial position");
752+
});
753+
});
754+
});
755+
});
756+
697757
it("resizable - keyboard support", () => {
698758
cy.mount(
699759
<>

packages/main/src/Dialog.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,11 +614,12 @@ class Dialog extends Popup {
614614
});
615615

616616
const deltaWidth = newWidth - this.getBoundingClientRect().width;
617+
const rightEdge = this._initialLeft! + this._initialWidth! + deltaWidth;
617618

618619
newLeft = clamp(
619-
this._initialLeft! + (clientX - this._initialX!) + deltaWidth,
620+
rightEdge - newWidth,
620621
0,
621-
this._initialX! + this._initialWidth! - this._minWidth!,
622+
rightEdge - this._minWidth!,
622623
);
623624
} else {
624625
newWidth = clamp(
@@ -637,7 +638,7 @@ class Dialog extends Popup {
637638
Object.assign(this.style, {
638639
height: `${newHeight}px`,
639640
width: `${newWidth}px`,
640-
left: newLeft ? `${newLeft}px` : undefined,
641+
left: this._isRTL ? `${newLeft}px` : undefined,
641642
});
642643
}
643644

packages/main/test/pages/Dialog.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
<ui5-button id="draggable-and-resizable-open">Open draggable & resizable dialog</ui5-button>
8383
<br>
8484
<br>
85+
<ui5-button id="rtl-draggable-and-resizable-open">Open RTL draggable & resizable dialog</ui5-button>
86+
<br>
87+
<br>
88+
<ui5-button id="rtl-maxwidth-resizable-open">Open RTL max-width resizable dialog</ui5-button>
89+
<br>
90+
<br>
8591
<ui5-button id="dynamic-open">Open dialog which is created dynamically</ui5-button>
8692
<br>
8793
<br>
@@ -424,6 +430,28 @@
424430
</div>
425431
</ui5-dialog>
426432

433+
<div dir="rtl">
434+
<ui5-dialog id="rtl-draggable-and-resizable-dialog" header-text="Draggable/Resizable dialog" draggable resizable>
435+
<p>Move this dialog around the screen by dragging it by its header.</p>
436+
<p>Resize this dialog by dragging it by its resize handle.</p>
437+
<p>These features are available only on Desktop.</p>
438+
<ui5-toolbar slot="footer">
439+
<ui5-toolbar-button id="rtl-draggable-and-resizable-close" design="Emphasized" text="OK"></ui5-toolbar-button>
440+
</ui5-toolbar>
441+
</ui5-dialog>
442+
</div>
443+
444+
<div dir="rtl">
445+
<ui5-dialog style="max-width: 500px" id="rtl-maxwidth-resizable-dialog" header-text="Draggable/Resizable dialog" draggable resizable>
446+
<p>Move this dialog around the screen by dragging it by its header.</p>
447+
<p>Resize this dialog by dragging it by its resize handle.</p>
448+
<p>These features are available only on Desktop.</p>
449+
<ui5-toolbar slot="footer">
450+
<ui5-toolbar-button id="rtl-maxwidth-resizable-close" design="Emphasized" text="OK"></ui5-toolbar-button>
451+
</ui5-toolbar>
452+
</ui5-dialog>
453+
</div>
454+
427455
<ui5-popover header-text="My Heading" id="pop" class="dialog8auto" placement="Top">
428456
<!-- <div slot="header">
429457
Hello World
@@ -953,6 +981,10 @@
953981
window["resizable-custom-header-close"].addEventListener("click", function () { window["resizable-dialog-custom-header"].open = false; });
954982
window["draggable-and-resizable-open"].addEventListener("click", function () { window["draggable-and-resizable-dialog"].open = true; });
955983
window["draggable-and-resizable-close"].addEventListener("click", function () { window["draggable-and-resizable-dialog"].open = false; });
984+
window["rtl-draggable-and-resizable-open"].addEventListener("click", function () { window["rtl-draggable-and-resizable-dialog"].open = true; });
985+
window["rtl-draggable-and-resizable-close"].addEventListener("click", function () { window["rtl-draggable-and-resizable-dialog"].open = false; });
986+
window["rtl-maxwidth-resizable-open"].addEventListener("click", function () { window["rtl-maxwidth-resizable-dialog"].open = true; });
987+
window["rtl-maxwidth-resizable-close"].addEventListener("click", function () { window["rtl-maxwidth-resizable-dialog"].open = false; });
956988

957989
window["dynamic-open"].addEventListener("click", function () {
958990
var dialog = document.createElement("ui5-dialog"),

0 commit comments

Comments
 (0)