From b63579b81cbe1a70d3962eb17287a74579cd41a5 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 12 Nov 2023 17:20:12 +0100 Subject: [PATCH] [UI] Fixed some glitches of the Dropdown component. --- .../src/components/elements/Dropdown.vue | 54 +++++++++++-------- .../src/components/elements/DropdownBody.vue | 2 +- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/platypush/backend/http/webapp/src/components/elements/Dropdown.vue b/platypush/backend/http/webapp/src/components/elements/Dropdown.vue index 0b42c6799..e71402c36 100644 --- a/platypush/backend/http/webapp/src/components/elements/Dropdown.vue +++ b/platypush/backend/http/webapp/src/components/elements/Dropdown.vue @@ -6,7 +6,7 @@ @@ -50,22 +50,6 @@ export default { }, computed: { - dropdownWidth() { - const dropdown = this.$refs.dropdown?.$el - if (!dropdown) - return 0 - - return parseFloat(getComputedStyle(dropdown).width) - }, - - dropdownHeight() { - const dropdown = this.$refs.dropdown?.$el - if (!dropdown) - return 0 - - return parseFloat(getComputedStyle(dropdown).height) - }, - buttonStyle() { if (!this.$refs.button) return {} @@ -98,6 +82,27 @@ export default { this.close() }, + getDropdownWidth() { + const dropdown = this.$refs.dropdown?.$el + if (!dropdown) + return 0 + + return parseFloat(getComputedStyle(dropdown).width) + }, + + getDropdownHeight() { + const dropdown = this.$refs.dropdown?.$el + if (!dropdown) + return 0 + + return parseFloat(getComputedStyle(dropdown).height) + }, + + onClick() { + if (!this.keepOpenOnItemClick) + this.close() + }, + close() { this.visible = false document.removeEventListener('click', this.documentClickHndl) @@ -106,6 +111,10 @@ export default { open() { document.addEventListener('click', this.documentClickHndl) + const element = this.$refs.dropdown?.$el + if (!element.parentElement) + this.$el.appendChild(element) + this.visible = true this.$refs.dropdownContainer.classList.remove('hidden') this.$nextTick(() => { @@ -120,12 +129,15 @@ export default { top: buttonPos.top + this.buttonHeight, } - if ((pos.left + this.dropdownWidth) > (window.innerWidth + window.scrollX) / 2) { - pos.left -= (this.dropdownWidth - this.buttonWidth) + const dropdownWidth = this.getDropdownWidth() + const dropdownHeight = this.getDropdownHeight() + + if ((pos.left + dropdownWidth) > (window.innerWidth + window.scrollX) / 2) { + pos.left -= (dropdownWidth - this.buttonWidth) } - if ((pos.top + this.dropdownHeight) > (window.innerHeight + window.scrollY) / 2) { - pos.top -= (this.dropdownHeight + this.buttonHeight - 10) + if ((pos.top + dropdownHeight) > (window.innerHeight + window.scrollY) / 2) { + pos.top -= (dropdownHeight + this.buttonHeight - 10) } const element = this.$refs.dropdown.$el diff --git a/platypush/backend/http/webapp/src/components/elements/DropdownBody.vue b/platypush/backend/http/webapp/src/components/elements/DropdownBody.vue index 835c1fcca..ba30e3127 100644 --- a/platypush/backend/http/webapp/src/components/elements/DropdownBody.vue +++ b/platypush/backend/http/webapp/src/components/elements/DropdownBody.vue @@ -1,5 +1,5 @@