Skip to content

Commit

Permalink
Fix separate dial code padding calc on right for RTL
Browse files Browse the repository at this point in the history
  • Loading branch information
pacotole authored and jackocnr committed Jul 6, 2023
1 parent f3327f1 commit 501153c
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 8 deletions.
4 changes: 4 additions & 0 deletions build/css/intlTelInput.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@
.iti--separate-dial-code.iti--show-flags .iti__selected-dial-code {
margin-left: 6px;
}
[dir=rtl] .iti--separate-dial-code.iti--show-flags .iti__selected-dial-code {
margin-left: 0;
margin-right: 6px;
}
.iti--container {
position: absolute;
top: -1000px;
Expand Down
2 changes: 1 addition & 1 deletion build/css/intlTelInput.min.css

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion build/js/intlTelInput-jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@
this.options.dropdownContainer = document.body;
}
}
// check if input has one parent with RTL
this.isRTL = !!this.telInput.closest("[dir=rtl]");
// these promises get resolved when their individual requests complete
// this way the dev can do something like iti.promise.then(...) to know when all requests are
// complete
Expand Down Expand Up @@ -1096,7 +1098,11 @@
// offsetWidth is zero if input is in a hidden container during initialisation
var selectedFlagWidth = this.selectedFlag.offsetWidth || this._getHiddenSelectedFlagWidth();
// add 6px of padding after the grey selected-dial-code box, as this is what we use in the css
this.telInput.style.paddingLeft = "".concat(selectedFlagWidth + 6, "px");
if (this.isRTL) {
this.telInput.style.paddingRight = "".concat(selectedFlagWidth + 6, "px");
} else {
this.telInput.style.paddingLeft = "".concat(selectedFlagWidth + 6, "px");
}
}
// and the input's placeholder
this._updatePlaceholder();
Expand Down
4 changes: 2 additions & 2 deletions build/js/intlTelInput-jquery.min.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion build/js/intlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@
this.options.dropdownContainer = document.body;
}
}
// check if input has one parent with RTL
this.isRTL = !!this.telInput.closest("[dir=rtl]");
// these promises get resolved when their individual requests complete
// this way the dev can do something like iti.promise.then(...) to know when all requests are
// complete
Expand Down Expand Up @@ -1091,7 +1093,11 @@
// offsetWidth is zero if input is in a hidden container during initialisation
var selectedFlagWidth = this.selectedFlag.offsetWidth || this._getHiddenSelectedFlagWidth();
// add 6px of padding after the grey selected-dial-code box, as this is what we use in the css
this.telInput.style.paddingLeft = "".concat(selectedFlagWidth + 6, "px");
if (this.isRTL) {
this.telInput.style.paddingRight = "".concat(selectedFlagWidth + 6, "px");
} else {
this.telInput.style.paddingLeft = "".concat(selectedFlagWidth + 6, "px");
}
}
// and the input's placeholder
this._updatePlaceholder();
Expand Down
4 changes: 2 additions & 2 deletions build/js/intlTelInput.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/css/intlTelInput.scss
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ $mobilePopupMargin: 30px !default;
}
&.iti--show-flags .iti__selected-dial-code {
margin-left: $arrowPadding;

[dir="rtl"] & {
margin-left: 0;
margin-right: $arrowPadding;
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/js/intlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ class Iti {
}
}

// check if input has one parent with RTL
this.isRTL = !!this.telInput.closest('[dir=rtl]');

// these promises get resolved when their individual requests complete
// this way the dev can do something like iti.promise.then(...) to know when all requests are
// complete
Expand Down Expand Up @@ -1202,7 +1205,11 @@ class Iti {
this.selectedFlag.offsetWidth || this._getHiddenSelectedFlagWidth();

// add 6px of padding after the grey selected-dial-code box, as this is what we use in the css
this.telInput.style.paddingLeft = `${selectedFlagWidth + 6}px`;
if (this.isRTL) {
this.telInput.style.paddingRight = `${selectedFlagWidth + 6}px`;
} else {
this.telInput.style.paddingLeft = `${selectedFlagWidth + 6}px`;
}
}

// and the input's placeholder
Expand Down

0 comments on commit 501153c

Please sign in to comment.