Skip to content

Commit b525513

Browse files
author
Sami Vänttinen
authored
Add support for showing Autocomplete Menu on top (#1866)
Add support for showing Autocomplete Menu on top
1 parent 48eea53 commit b525513

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

keepassxc-browser/content/autocomplete.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ class Autocomplete {
110110
}
111111

112112
this.updateList();
113-
this.updatePosition();
114113
this.container.style.display = 'block';
114+
this.updatePosition();
115115
}
116116

117117
async updateList() {
@@ -273,11 +273,21 @@ class Autocomplete {
273273
const rect = this.input.getBoundingClientRect();
274274
this.container.style.minWidth = Pixels(this.input.offsetWidth);
275275

276+
// Calculate Y offset if menu does not fit to the bottom of the screen -> show it at the top of the input field
277+
const menuRect = this.container.getBoundingClientRect();
278+
const totalHeight = menuRect.height + rect.height;
279+
const menuOffset = (totalHeight + rect.y) > window.self.visualViewport.height ? totalHeight : 0;
280+
if (menuOffset > 0) {
281+
this.container.classList.add('kpxcAutocomplete-container-on-top');
282+
} else {
283+
this.container.classList.remove('kpxcAutocomplete-container-on-top');
284+
}
285+
276286
if (kpxcUI.bodyStyle.position.toLowerCase() === 'relative') {
277-
this.container.style.top = Pixels(rect.top - kpxcUI.bodyRect.top + document.scrollingElement.scrollTop + this.input.offsetHeight);
287+
this.container.style.top = Pixels(rect.top - kpxcUI.bodyRect.top + document.scrollingElement.scrollTop + this.input.offsetHeight - menuOffset);
278288
this.container.style.left = Pixels(rect.left - kpxcUI.bodyRect.left + document.scrollingElement.scrollLeft);
279289
} else {
280-
this.container.style.top = Pixels(rect.top + document.scrollingElement.scrollTop + this.input.offsetHeight);
290+
this.container.style.top = Pixels(rect.top + document.scrollingElement.scrollTop + this.input.offsetHeight - menuOffset);
281291
this.container.style.left = Pixels(rect.left + document.scrollingElement.scrollLeft);
282292
}
283293
}

keepassxc-browser/css/autocomplete.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
overflow: hidden; /* this fixes an issue with the border radius not showing up clearly */
99
}
1010

11+
.kpxcAutocomplete-container-on-top {
12+
border-bottom-right-radius: 0px;
13+
border-bottom-left-radius: 0px;
14+
border-top-right-radius: 4px;
15+
border-top-left-radius: 4px;
16+
}
17+
1118
.kpxcAutocomplete-items {
1219
max-height: 250px;
1320
overflow-y: auto;

0 commit comments

Comments
 (0)