Improve _posFixed to make sure content never gets cut off on very small view ports.
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tp/helpers",
|
"name": "@tp/helpers",
|
||||||
"version": "2.6.0",
|
"version": "2.7.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "closest.js",
|
"main": "closest.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
17
position.js
17
position.js
@ -52,6 +52,12 @@ export const Position = function(superClass) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure top never goes below 0
|
||||||
|
if (top < 0) {
|
||||||
|
compTop += Math.abs(top);
|
||||||
|
top = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.halign === 'left') {
|
if (options.halign === 'left') {
|
||||||
left = anchorRect.left;
|
left = anchorRect.left;
|
||||||
}
|
}
|
||||||
@ -74,6 +80,17 @@ export const Position = function(superClass) {
|
|||||||
left = 0;
|
left = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Constrain height to viewport - calculate available height from final top position
|
||||||
|
const availableHeight = window.innerHeight - top;
|
||||||
|
if (elRect.height > availableHeight) {
|
||||||
|
el.style.maxHeight = availableHeight + 'px';
|
||||||
|
el.style.overflowY = 'auto';
|
||||||
|
} else {
|
||||||
|
// Reset max-height if element fits
|
||||||
|
el.style.maxHeight = '';
|
||||||
|
el.style.overflowY = '';
|
||||||
|
}
|
||||||
|
|
||||||
el.style.top = (top - fixTop) + 'px';
|
el.style.top = (top - fixTop) + 'px';
|
||||||
el.style.left = (left - fixLeft) + 'px';
|
el.style.left = (left - fixLeft) + 'px';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user