Skip to content

Commit 974c851

Browse files
pdanpdanrstoenescu
authored andcommitted
feat(position-engine): Some tweaks to setPosition (quasarframework#6245)
1 parent db0875b commit 974c851

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

ui/src/css/core/positioning.sass

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,6 @@
9696
/* internal: */
9797
.q-position-engine
9898
margin-top: var(--q-pe-top, 0) !important
99-
margin-left: var(--q-pe-left, 0) !important
99+
margin-left: var(--q-pe-left, 0) !important
100+
will-change: auto
101+
visibility: collapse // needed for animation - is removed on first positioning

ui/src/css/core/positioning.styl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,6 @@
9696
/* internal: */
9797
.q-position-engine
9898
margin-top: var(--q-pe-top, 0) !important
99-
margin-left: var(--q-pe-left, 0) !important
99+
margin-left: var(--q-pe-left, 0) !important
100+
will-change: auto
101+
visibility: collapse // needed for animation - is removed on first positioning

ui/src/utils/position-engine.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,10 @@ export function setPosition (cfg) {
9595
let anchorProps
9696

9797
// scroll position might change
98-
// if max-height changes, so we
98+
// if max-height/-width changes, so we
9999
// need to restore it after we calculate
100100
// the new positioning
101-
const scrollTop = cfg.el.scrollTop
102-
103-
cfg.el.style.maxHeight = cfg.maxHeight
104-
cfg.el.style.maxWidth = cfg.maxWidth
101+
const { scrollLeft, scrollTop } = cfg.el
105102

106103
if (cfg.absoluteOffset === void 0) {
107104
anchorProps = getAnchorProps(cfg.anchorEl, cfg.cover === true ? [0, 0] : cfg.offset)
@@ -115,13 +112,21 @@ export function setPosition (cfg) {
115112
anchorProps = { top, left, width: 1, height: 1, right: left + 1, center: top, middle: left, bottom: top + 1 }
116113
}
117114

115+
let elStyle = {
116+
maxHeight: cfg.maxHeight,
117+
maxWidth: cfg.maxWidth,
118+
visibility: 'visible'
119+
}
120+
118121
if (cfg.fit === true || cfg.cover === true) {
119-
cfg.el.style.minWidth = anchorProps.width + 'px'
122+
elStyle.minWidth = anchorProps.width + 'px'
120123
if (cfg.cover === true) {
121-
cfg.el.style.minHeight = anchorProps.height + 'px'
124+
elStyle.minHeight = anchorProps.height + 'px'
122125
}
123126
}
124127

128+
Object.assign(cfg.el.style, elStyle)
129+
125130
const
126131
targetProps = getTargetProps(cfg.el),
127132
props = {
@@ -131,20 +136,27 @@ export function setPosition (cfg) {
131136

132137
applyBoundaries(props, anchorProps, targetProps, cfg.anchorOrigin, cfg.selfOrigin)
133138

134-
cfg.el.style.top = Math.max(0, Math.floor(props.top)) + 'px'
135-
cfg.el.style.left = Math.max(0, Math.floor(props.left)) + 'px'
139+
elStyle = {
140+
top: Math.max(0, Math.floor(props.top)) + 'px',
141+
left: Math.max(0, Math.floor(props.left)) + 'px'
142+
}
136143

137144
if (props.maxHeight !== void 0) {
138-
cfg.el.style.maxHeight = Math.floor(props.maxHeight) + 'px'
145+
elStyle.maxHeight = Math.floor(props.maxHeight) + 'px'
139146
}
140147
if (props.maxWidth !== void 0) {
141-
cfg.el.style.maxWidth = Math.floor(props.maxWidth) + 'px'
148+
elStyle.maxWidth = Math.floor(props.maxWidth) + 'px'
142149
}
143150

151+
Object.assign(cfg.el.style, elStyle)
152+
144153
// restore scroll position
145154
if (cfg.el.scrollTop !== scrollTop) {
146155
cfg.el.scrollTop = scrollTop
147156
}
157+
if (cfg.el.scrollLeft !== scrollLeft) {
158+
cfg.el.scrollLeft = scrollLeft
159+
}
148160
}
149161

150162
function applyBoundaries (props, anchorProps, targetProps, anchorOrigin, selfOrigin) {

0 commit comments

Comments
 (0)