Skip to content

Commit 3ac02d4

Browse files
pavi41Pavitra Khatri
andauthored
Fixed Date Widget position in rtl (#1442)
Co-authored-by: Pavitra Khatri <pavitrakhatri@pavitras-mbp.corp.adobe.com>
1 parent e185052 commit 3ac02d4

File tree

6 files changed

+25
-8
lines changed

6 files changed

+25
-8
lines changed

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/datepicker/v1/datepicker/clientlibs/site/css/datepickerwidget.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154

155155
.cmp-adaptiveform-datepicker__calendar-icon {
156156
position: absolute;
157-
top: 50%;
157+
top: 41px;
158158
right: 30px;
159159
z-index: 10;
160160
background: url("/etc.clientlibs/core/fd/components/form/datepicker/v1/datepicker/clientlibs/site/resources/calendar.png") no-repeat center center;

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/datepicker/v1/datepicker/clientlibs/site/js/datepickerwidget.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,10 @@ if (typeof window.DatePickerWidget === 'undefined') {
546546
this.#dp.getElementsByClassName("dp-clear")[0].getElementsByTagName(
547547
"a")[0].innerText = this.#options.locale.clearText;
548548
this.#layout(this.#defaultView);
549-
this.#position();
550549
this.#dp.style.display = "flex";
551550
this.#focusedOnLi = false;
552551
DatePickerWidget.#visible = true;
552+
this.#position();
553553
if (this.#options.showCalendarIcon) {
554554
this.#curInstance.$field.setAttribute('readonly', true); // when the datepicker is active, deactivate the field
555555
}
@@ -580,33 +580,39 @@ if (typeof window.DatePickerWidget === 'undefined') {
580580
windowScrollY = window.scrollY,
581581
windowInnerHeight = window.innerHeight,
582582
windowInnerWidth = window.innerWidth,
583+
inputRect = $elem.getBoundingClientRect(),
583584
height = $elem.offsetHeight,
584585
top = this.#getOffset($elem).top + height,
585586
left = this.#getOffset($elem).left,
586587
styles = {"top": (top + "px"), "left": (left + "px")},
587-
diffBottom = top + 333 - windowInnerHeight - windowScrollY, //todo: hard-coded dp height to 333
588+
diffBottom = top + this.#dp.offsetHeight - windowInnerHeight - windowScrollY, //this.#dp.offsetHeight is the widget's height
588589
newLeft,
589590
newTop;
590591
if (diffBottom > 0) {
591592
//can't appear at the bottom
592593
//check top
593-
newTop = top - height - 333 - 20;
594+
newTop = top - height - this.#dp.offsetHeight - 20;
594595
if (newTop < windowScrollY) {
595596
//can't appear at the top as well ... the datePicker pop up overlaps the date field
596597
newTop = top - diffBottom;
597598
}
598599
styles.top = newTop + "px";
599600
}
600-
if (left + 433 > windowScrollX + windowInnerWidth) { //todo: hard-coding width to 433
601+
if (left + this.#dp.offsetWidth > windowScrollX + windowInnerWidth) {
601602
//align with the right edge
602-
newLeft = windowScrollX + windowInnerWidth - 433 - 20;
603+
newLeft = windowScrollX + windowInnerWidth - this.#dp.offsetWidth - 20;
603604
styles.left = newLeft + "px";
604605
}
605606
this.#dp.style.top = styles.top;
606607
this.#dp.style.left = styles.left;
607608
const localeObj = new Intl.Locale(this.#lang);
608609
if(localeObj?.textInfo?.direction == "rtl") {
609-
this.#dp.style.right = styles.left;
610+
let right = windowInnerWidth - (left + inputRect.width); // Calculate right offset
611+
if (right + this.#dp.offsetWidth > windowInnerWidth) { // this.#dp.offsetWidth is the widget's width
612+
// Align with the right edge of the viewport
613+
right = windowScrollX + windowInnerWidth - this.#dp.offsetWidth - 20; // Adjust with a 20px margin
614+
}
615+
this.#dp.style.right = right + "px";
610616
this.#dp.style.left = "unset"
611617
}
612618
return this;

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/textinput/v1/textinput/textinput.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
placeholder="${text.placeHolder}"
4949
autocomplete="${text.autoComplete}"
5050
minlength="${text.minLength}"
51-
maxlength="${text.maxLength}"></textarea>
51+
maxlength="${text.maxLength}"
52+
dir="auto"></textarea>
5253
<input data-sly-test="${!useTextarea}"
5354
title="${text.tooltipVisible ? '' : text.tooltipText}"
5455
class="cmp-adaptiveform-textinput__widget"
-1.01 KB
Loading
77.5 KB
Loading

ui.tests/test-module/specs/datepicker/datepicker.runtime.persian.locale.cy.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ describe("Form Runtime with Date Picker", () => {
4949
});
5050
});
5151

52+
it("snapshot testing for rtl", () => {
53+
const [datePicker8, datePicker8FieldView] = Object.entries(formContainer._fields)[8];
54+
cy.get(`#${datePicker8}`).find(".cmp-adaptiveform-datepicker__calendar-icon").should("be.visible").click();
55+
cy.get('body').toMatchImageSnapshot({
56+
imageConfig: {
57+
threshold: 0,
58+
},
59+
});
60+
});
61+
5262

5363

5464

0 commit comments

Comments
 (0)