From 120d5af098fab04794ab4f3a36a287e708bcd569 Mon Sep 17 00:00:00 2001 From: Mateusz Sobiecki Date: Fri, 28 May 2021 14:53:40 +0200 Subject: [PATCH] Prop for auto-placement of items list --- src/components/VueBootstrapTypeahead.vue | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/VueBootstrapTypeahead.vue b/src/components/VueBootstrapTypeahead.vue index e172442..42219c6 100644 --- a/src/components/VueBootstrapTypeahead.vue +++ b/src/components/VueBootstrapTypeahead.vue @@ -94,7 +94,11 @@ export default { }, placeholder: String, prepend: String, - append: String + append: String, + autoEstimatePlace: { + type: Boolean, + default: false + }, }, computed: { @@ -120,6 +124,15 @@ export default { resizeList(el) { const rect = el.getBoundingClientRect() const listStyle = this.$refs.list.$el.style + + if(this.autoEstimatePlace) { + const firstHalfOfScreen = rect.y < (screen.availHeight / 2); + if (!firstHalfOfScreen) { + listStyle.top = this.$refs.list.$el.offsetHeight * (-1) + 'px'; + } else { + listStyle.top = ""; + } + } // Set the width of the list on resize listStyle.width = rect.width + 'px'