1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 01:16:10 +00:00

fix(ui): pages have a main heading, a skip link and labelled search boxes

An accessibility sweep (axe-core on 22 pages in four themes, and the
keyboard) found:

- No page had an h1: the page heading was an h3, and pages with their
  own heading (sign-in, Computes, errors) kept an empty one. The heading
  is an h1 at the same size; those pages leave the empty one out, and
  Balance has a hidden h1 beside its breadcrumb. Tests check every page,
  an error page and the lock page for one h1 and no empty heading.
- Keyboard users went through the whole menu on every page: a "Skip to
  content" link shows when it has the focus, and brings the content up
  below the sticky navbar. The OTP QR page takes only a signed token from
  its fragment, not the link's #main.
- Tom Select moves a field's label to its own box, leaving the hidden
  select it keeps unnamed (the Tags field of a host, the owner forms'
  user and VM): the label names it too.
- Put in maintenance was yellow text on white (1.6:1), an outline
  secondary button now.
- The pool page's Volumes heading skipped a level.
This commit is contained in:
catborise 2026-11-21 15:00:23 +03:00
parent f7dcdbab31
commit 7196871880
20 changed files with 64 additions and 11 deletions

View file

@ -2,6 +2,7 @@
{% load i18n %}
{% block title %}{% trans "WebVirtCloud" %} - {% trans "Sign-in locked" %}{% endblock title %}
{% block page_header %}{% endblock page_header %}{# the page has its own heading #}
{% block content %}
<div class="row justify-content-center pt-5">

View file

@ -3,6 +3,7 @@
{% load i18n %}
{% block title %}{% trans "WebVirtCloud" %} - {% trans "Sign In with OTP" %}{% endblock title %}
{% block page_header %}{% endblock page_header %}{# the page has its own heading #}
{% block content %}
<div class="row justify-content-center pt-5">

View file

@ -3,6 +3,7 @@
{% load i18n %}
{% block title %}{% trans "WebVirtCloud" %} - {% trans "Sign In" %}{% endblock title %}
{% block page_header %}{% endblock page_header %}{# the page has its own heading #}
{% block content %}
<div class="row justify-content-center pt-5">

View file

@ -49,6 +49,7 @@ class LoginPageTests(TestCase):
response = self.login("right-pass-1")
self.assertEqual(response.status_code, 429)
self.assertTemplateUsed(response, "accounts/lockout.html")
self.assertEqual(response.content.decode().count("<h1"), 1)
self.assertContains(response, "The lock ends within 20 minutes.", status_code=429)
def test_the_notice_is_shown_only_when_set(self):

View file

@ -4,6 +4,7 @@
{% load operations %}
{% load bootstrap_icons %}
{% block title %}{% trans "Balance" %}{% endblock %}
{% block page_header %}{% endblock page_header %}{# the page has its own heading #}
{% block content %}
<nav aria-label="breadcrumb">
@ -12,6 +13,7 @@
<li class="breadcrumb-item active fw-bold" aria-current="page">{% trans "Balance" %}</li>
</ol>
</nav>
<h1 class="visually-hidden">{% trans "Balance" %}</h1>
<p class="text-body-secondary">{% trans "Migrations that give each host about the same share of its memory, then of its CPUs, for its running VMs: a host twice as large takes twice as much." %}</p>
{% if unreachable %}
<div class="alert alert-warning shadow-sm">{% trans "These hosts cannot be read and are left out:" %} {{ unreachable|join:", " }}</div>

View file

@ -4,6 +4,7 @@
{% load bootstrap_icons %}
{% load operations %}
{% block title %}{% trans "Computes" %}{% endblock %}
{% block page_header %}{% endblock page_header %}{# the page has its own heading #}
{% block content %}
<div id="job-panel" aria-live="polite"></div>
<div class="row">
@ -11,7 +12,7 @@
{% include 'create_comp_block.html' %}
{% if computes|length > 1 %}<a href="{% url 'balance' %}" class="btn btn-outline-primary mt-1 ms-1 float-end">{% trans "Balance" %}</a>{% endif %}
{% include 'search_block.html' %}
<h3 class="mb-3">{% trans "Computes" %}</h3>
<h1 class="h3 mb-3">{% trans "Computes" %}</h1>
</div>
</div>
{% include "computes/attention.html" %}

View file

@ -14,11 +14,11 @@
</form>
{% elif given.active %}
{# its VMs are migrated with it: the Bulk Migrate page puts it in maintenance, with or without moving them #}
<a class="btn btn-sm btn-outline-warning" href="{% url 'bulk_migrate' compute.id %}?maintenance=on">{% bs_icon 'wrench-adjustable' %} {% trans "Put in maintenance" %}</a>
<a class="btn btn-sm btn-outline-secondary" href="{% url 'bulk_migrate' compute.id %}?maintenance=on">{% bs_icon 'wrench-adjustable' %} {% trans "Put in maintenance" %}</a>
{% else %}
<form method="post" action="{% url 'compute_maintenance' compute.id %}" class="d-inline">{% csrf_token %}
<input type="hidden" name="maintenance" value="on">
<button type="submit" class="btn btn-sm btn-outline-warning" data-confirm="{% trans "Put the host in maintenance? No new VM or migration comes to it, its VMs cannot be started there, and Balance leaves it out." %}">{% bs_icon 'wrench-adjustable' %} {% trans "Put in maintenance" %}</button>
<button type="submit" class="btn btn-sm btn-outline-secondary" data-confirm="{% trans "Put the host in maintenance? No new VM or migration comes to it, its VMs cannot be started there, and Balance leaves it out." %}">{% bs_icon 'wrench-adjustable' %} {% trans "Put in maintenance" %}</button>
</form>
{% endif %}
<a class="btn btn-sm btn-outline-primary" href="{% url 'compute_update' compute.id %}">{% bs_icon 'pencil' %} {% trans "Edit connection" %}</a>

Binary file not shown.

View file

@ -13080,3 +13080,7 @@ msgstr[1] "%(failure_count)d başarısız deneme nedeniyle doğrulama geçici ol
msgid "Verification of the token is currently disabled"
msgstr "Kod doğrulaması şu anda kapalı"
#: templates/base.html:35
msgid "Skip to content"
msgstr "İçeriğe atla"

Binary file not shown.

View file

@ -12251,3 +12251,7 @@ msgstr[0] "由于 %(failure_count)d 次验证失败,验证已暂时停用,
msgid "Verification of the token is currently disabled"
msgstr "当前已停用验证码验证"
#: templates/base.html:35
msgid "Skip to content"
msgstr "跳到内容"

View file

@ -334,3 +334,8 @@ td .tag-more {
width: 0.85em;
height: 0.85em;
}
/* "Skip to content" brings #main up below the sticky navbar, not behind it */
#main {
scroll-margin-top: 5rem;
}

View file

@ -1,7 +1,8 @@
// The mailed OTP link carries its token after "#", which no request sends,
// so it is in no access log: the page posts it to get the QR code.
// so it is in no access log: the page posts it to get the QR code. A signed
// token has a ":"; another fragment (the "Skip to content" link's) is not one.
var otpQrForm = document.getElementById("otp-qr-form");
if (otpQrForm && location.hash.length > 1) {
if (otpQrForm && location.hash.includes(":")) {
otpQrForm.elements.token.value = location.hash.slice(1);
history.replaceState(null, "", location.pathname);
otpQrForm.submit();

View file

@ -1,6 +1,16 @@
// Tom Select moves the field's label to its own box: the hidden <select> it
// keeps is named by that label too, for screen readers that still meet it.
function labelOriginal() {
var label = document.getElementById(this.input.id + "-ts-label");
if (label) {
this.input.setAttribute("aria-labelledby", label.id);
}
}
// A <select data-searchable> of many users or VMs gets a search box (Tom Select).
document.querySelectorAll("select[data-searchable]").forEach(function (select) {
new TomSelect(select, {
onInitialize: labelOriginal,
// the box leaves its focused, taller look at once: else the next tap's
// button moves away under the finger on a phone
onItemAdd: function () { this.blur(); },
@ -19,6 +29,7 @@ function isTagName(input) {
}
document.querySelectorAll("select[data-tags]").forEach(function (select) {
new TomSelect(select, {
onInitialize: labelOriginal,
create: function (input) {
return {value: tagName(input), text: tagName(input)};
},

View file

@ -113,7 +113,7 @@
</div>
{% elif volumes %}
<div class="d-flex flex-wrap align-items-center gap-2 mb-2">
<h5 class="me-auto mb-0">{% trans "Volumes" %}</h5>
<h2 class="h5 me-auto mb-0">{% trans "Volumes" %}</h2>
<input id="filter" class="form-control w-auto" type="search" placeholder="{% trans "Search volumes" %}" aria-label="{% trans "Search volumes" %}">
</div>
{% if users_read %}

View file

@ -30,10 +30,12 @@
<body class="pb-5"{% block body_attrs %}{% endblock %}>
{% if request.user.is_authenticated %}
{# for the keyboard: past the menu, shown when it has the focus #}
<a class="visually-hidden-focusable d-block text-center p-2" href="#main">{% trans "Skip to content" %}</a>
{% include 'navbar.html' %}
{% endif %}
<div role="main" class="container">
<div role="main" id="main" class="container">
{% block page_header %}{# a page with a heading of its own leaves it out #}
<div>
<div>
@ -41,10 +43,10 @@
{% block page_heading_extra %}
{% endblock page_heading_extra %}
</div>
<h3 class="mb-3">
<h1 class="h3 mb-3">
{% block page_heading %}
{% endblock page_heading %}
</h3>
</h1>
</div>
</div>
{% endblock page_header %}

View file

@ -6,7 +6,7 @@
{% block page_header %}
<div class="row justify-content-center">
<div class="col-lg-8"><h3 class="mb-3 text-break">{% trans "Delete" %} {{ object }}</h3></div>
<div class="col-lg-8"><h1 class="h3 mb-3 text-break">{% trans "Delete" %} {{ object }}</h1></div>
</div>
{% endblock page_header %}

View file

@ -11,7 +11,7 @@
{% block page_header %}
<div class="row justify-content-center">
<div class="col-lg-8"><h3 class="mb-3">{{ title }}</h3></div>
<div class="col-lg-8"><h1 class="h3 mb-3">{{ title }}</h1></div>
</div>
{% endblock page_header %}

View file

@ -1,6 +1,7 @@
{% extends "base.html" %}
{% load i18n %}
{% block page_header %}{% endblock page_header %}{# the page has its own heading #}
{% block content %}
<div class="row justify-content-center py-3 py-sm-4">
<div class="col-12 col-lg-10">

View file

@ -72,6 +72,24 @@ class PageTests(TestCase):
with self.subTest(page=name):
self.assertEqual({i: n for i, n in ids.items() if n > 1}, {})
def test_every_page_has_one_main_heading_and_no_empty_one(self):
# screen readers go to a page's h1; an empty heading is read as nothing. Not
# pages of the panel: a tab's fragment, the cloud-init data source, the API docs
parts = {"instances:host_devices", "ds_openstack_index", "schema-redoc", "schema-swagger-ui"}
for name, page in self.pages():
if name in parts:
continue
headings = page.xpath("//h1|//h2|//h3|//h4|//h5|//h6")
with self.subTest(page=name):
self.assertEqual(len(page.xpath("//h1")), 1)
# a dialog title is filled in when the dialog opens
self.assertEqual([h.tag for h in headings if not h.text_content().strip() and "modal-title" not in h.get("class", "")], [])
def test_an_error_page_has_one_main_heading(self):
self.client.force_login(get_user_model().objects.create_superuser("err", "err@example.com", "pw"))
page = html.fromstring(self.client.get("/no-such-page/").content)
self.assertEqual([h.text_content().strip() != "" for h in page.xpath("//h1")], [True])
def test_every_table_scrolls_in_its_own_box(self):
# a wide table scrolls inside .table-responsive instead of widening the page on a phone
for name, page in self.pages():