diff --git a/app/static/builder/command-builder.css b/app/static/builder/command-builder.css index 20402b70..6424d72c 100644 --- a/app/static/builder/command-builder.css +++ b/app/static/builder/command-builder.css @@ -278,6 +278,7 @@ #nullius-builder .std-boat-sizes .nb-tile-note { font-size: 13px; line-height: 1.4; } /* the Benchmark and Agent steps' grids: the card toolkit's (catalogue.css), fitted to the form */ #nullius-builder .nb-step { border-radius: 0; margin: 0; } /* catalogue.css has a .nb-step of its own */ +#nullius-builder .st-search-clear:focus-visible { outline-offset: 1px; } /* style.css's ring, inside the search box's own */ #nullius-builder :is(#nb-bench-grid, #nb-agent-grid) { margin-bottom: 20px; } #nullius-builder :is(#nb-bench-grid, #nb-agent-grid) .bench-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 12px; grid-auto-rows: 1fr; } #nullius-builder :is(#nb-bench-grid, #nb-agent-grid) .bench-card { padding: 16px; gap: 10px; } diff --git a/app/static/style.css b/app/static/style.css index de6b267c..d3f123cf 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -397,6 +397,12 @@ button.seg:hover { filter: brightness(1.25); } .st-search input { min-width: 0; width: 100%; padding: 0; border: 0; background: transparent; color: var(--text); font: 13px var(--sans); } .st-search input:focus-visible { outline: none; } .st-search:focus-within { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); } +/* the toolkit's one clear control; the browser's own is hidden */ +.st-search [data-search]::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; } +.st-search-clear { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; margin: -2px -4px -2px 0; padding: 0; border: 0; border-radius: 5px; background: transparent; color: var(--text-faint); cursor: pointer; } +.st-search-clear .ic { width: 14px; height: 14px; } +.st-search-clear:hover { color: var(--text); background: var(--surface); } +.st-search-clear:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; } .menu-wrap { position: relative; } .btn.sm { font-size: .8rem; padding: .42rem .75rem; } .menu { diff --git a/app/static/tables.js b/app/static/tables.js index 53ac9231..fa09f614 100644 --- a/app/static/tables.js +++ b/app/static/tables.js @@ -153,17 +153,22 @@ window.NulliusTable = { /* A controls row's search box and filters (the controls macro), under `tools`; each optional. Search keeps the rows (or cards) whose data-search holds every word of the query, in any order and case; - Escape clears it. A column narrows when it does not show every value; + its clear button, shown while it holds text, or Escape empties it as + typing would and leaves the focus in it. A column narrows when it does not show every value; the Filter button or a dropdown holding such a column is marked .narrowed and counts: the Filter button the columns it narrows, a dropdown the values chosen (after None, 0), or the one chosen by name. Clear filters clears every column. `changed` runs after any of them. Returns passes(row). */ narrow(tools, changed) { const [fbtn, fmenu] = [tools.querySelector('[data-tools-btn="filter"]'), tools.querySelector('[data-tools="filter"]')]; - const q = tools.querySelector('[data-search]'); + const q = tools.querySelector('[data-search]'), x = tools.querySelector('[data-search-clear]'); + const shown = () => { if (x) x.hidden = !q.value; }; + const clear = () => { q.value = ''; q.dispatchEvent(new Event('input', {bubbles: true})); q.focus(); }; if (q) { - q.addEventListener('input', changed); - q.addEventListener('keydown', e => { if (e.key === 'Escape' && q.value) { e.preventDefault(); q.value = ''; changed(); } }); + q.addEventListener('input', () => { shown(); changed(); }); + q.addEventListener('keydown', e => { if (e.key === 'Escape' && q.value) { e.preventDefault(); clear(); } }); + x?.addEventListener('click', clear); + shown(); // a value the browser restored } const found = row => !q || this.matches(row.dataset.search, q.value); const menus = [...(fmenu ? [[fbtn, fmenu, () => 1]] : []), @@ -176,7 +181,7 @@ window.NulliusTable = { count.textContent = sets.length === 1 ? n(sets[0]) : sets.length ? sets.reduce((sum, set) => sum + n(set), 0) : ''; count.hidden = !sets.length; }); - const narrowed = () => { mark(); changed(); }; + const narrowed = () => { mark(); if (q) shown(); changed(); }; // a page that empties the box itself, then filters const f = this.filters(tools, narrowed); mark(); menus.forEach(([btn, menu]) => this.menu(btn, menu)); diff --git a/app/templates/_tables.html b/app/templates/_tables.html index db81311f..1cfe06b7 100644 --- a/app/templates/_tables.html +++ b/app/templates/_tables.html @@ -79,7 +79,7 @@ {% macro controls(id, cols, search='', columns=false, choices={}, only={}, views=none, actions=none, sort=true, layout=none, default='table') %} {%- set by = {'button': [], 'dropdown': [], 'pills': []} %}{% for c in cols if c.key in choices %}{% for f in ([c.filter] if c.filter is string else c.filter or ['button']) %}{% set _ = by[f].append(c) %}{% endfor %}{% endfor %}
- {% if search %}{% endif %} + {% if search %}{% endif %} {% if columns or by.dropdown or by.button or sort or views or actions or layout %}
{{ slot('views', views) }} {% if columns %}{% endif %} diff --git a/app/ui_tests/test_routes.py b/app/ui_tests/test_routes.py index cdfeaeea..793f2fbd 100644 --- a/app/ui_tests/test_routes.py +++ b/app/ui_tests/test_routes.py @@ -146,6 +146,13 @@ def get_ok(self, path, **kwargs): self.assertEqual(response.status_code, 200, path) return response + def test_the_toolkit_search_carries_its_clear_button_hidden(self): + for path in ("/runs", "/benchmarks", "/agents", "/kits", "/workspaces"): + with self.subTest(path=path): + html = self.get_ok(path).get_data(as_text=True) + self.assertIn('', html) + def test_home_opens_runs_with_or_without_active_workspace(self): for active in (self.active, None): with self.subTest(active=bool(active)): diff --git a/app/ui_tests/test_tables.py b/app/ui_tests/test_tables.py index 2fd5a665..c73da20c 100644 --- a/app/ui_tests/test_tables.py +++ b/app/ui_tests/test_tables.py @@ -65,6 +65,7 @@ class El { for (let e = this; e && !ev.stopped; e = e.parentNode) (e.on[type] || []).forEach(f => f(ev)); return ev; } + dispatchEvent(ev) { return this.dispatch(ev.type); } click() { if (this.tagName === 'INPUT' && this.getAttribute('type') === 'checkbox') this.checked = !this.checked; if (this.tagName === 'INPUT' && this.getAttribute('type') === 'radio') { @@ -94,6 +95,7 @@ class El { document.getElementById = id => document.querySelector(`[id="${id}"]`); document.createElement = tag => new El(tag); global.window = global; +global.Event = class { constructor(type) { this.type = type; } }; const on = {}; global.addEventListener = (t, f) => (on[t] ||= []).push(f); global.scrollY = 0; @@ -133,7 +135,7 @@ class El { const radio = (k, v) => el('label', {}, el('input', {type: 'radio', name: `${id}-sort-${k}`, [`data-sort-${k}`]: '', value: v}), ' ' + v); const button = !filter ? [] : typeof filter[0] === 'string' ? [filter] : filter; const tools = el('div', {id: id + '-tools'}, - ...(search ? [el('label', {}, el('input', {type: 'search', 'data-search': ''}))] : []), + ...(search ? [el('label', {}, el('input', {type: 'search', 'data-search': ''}), el('button', {type: 'button', 'data-search-clear': '', hidden: true}))] : []), ...dropdowns.map(c => dropdownOf(c, only)), ...(button.length ? [el('button', {'data-tools-btn': 'filter'}, 'Filter', el('span', {class: 'tools-count', hidden: true})), el('div', {'data-tools': 'filter', hidden: true}, el('button', {'data-clear': ''}), ...button.map(c => fieldOf(c, only)))] : []), @@ -220,6 +222,23 @@ def test_a_screen_reader_hears_a_change_once_typing_pauses(self): self.assertNotIn('role="status"', html) + def test_the_clear_button_empties_the_box_as_typing_would(self): + got = node(LAUNCHES + r''' +const box = t.tools.querySelector('[data-search]'), x = t.tools.querySelector('[data-search-clear]'); +let heard = 0; box.addEventListener('input', () => heard++); // a page's own listener +const out = {start: x.hidden}; +t.type('gamma'); out.typed = [x.hidden, t.note()]; +document.activeElement = null; x.click(); +out.clicked = [box.value, t.note(), x.hidden, document.activeElement === box, heard]; +t.type('delta'); document.activeElement = null; box.dispatch('keydown', {key: 'Escape'}); +out.escaped = [box.value, t.note(), x.hidden, document.activeElement === box, heard]; +process.stdout.write(JSON.stringify(out)); +''') + self.assertEqual(got["start"], True) # hidden while empty + self.assertEqual(got["typed"], [False, "1–15 of 15"]) + self.assertEqual(got["clicked"], ["", "1–25 of 30", True, True, 2]) # every row back, focus in the box + self.assertEqual(got["escaped"], ["", "1–25 of 30", True, True, 4]) + # Thirty rows of a state and a kind; the kind in pills, a dropdown and the Filter menu, the state in the Filter menu. FORMS = r''' const kinds = ['a', 'b', 'c']; @@ -458,7 +477,7 @@ def test_a_controls_row_places_its_slots_around_the_buttons(self): f"{{% call(r, c) table('t', {cols}, [], none, search='Find', columns=true, choices={{'x': [('a', 'A')]}}, views=views, actions=actions) %}}{{% endcall %}}"): with self.subTest(call=call[:12]): html = self.slotted(call) - self.assertEqual(re.findall(r'data-search|data-slot="(\w+)"|data-tools-btn="(\w+)"|', html), + self.assertEqual(re.findall(r'data-search(?!-)|data-slot="(\w+)"|data-tools-btn="(\w+)"|', html), [("", "", ""), ("views", "", ""), ("", "", "v1"), ("", "", "v2"), ("", "columns", ""), ("", "filter", ""), ("", "sort", ""), ("actions", "", ""), ("", "", "a1"), ("", "", "a2")]) self.assertEqual(html.count('class="table-slot"'), 2) # each slot one group, spaced as the buttons