Skip to content

Commit a7b8bfd

Browse files
committed
fix(catalogue): let a read-only list of tasks show a task's whole text on focus
In a list of tasks that cannot be changed here, a row's box is disabled and cannot take the keyboard's focus. The rule that shows a task's whole text in place on focus could then never apply, and the keyboard reached no row of the list. Where its box is disabled, the row's text takes the focus, and the same rule shows the whole text. The test of the rows now reads the box from the generated row: an enabled checkbox where the list can be changed, a disabled one and a text that takes the focus where it cannot.
1 parent 8066f87 commit a7b8bfd

3 files changed

Lines changed: 26 additions & 14 deletions

File tree

‎app/static/catalogue/catalogue.css‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,8 @@ a.std-need { font-size: .78rem; color: var(--text-dim); text-decoration: underli
474474
.tasks-row .tasks-whole { display: none; flex: 1 1 100%; white-space: pre-wrap; line-height: 1.45; }
475475
.tasks-table .tasks-id { display: none; flex: none; margin: 0; }
476476
.tasks-table tr:hover .tasks-id, .tasks-table tr:focus-within .tasks-id { display: inline; }
477-
/* the row's tooltip shows on hover alone: while its box has the keyboard's focus, the whole text is in place */
477+
/* the row's tooltip shows on hover alone: while its box, or its text where the box is disabled, has the keyboard's
478+
focus, the whole text is in place */
478479
.tasks-table tr:has(:focus-visible) .tasks-row { flex-wrap: wrap; }
479480
.tasks-table tr:has(:focus-visible) .tasks-title { display: none; }
480481
.tasks-table tr:has(:focus-visible) .tasks-whole { display: block; }

‎app/static/catalogue/tasks.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
if ($('tasks-bar-chosen')) $('tasks-bar-chosen').textContent = $('tasks-chosen').textContent;
2626
$('tasks-show').disabled = !chosen.size && !st.showing;
2727
}
28-
// a task on one line: its title cut to the width, the whole text in the row's tooltip and, while its box has the
29-
// keyboard's focus, in place; its id beside it on hover or focus. A click anywhere on the row ticks it.
28+
// a task on one line: its title cut to the width, the whole text in the row's tooltip and, while its box (its text
29+
// where the box is disabled) has the keyboard's focus, in place; its id beside it on hover or focus. A click
30+
// anywhere on the row ticks it.
3031
function row(t) {
3132
const tags = Object.values(t.categories || {}).map(v => `<span class="cat-tag">${esc(v)}</span>`).join(' ');
3233
const whole = t.text || t.title || t.id;
3334
return `<tr data-id="${esc(t.id)}" title="${esc(whole)}"><td class="tasks-tick"><input type="checkbox" aria-label="Choose ${esc(t.id)}"${chosen.has(t.id) ? ' checked' : ''}${writable ? '' : ' disabled'}></td>`
34-
+ `<td class="tasks-text"><span class="tasks-row"><span class="tasks-title">${esc(t.title || t.id)}</span>`
35+
+ `<td class="tasks-text"><span class="tasks-row"${writable ? '' : ' tabindex="0"'}><span class="tasks-title">${esc(t.title || t.id)}</span>`
3536
+ `<span class="tasks-whole">${esc(whole)}</span>${t.title ? `<small class="tasks-id mono faint">${esc(t.id)}</small>` : ''}</span>`
3637
+ `${t.unknown ? '<small class="warn">not in the listing</small>' : ''}`
3738
+ (tags ? `<span class="tasks-tags">${tags}</span>` : '') + `</td><td class="tasks-catcol">${tags}</td></tr>`;

‎app/ui_tests/test_task_set_pages.py‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ def test_the_rows_of_chosen_ids_say_which_the_listing_does_not_hold(self):
208208

209209

210210
class TheTaskRows(unittest.TestCase):
211-
"""A task is one line: its title cut to the width; its whole text in the row's tooltip and, while its box has the
212-
keyboard's focus, in place; its id beside it on hover or focus. A click anywhere on the row ticks it; its box, a
213-
link or a button keeps its own action."""
211+
"""A task is one line: its title cut to the width; its whole text in the row's tooltip and, while its box (its
212+
text in a read-only list, where the box is disabled) has the keyboard's focus, in place; its id beside it on
213+
hover or focus. A click anywhere on the row ticks it; its box, a link or a button keeps its own action."""
214214

215215
def test_a_row_is_one_line_ticked_by_a_click_with_its_whole_text_on_hover_and_its_id_beside_it(self):
216216
node = shutil.which("node")
@@ -227,7 +227,8 @@ def test_a_row_is_one_line_ticked_by_a_click_with_its_whole_text_on_hover_and_it
227227
});
228228
return elements.get(id);
229229
}
230-
element('tasks-page').dataset = {writable: 'true', listing: '/listing', rows: '/rows'};
230+
const writable = process.argv[2] === 'true';
231+
element('tasks-page').dataset = {writable: process.argv[2], listing: '/listing', rows: '/rows'};
231232
const long = 'Open the report and ' + 'make the second table match the first one, '.repeat(6);
232233
const tasks = [{id: 'os__a', title: long.slice(0, 99) + '…', text: long, categories: {}}, {id: 'b', title: '', text: '', categories: {}}];
233234
const request = async () => ({json: async () => ({ok: true, ready: true, total: 2, of: 2, pages: 1, page: 1, categories: {}, described: true, tasks})});
@@ -241,24 +242,33 @@ def test_a_row_is_one_line_ticked_by_a_click_with_its_whole_text_on_hover_and_it
241242
for (let n = 0; n < 20; n++) await Promise.resolve();
242243
const rows = element('tasks-rows').innerHTML;
243244
assert.ok(rows.includes(`<tr data-id="os__a" title="${long}"><td class="tasks-tick">`), rows);
244-
assert.ok(rows.includes(`<span class="tasks-row"><span class="tasks-title">${long.slice(0, 99)}…</span>`), rows);
245+
// the text takes the keyboard's focus only where the box cannot
246+
const text = writable ? '<span class="tasks-row">' : '<span class="tasks-row" tabindex="0">';
247+
assert.ok(rows.includes(`${text}<span class="tasks-title">${long.slice(0, 99)}…</span>`), rows);
245248
assert.ok(rows.includes(`<span class="tasks-whole">${long}</span><small class="tasks-id mono faint">os__a</small></span>`), rows);
246249
// an id alone is its own title, with nothing beside it
247250
assert.ok(rows.includes('<tr data-id="b" title="b">'), rows);
248251
assert.ok(rows.includes('<span class="tasks-title">b</span><span class="tasks-whole">b</span></span>'), rows);
249-
// the row's box clicked, as the browser does: it turns and says so
252+
// the generated row's box, looked up and clicked as the browser does: an enabled checkbox turns and says so
253+
const input = (rows.match(/<tr data-id="os__a"[\s\S]*?<\/tr>/) || [''])[0].match(/<input\b[^>]*>/)?.[0] || '';
254+
const checkbox = /\stype="checkbox"/.test(input), enabled = checkbox && !/\sdisabled\b/.test(input);
255+
assert.ok(checkbox && enabled === writable, input);
250256
const box = {checked: false, closest: () => ({dataset: {id: 'os__a'}}),
251-
click() { this.checked = !this.checked; element('tasks-rows').listeners.change({target: {closest: () => box}}); }};
252-
const tr = {querySelector: s => s === 'input[type=checkbox]' ? box : null};
257+
click() { if (!enabled) return; this.checked = !this.checked; element('tasks-rows').listeners.change({target: {closest: () => box}}); }};
258+
const tr = {querySelector: s => s === 'input[type=checkbox]' && checkbox ? box : null};
253259
const click = own => element('tasks-rows').listeners.click({target: {closest: s => s === 'input, a, button' ? own : s === 'tr[data-id]' ? tr : null}});
260+
if (!writable) { click(null); assert.equal(box.checked, false); return; } // read-only: a click ticks nothing
254261
click(null); assert.equal(element('tasks-chosen').textContent, '1 chosen');
255262
click({}); assert.equal(element('tasks-chosen').textContent, '1 chosen'); // the box, a link or a button: its own action alone
256263
selected = 'the second table'; click(null); assert.equal(element('tasks-chosen').textContent, '1 chosen'); // words selected
257264
selected = ''; click(null); assert.equal(element('tasks-chosen').textContent, '0 chosen');
258265
})().catch(error => { console.error(error); process.exitCode = 1; });
259266
"""
260-
got = subprocess.run([node, "-e", program, str(script)], stdin=subprocess.DEVNULL, capture_output=True, text=True, timeout=10)
261-
self.assertEqual(got.returncode, 0, got.stderr)
267+
for writable in ("true", "false"):
268+
with self.subTest(writable=writable):
269+
got = subprocess.run([node, "-e", program, str(script), writable], stdin=subprocess.DEVNULL, capture_output=True,
270+
text=True, timeout=10)
271+
self.assertEqual(got.returncode, 0, got.stderr)
262272
css = (Path(__file__).resolve().parents[1] / "static/catalogue/catalogue.css").read_text(encoding="utf-8")
263273
self.assertIn(".tasks-row .tasks-title { flex: 1 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }", css)
264274
self.assertIn(".tasks-table tr:hover .tasks-id, .tasks-table tr:focus-within .tasks-id { display: inline; }", css)

0 commit comments

Comments
 (0)