From ba64830f1c6f66e0898f689d21367f16d7115f84 Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Tue, 3 Nov 2026 11:27:39 +0900 Subject: [PATCH 1/5] Keep wiki toolbar menus from being clipped by the form The menus were positioned inside div.form-field, which has overflow:hidden, so the lower part of the code language menu could not be seen or clicked in forms such as the new issue form. They now have a fixed position and follow the button when the page is scrolled or resized. Co-Authored-By: Claude Opus 5.5 --- app/assets/stylesheets/jstoolbar.css | 2 +- .../controllers/wiki_toolbar_controller.js | 17 +++++++++++------ test/system/wiki_toolbar_test.rb | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/jstoolbar.css b/app/assets/stylesheets/jstoolbar.css index f193828dc..7ec673e9c 100644 --- a/app/assets/stylesheets/jstoolbar.css +++ b/app/assets/stylesheets/jstoolbar.css @@ -112,7 +112,7 @@ } .table-generator, .jstMenu { - position: absolute; + position: fixed; z-index: 100; } diff --git a/app/javascript/controllers/wiki_toolbar_controller.js b/app/javascript/controllers/wiki_toolbar_controller.js index dd3259390..c0ff10886 100644 --- a/app/javascript/controllers/wiki_toolbar_controller.js +++ b/app/javascript/controllers/wiki_toolbar_controller.js @@ -142,6 +142,10 @@ export default class extends Controller { if (!this.menu.contains(event.target) && !currentTarget.contains(event.target)) this.closeMenu() } document.addEventListener('mousedown', this.closeMenuOnOutsideClick) + // The menu has a fixed position so that it is not clipped by the form + this.repositionMenu = () => this.positionMenu(currentTarget) + window.addEventListener('scroll', this.repositionMenu, { capture: true, passive: true }) + window.addEventListener('resize', this.repositionMenu) this.menu.querySelector('button')?.focus() } @@ -149,9 +153,12 @@ export default class extends Controller { if (!this.menu) return document.removeEventListener('mousedown', this.closeMenuOnOutsideClick) + window.removeEventListener('scroll', this.repositionMenu, { capture: true }) + window.removeEventListener('resize', this.repositionMenu) this.menu.remove() this.menu = null this.closeMenuOnOutsideClick = null + this.repositionMenu = null } highlightTable({ target }) { @@ -253,13 +260,11 @@ export default class extends Controller { } positionMenu(button) { - const parent = this.menu.offsetParent || document.documentElement - const parentRect = parent.getBoundingClientRect() + const blockRect = this.element.getBoundingClientRect() const buttonRect = button.getBoundingClientRect() - const left = buttonRect.left - parentRect.left + parent.scrollLeft - const maxLeft = this.element.clientWidth - this.menu.offsetWidth - this.menu.style.left = `${Math.max(0, Math.min(left, maxLeft))}px` - this.menu.style.top = `${buttonRect.bottom - parentRect.top + parent.scrollTop}px` + const maxLeft = blockRect.left + this.element.clientWidth - this.menu.offsetWidth + this.menu.style.left = `${Math.max(blockRect.left, Math.min(buttonRect.left, maxLeft))}px` + this.menu.style.top = `${buttonRect.bottom}px` } encloseSelection(prefix, suffix) { diff --git a/test/system/wiki_toolbar_test.rb b/test/system/wiki_toolbar_test.rb index d81cbeba3..2189ee019 100644 --- a/test/system/wiki_toolbar_test.rb +++ b/test/system/wiki_toolbar_test.rb @@ -227,6 +227,22 @@ class WikiToolbarTest < ApplicationSystemTestCase assert_equal false, overflow end + def test_precode_menu_should_not_be_clipped_by_the_form + log_user('jsmith', 'jsmith') + visit '/projects/ecookbook/issues/new' + + find('button.jstb_precode').click + assert_selector '.jstMenu' + visible = page.evaluate_script(<<~JS) + (() => { + const menu = document.querySelector('.jstMenu') + const rect = menu.getBoundingClientRect() + return menu.contains(document.elementFromPoint(rect.left + rect.width / 2, rect.bottom - 5)) + })() + JS + assert visible + end + private def select_text(id, start, finish) -- 2.55.0