[BUGFIX] Major context menu refinements
With #94891 the close handling of the context menus got reworked as its previous attempt had some glitches. However, the introduced overhaul had another glitch: The context menu should hide once the cursor has left the context menu for at least 500ms. When the cursor is moved within these 500ms, but is still outside the context menu, the timeout is reset because the event handler storing the cursor's position calls the "should I close the menu"-routine which resets all timeouts. This patch replaces the hand-crafted timeout magic with event debouncing, providing basically the same functionality, but in a more reliable way. Doing so allows us to remove some code that became obsolete by now. The `within()` method had a minor flaw where it considered a cursor not being within an element if the cursor position was at the exact right or bottom boundary. The method is now based on `getBoundingClientRect()` which appears to be more stable. Previously, a context menu suddenly could have an offset of 0 causing some glitches where the menus closed unexpectedly. The cursor's position is stored all 50ms, which may lead to timing issues between the debounced event and the last cursor update. To circumvent this, the cursor position is now also updated when the context menu is entered. As additional measurements, the logic when exactly a context menu gets closed is refined: * close if cursor is outside the context menu AND no child menu is visible or available * close parent menu if cursor leaves child menu from any boundary where cursor will not enter its parent menu Resolves: #96105 Related: #94891 Releases: main, 11.5 Change-Id: Ib9c2505480ada166f8497fc69b42fb9ee45f6cc3 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72425 Tested-by:core-ci <typo3@b13.com> Tested-by:
Andreas Fernandez <a.fernandez@scripting-base.de> Reviewed-by:
Andreas Fernandez <a.fernandez@scripting-base.de>
Showing
- Build/Sources/TypeScript/backend/Resources/Public/TypeScript/ContextMenu.ts 60 additions, 78 deletions...Script/backend/Resources/Public/TypeScript/ContextMenu.ts
- typo3/sysext/backend/Resources/Public/JavaScript/ContextMenu.js 1 addition, 1 deletion...sysext/backend/Resources/Public/JavaScript/ContextMenu.js
Please register or sign in to comment