From: Alexander Ebert Date: Wed, 3 May 2023 08:50:29 +0000 (+0200) Subject: Fix the tooltip position and alignment of the date picker X-Git-Tag: 6.0.0_Alpha_1~171 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e13ead9bb28b56c7b2f72cdee4f4424d8d955de3;p=GitHub%2FWoltLab%2FWCF.git Fix the tooltip position and alignment of the date picker Fixes #5214 --- diff --git a/ts/WoltLabSuite/Core/Date/Picker.ts b/ts/WoltLabSuite/Core/Date/Picker.ts index 1c833e1545..0b0121023c 100644 --- a/ts/WoltLabSuite/Core/Date/Picker.ts +++ b/ts/WoltLabSuite/Core/Date/Picker.ts @@ -14,11 +14,13 @@ import * as Language from "../Language"; import * as UiAlignment from "../Ui/Alignment"; import UiCloseOverlay from "../Ui/CloseOverlay"; import DomUtil from "../Dom/Util"; +import { getPageOverlayContainer } from "../Helper/PageOverlay"; import { createFocusTrap, FocusTrap } from "focus-trap"; let _didInit = false; let _firstDayOfWeek = 0; let _focusTrap: FocusTrap; +let _updatePosition: (() => void) | undefined = undefined; const _data = new Map(); let _input: HTMLInputElement | null = null; @@ -186,7 +188,7 @@ function createPicker() { _dateTime.appendChild(_dateMinute); - document.body.appendChild(_datePicker); + getPageOverlayContainer().appendChild(_datePicker); _focusTrap = createFocusTrap(_datePicker, { allowOutsideClick: true, @@ -323,7 +325,11 @@ function open(event: MouseEvent): void { renderPicker(date.getDate(), date.getMonth(), date.getFullYear()); - UiAlignment.set(_datePicker!, _input); + _updatePosition = () => { + UiAlignment.set(_datePicker!, _input!); + }; + _updatePosition(); + window.addEventListener("scroll", _updatePosition, { passive: true }); _input.nextElementSibling!.setAttribute("aria-expanded", "true"); @@ -347,6 +353,11 @@ function close() { EventHandler.fire("WoltLabSuite/Core/Date/Picker", "close", { element: _input }); + if (typeof _updatePosition !== "undefined") { + window.removeEventListener("scroll", _updatePosition); + _updatePosition = undefined; + } + const sibling = _input!.nextElementSibling as HTMLElement; sibling.setAttribute("aria-expanded", "false"); _input = null; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js index abb83b1974..9f03db6b42 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Date/Picker.js @@ -5,7 +5,7 @@ * @copyright 2001-2019 WoltLab GmbH * @license GNU Lesser General Public License */ -define(["require", "exports", "tslib", "../Core", "./Util", "../Dom/Change/Listener", "../Event/Handler", "../Language", "../Ui/Alignment", "../Ui/CloseOverlay", "../Dom/Util", "focus-trap"], function (require, exports, tslib_1, Core, DateUtil, Listener_1, EventHandler, Language, UiAlignment, CloseOverlay_1, Util_1, focus_trap_1) { +define(["require", "exports", "tslib", "../Core", "./Util", "../Dom/Change/Listener", "../Event/Handler", "../Language", "../Ui/Alignment", "../Ui/CloseOverlay", "../Dom/Util", "../Helper/PageOverlay", "focus-trap"], function (require, exports, tslib_1, Core, DateUtil, Listener_1, EventHandler, Language, UiAlignment, CloseOverlay_1, Util_1, PageOverlay_1, focus_trap_1) { "use strict"; Core = tslib_1.__importStar(Core); DateUtil = tslib_1.__importStar(DateUtil); @@ -18,6 +18,7 @@ define(["require", "exports", "tslib", "../Core", "./Util", "../Dom/Change/Liste let _didInit = false; let _firstDayOfWeek = 0; let _focusTrap; + let _updatePosition = undefined; const _data = new Map(); let _input = null; let _maxDate; @@ -155,7 +156,7 @@ define(["require", "exports", "tslib", "../Core", "./Util", "../Dom/Change/Liste } _dateMinute.innerHTML = tmp; _dateTime.appendChild(_dateMinute); - document.body.appendChild(_datePicker); + (0, PageOverlay_1.getPageOverlayContainer)().appendChild(_datePicker); _focusTrap = (0, focus_trap_1.createFocusTrap)(_datePicker, { allowOutsideClick: true, escapeDeactivates() { @@ -272,7 +273,11 @@ define(["require", "exports", "tslib", "../Core", "./Util", "../Dom/Change/Liste } _datePicker.classList[data.isTimeOnly ? "add" : "remove"]("datePickerTimeOnly"); renderPicker(date.getDate(), date.getMonth(), date.getFullYear()); - UiAlignment.set(_datePicker, _input); + _updatePosition = () => { + UiAlignment.set(_datePicker, _input); + }; + _updatePosition(); + window.addEventListener("scroll", _updatePosition, { passive: true }); _input.nextElementSibling.setAttribute("aria-expanded", "true"); _focusTrap.activate(); } @@ -289,6 +294,10 @@ define(["require", "exports", "tslib", "../Core", "./Util", "../Dom/Change/Liste data.onClose(); } EventHandler.fire("WoltLabSuite/Core/Date/Picker", "close", { element: _input }); + if (typeof _updatePosition !== "undefined") { + window.removeEventListener("scroll", _updatePosition); + _updatePosition = undefined; + } const sibling = _input.nextElementSibling; sibling.setAttribute("aria-expanded", "false"); _input = null;