Improve _posFixed to make sure content never gets cut off on very small view ports.

This commit is contained in:
2025-07-05 23:49:12 +02:00
parent e75b7b8efe
commit ab914d8bf2
2 changed files with 18 additions and 1 deletions

View File

@ -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": {

View File

@ -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';