From 0e3cd1deb077b0727cb280855c1d1c01b8ac58d1 Mon Sep 17 00:00:00 2001 From: Harenome Ranaivoarivony-Razanajato Date: Tue, 24 Nov 2026 14:41:38 +0100 Subject: [PATCH] fix(compare): open the run list under its button, inside the window The table toolkit's menu() cleared every menu's inline left and right on each click, so the run list lost the left Compare had just given it and opened at the window's edge. menu() now undoes only its own rightward flip. Compare places the list above its button when there is more room there, and keeps its height to the room left. --- app/static/compare/columns.js | 7 +++++-- app/static/tables.js | 8 +++++--- app/ui_tests/test_compare_columns.py | 14 +++++++++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/static/compare/columns.js b/app/static/compare/columns.js index 9da1d751..71a1f146 100644 --- a/app/static/compare/columns.js +++ b/app/static/compare/columns.js @@ -90,10 +90,13 @@ window.NulliusCompare = { }); list.addEventListener('click', e => { const o = e.target.closest('[role="option"]'); if (o && o.getAttribute('aria-disabled') !== 'true') pick(o); }); // fixed under its button (the table's scroll box would clip it), placed before it opens and takes the focus, - // so the focus never scrolls the table + // so the focus never scrolls the table; above it when there is more room there, its height kept to the room const place = () => { const b = btn.getBoundingClientRect(), w = Math.min(Math.max(b.width, 320), innerWidth - 16); - Object.assign(menu.style, {top: `${b.bottom + 4}px`, left: `${Math.max(8, Math.min(b.left, innerWidth - w - 8))}px`, width: `${w}px`}); + const below = innerHeight - b.bottom - 12, above = b.top - 12, up = above > below; + Object.assign(menu.style, {top: up ? 'auto' : `${b.bottom + 4}px`, bottom: up ? `${innerHeight - b.top + 4}px` : 'auto', + maxHeight: `${Math.max(up ? above : below, 0)}px`, + left: `${Math.max(8, Math.min(b.left, innerWidth - w - 8))}px`, width: `${w}px`}); }; btn.addEventListener('click', place); NulliusTable.menu(btn, menu); diff --git a/app/static/tables.js b/app/static/tables.js index fa09f614..87efc4ff 100644 --- a/app/static/tables.js +++ b/app/static/tables.js @@ -134,13 +134,15 @@ window.NulliusTable = { const close = () => { menu.hidden = true; btn.setAttribute('aria-expanded', 'false'); }; // a modal over the page (the first-visit guide) takes the focus and the clicks without closing the menu under it const away = to => !menu.contains(to) && !btn.contains(to) && !to.closest?.('[aria-modal="true"]'); + let flipped = false; btn.addEventListener('click', () => { const open = menu.hidden; menu.hidden = !open; btn.setAttribute('aria-expanded', String(open)); - // one that opens leftwards past the page's edge (a narrow screen) opens rightwards instead - menu.style.left = menu.style.right = ''; - if (open && menu.getBoundingClientRect().left < 0) Object.assign(menu.style, {left: '0', right: 'auto'}); + // one that opens leftwards past the page's edge (a narrow screen) opens rightwards instead; + // only that flip is undone, so a position its caller set is kept + if (flipped) { menu.style.left = menu.style.right = ''; flipped = false; } + if (open && menu.getBoundingClientRect().left < 0) { Object.assign(menu.style, {left: '0', right: 'auto'}); flipped = true; } if (open) menu.querySelector('input:not(:disabled), button, a[href]')?.focus(); }); document.addEventListener('click', e => { if (!menu.hidden && away(e.target)) close(); }); diff --git a/app/ui_tests/test_compare_columns.py b/app/ui_tests/test_compare_columns.py index a2db6fc2..9a3abd09 100644 --- a/app/ui_tests/test_compare_columns.py +++ b/app/ui_tests/test_compare_columns.py @@ -10,7 +10,7 @@ SETUP = r''' require(process.argv[2]); document.createElement = tag => new El(tag); -global.innerWidth = 1280; +global.innerWidth = 1280; global.innerHeight = 800; global.addEventListener = () => {}; global.location = {get href() { return 'http://nullius/compare?pick=a:r1&pick=b:&cohort=matched'; }, set href(url) { this.went = url; }}; const replaced = [], fetched = []; @@ -125,6 +125,18 @@ def test_a_run_another_column_shows_is_greyed_and_cannot_be_picked(self): self.assertEqual(got["searched"], ["Already in column 1"]) # search still finds it self.assertIsNone(got["entered"]) # and Enter does nothing + def test_the_opened_list_keeps_its_place_by_its_button_inside_the_window(self): + got = node(r''' +global.scrollY = 0; +const [th] = page([column(0, '', 'a')], {values: ['a:'], lists: {a: {runs: RUNS, same: 0}}, dataset: '', runs: '/compare/runs'}); +const btn = th.querySelector('[data-run-btn]'), list = th.querySelector('[data-run-menu]'); +const at = y => { Object.assign(btn, {y, height: 30, width: 200}); btn.click(); const {left, top, bottom, maxHeight} = list.style; btn.click(); return {left, top, bottom, maxHeight}; }; +process.stdout.write(JSON.stringify({high: at(300), low: at(700)})); +''') + # the menu toolkit leaves the place Compare gave it: under its button with room below, above it near the bottom + self.assertEqual(got["high"], {"left": "8px", "top": "334px", "bottom": "auto", "maxHeight": "458px"}) + self.assertEqual(got["low"], {"left": "8px", "top": "auto", "bottom": "104px", "maxHeight": "688px"}) + def test_a_modal_over_the_page_leaves_the_opened_list_open(self): got = node(r''' const [th] = page([column(0, '', 'a')], {values: ['a:'], lists: {a: {runs: RUNS, same: 0}}, dataset: '', runs: '/compare/runs'});