mirror of
https://github.com/discourse/discourse.git
synced 2025-02-16 18:24:52 -06:00
FIX: better left/right positioning in select-kit components (#6824)
This commit is contained in:
parent
0f09cb50e9
commit
7b15b87cf5
@ -192,29 +192,43 @@ export default Ember.Mixin.create({
|
|||||||
: windowWidth;
|
: windowWidth;
|
||||||
const bodyWidth = this._computedStyle(this.$body()[0], "width");
|
const bodyWidth = this._computedStyle(this.$body()[0], "width");
|
||||||
|
|
||||||
let marginToEdge;
|
let spaceToLeftEdge;
|
||||||
if (this.$scrollableParent().length) {
|
if (this.$scrollableParent().length) {
|
||||||
marginToEdge =
|
spaceToLeftEdge =
|
||||||
this.$().offset().left - this.$scrollableParent().offset().left;
|
this.$().offset().left - this.$scrollableParent().offset().left;
|
||||||
} else {
|
} else {
|
||||||
marginToEdge = this.get("element").getBoundingClientRect().left;
|
spaceToLeftEdge = this.get("element").getBoundingClientRect().left;
|
||||||
}
|
}
|
||||||
|
|
||||||
const enoughMarginToOppositeEdge =
|
let isLeftAligned = true;
|
||||||
parentWidth - marginToEdge - bodyWidth + this.get("horizontalOffset") >
|
const spaceToRightEdge = parentWidth - spaceToLeftEdge;
|
||||||
0;
|
const elementWidth = this.get("element").getBoundingClientRect().width;
|
||||||
if (enoughMarginToOppositeEdge) {
|
if (spaceToRightEdge > spaceToLeftEdge + elementWidth) {
|
||||||
|
isLeftAligned = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLeftAligned) {
|
||||||
this.$()
|
this.$()
|
||||||
.addClass("is-left-aligned")
|
.addClass("is-left-aligned")
|
||||||
.removeClass("is-right-aligned");
|
.removeClass("is-right-aligned");
|
||||||
options.left = this.get("horizontalOffset");
|
|
||||||
options.right = "unset";
|
if (this._isRTL()) {
|
||||||
|
options.right = this.get("horizontalOffset");
|
||||||
|
} else {
|
||||||
|
options.left =
|
||||||
|
-bodyWidth + elementWidth - this.get("horizontalOffset");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.$()
|
this.$()
|
||||||
.addClass("is-right-aligned")
|
.addClass("is-right-aligned")
|
||||||
.removeClass("is-left-aligned");
|
.removeClass("is-left-aligned");
|
||||||
options.left = "unset";
|
|
||||||
options.right = this.get("horizontalOffset");
|
if (this._isRTL()) {
|
||||||
|
options.right =
|
||||||
|
-bodyWidth + elementWidth - this.get("horizontalOffset");
|
||||||
|
} else {
|
||||||
|
options.left = this.get("horizontalOffset");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user