@jskit-ai/material-web 0.1.14 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/package.json +1 -1
- package/src/client/index.js +6 -5
- package/src/client/keyboardRipple.js +47 -0
- package/src/client/material.css +75 -0
- package/test/fixtures/keyboard-ripple/index.html +2 -0
- package/test/fixtures/keyboard-ripple/main.js +47 -0
- package/test/fixtures/keyboard-ripple/vite.config.js +7 -0
- package/test/fixtures/overlay-stacking/index.html +2 -0
- package/test/fixtures/overlay-stacking/main.js +36 -0
- package/test/fixtures/overlay-stacking/vite.config.js +7 -0
- package/test/fixtures/underlay-stacking/index.html +2 -0
- package/test/fixtures/underlay-stacking/main.js +45 -0
- package/test/fixtures/underlay-stacking/vite.config.js +7 -0
- package/test/keyboardRipple.browser.test.js +69 -0
- package/test/overlayStacking.browser.test.js +89 -0
- package/test/underlayStacking.browser.test.js +235 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- axe judges the text of a tonal alert, an alert with a border, an editable stepper step, a tonal snackbar and an expansion panel's title, the title's in each state that shows its state layer. Vuetify draws each one's own layer (the alert's tint and its border box, the step's state layer and underlay, the snackbar's tint, the title's state layer on hover, on keyboard focus and on an open `focusable` panel) as a positioned box after the text it covers, so axe found it over the text and judged none of it (color-contrast incomplete, bgOverlap). material.css draws the alert's, step's and snackbar's layers under the text, as it already did a button's, chip's, list item's, card's and avatar's: each component is a stacking context with its layers at z-index -1 in it, and each part holding its text is one too. A title's text is the title's own, with no part to lift above a layer, so material.css draws its state as the title's own background, the text's colour at the state's opacity, and hides Vuetify's layer; a title with a background of its own (its `color`, a bg- class or an inline background) keeps Vuetify's layer, since no rule can mix a tint into a background another rule sets. The tints are the text's own colour, so the window's pixels are the same but for rounding, two levels of 255 at most. An icon button's text is judged as Vuetify draws it. A circular progress's reading keeps Vuetify's order: its ring is an svg, which axe takes for an image whether it lies over the reading or under it (bgOverlap, imgNode), so it judges the reading neither way. `underlayStacking.browser.test.js` has axe judge each of these texts, the titles' at rest, hovered and focused, finds a title of its own colour judged on its background at rest and under Vuetify's layer when hovered, and finds the same pixels, but for rounding, as with Vuetify's drawing.
|
|
6
|
+
- A keyboard press's ripple ends with the press on a control whose own key handler moves focus away, as mobilynet's map card does: Enter opens a panel and focuses its title. Vuetify's ripple directive hears a key after the control's own listeners, so the card's blur came before its ripple existed, the ripple then showed on a card that no longer held focus, Enter came up on the panel's title, and nothing ended it. It stayed drawn, axe read its whole box, which reaches past the card, as covering mobilynet's label above it (color-contrast incomplete, bgOverlap), and Vuetify's flag that a keyboard ripple is showing stayed set, so the next control pressed with Enter showed none. `createMaterialVuetifyOptions()`, in a browser, now listens on the window once: when a key comes up, each control around where it went down that shows a ripple but no longer holds focus is sent the blur it missed, and Vuetify's own blur listener ends the ripple and clears the flag. A blur listener of the control's own hears that blur too, a second time. `keyboardRipple.browser.test.js` presses Enter on such a card, then on a button.
|
|
7
|
+
- axe judges the texts of a dialog, menu, tooltip or snackbar open over page content that has a z-index of its own. Vuetify places every overlay in a container (`.v-overlay-container`) with `contain: layout` and `display: contents`, which draws no box, so the browser makes no stacking context of it; axe-core 4.14 counts `contain: layout` as one whatever the element draws, ranked the container at the page's base level, and so ranked every overlay under any content with a z-index of 1 or more. Over such content it found the page over a dialog's text and judged none of it (color-contrast incomplete, bgOverlap): mobilynet's dialogs, over its pages' content at z-index 1. axe-core 4.11 read `contain` too, but ranked the container by its position, an entry the overlay's own stacking context took out of the order; 4.14 keeps a stacking context in the order. material.css sets the container's `contain` to none, which the browser draws the same: `overlayStacking.browser.test.js` opens a dialog over a div at z-index 1, has axe judge each of its texts, and finds the same elements under every text (elementsFromPoint) and the same pixels as with Vuetify's `contain: layout`.
|
|
5
8
|
- axe judges every text beside an open menu or a snackbar. Vuetify places a menu's content and a snackbar's message in an overlay the size of the window (or of the container it is attached to), transparent and taking no clicks, and axe found that box over every other text on the page and judged none of them (color-contrast incomplete, bgOverlap): 36 texts on mobilynet's page with a menu open, so text no one could read there passed. material.css hides a menu's and a snackbar's overlay and shows what it holds (`.v-overlay:is(.v-menu, .v-snackbar)`, visibility), so nothing changes on screen, clicks and assistive technology reach the same elements (a snackbar's `role="status"` is on its content), and the content is the only box it lays over the page. Select, autocomplete and combobox lists are menus too. A tooltip keeps its overlay, which carries its `role="tooltip"`. A test that asked whether a snackbar's root (`.v-snackbar`) is visible now asks its message (`.v-snackbar__wrapper`): the root is hidden.
|
|
6
9
|
- An active button whose label is drawn in its colour (filled, elevated, text, outlined) shows one state layer at a time, as Material 3 does: hovered, focused or pressed, that state's layer alone. Vuetify added the hover or focus layer to its activated one, 18% or 20% of a text button's colour under its label, which took a primary text button's label to 4.13:1 under the mouse that had just opened its menu; Vuetify draws a button as active while its menu is open, and a filled or elevated one now has no activated layer then either, as when its route is current. A selected tonal button keeps its selected layer under the others: its on-container label keeps 4.5:1 over both.
|
|
7
10
|
shell-web's `colorContrast.browser.test.js` opens a text button's menu and a filled button's, and shows a snackbar, at 1280 and has axe judge every text on the page, and judges every colour and variant active, at rest, hovered, focused and pressed, in light and dark.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/material-web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Exact Material 3 for JSKIT Vuetify apps: seed-generated light and dark schemes, Material Symbols Rounded icon aliases, Roboto Flex and Material 3 component defaults.",
|
|
6
6
|
"exports": {
|
package/src/client/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { md3 } from "vuetify/blueprints";
|
|
2
2
|
import { materialThemes } from "./colorSchemes.js";
|
|
3
3
|
import { materialDefaults } from "./defaults.js";
|
|
4
|
+
import { endKeyboardRipplesWithThePress } from "./keyboardRipple.js";
|
|
4
5
|
import { materialSymbols } from "./symbols.js";
|
|
5
6
|
|
|
6
7
|
// The default Material 3 seed, the baseline purple of the Material 3 guidelines.
|
|
@@ -45,7 +46,8 @@ function appIconAliases(icons) {
|
|
|
45
46
|
* the app's own colours as harmonized custom colours), following the system's light or dark setting, the brand and
|
|
46
47
|
* plain typefaces (Roboto Flex unless the app names its own), Material Symbols Rounded behind every icon alias (plus
|
|
47
48
|
* the app's own), and JSKIT's Material 3 component defaults. Pass the result to createVuetify(); import
|
|
48
|
-
* "@jskit-ai/material-web/client/material.css" after "vuetify/styles".
|
|
49
|
+
* "@jskit-ai/material-web/client/material.css" after "vuetify/styles". In a browser it also makes a keyboard press's
|
|
50
|
+
* ripple end with the press on a control whose own key handler moves focus away (keyboardRipple.js), once per window.
|
|
49
51
|
* @param {{ seed?: string, colors?: Record<string, string | { value: string, blend?: boolean }>, icons?: Record<string, string>, typography?: { brand?: string, plain?: string } }} [theme]
|
|
50
52
|
*/
|
|
51
53
|
function createMaterialVuetifyOptions({ seed = DEFAULT_SEED, colors = {}, icons = {}, typography = {} } = {}) {
|
|
@@ -54,15 +56,14 @@ function createMaterialVuetifyOptions({ seed = DEFAULT_SEED, colors = {}, icons
|
|
|
54
56
|
for (const theme of Object.values(themes)) {
|
|
55
57
|
theme.variables = { ...theme.variables, ...typefaces };
|
|
56
58
|
}
|
|
59
|
+
const aliases = { ...materialSymbols, ...appIconAliases(icons) };
|
|
60
|
+
endKeyboardRipplesWithThePress(globalThis.window);
|
|
57
61
|
return {
|
|
58
62
|
blueprint: md3,
|
|
59
63
|
defaults: materialDefaults,
|
|
60
64
|
icons: {
|
|
61
65
|
defaultSet: "svg",
|
|
62
|
-
aliases
|
|
63
|
-
...materialSymbols,
|
|
64
|
-
...appIconAliases(icons)
|
|
65
|
-
}
|
|
66
|
+
aliases
|
|
66
67
|
},
|
|
67
68
|
theme: {
|
|
68
69
|
defaultTheme: "system",
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Vuetify's ripple directive adds its key listeners when it mounts, after a control's own, so it hears a key after the
|
|
2
|
+
// control's own handler. When that handler moves focus (Enter on a card that opens a panel and focuses its title), the
|
|
3
|
+
// control's blur, which ends a keyboard ripple, comes before the ripple exists; the directive then shows the ripple on a
|
|
4
|
+
// control that no longer holds focus, the key comes up on the new focus, and nothing ends the ripple. It stays drawn
|
|
5
|
+
// (and axe reads its whole box, which reaches past the control, as covering the text around it), and Vuetify's flag
|
|
6
|
+
// that one keyboard ripple is showing stays set, so the next control pressed shows none until some rippling control
|
|
7
|
+
// blurs. When a key comes up, each control around where it went down that shows a ripple but no longer holds focus is
|
|
8
|
+
// sent the blur it missed: Vuetify's own blur listener ends the ripple and clears the flag. (A blur listener of the
|
|
9
|
+
// control's own hears it a second time; the control has not held focus since the first.)
|
|
10
|
+
const INSTALLED = Symbol.for("@jskit-ai/material-web/keyboard-ripples");
|
|
11
|
+
// A ripple Vuetify shows (--visible from the start) and has not begun to hide, in a control's own ripple container.
|
|
12
|
+
const LIVE_RIPPLE = ":scope > .v-ripple__container > .v-ripple__animation--visible:not([data-is-hiding])";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Ends a keyboard press's ripple when the press ends, on a control whose own key handler moved focus away before
|
|
16
|
+
* Vuetify's ripple heard the key. Listens on `view` once, however often it is called, for as long as the page lives or
|
|
17
|
+
* until the returned function releases it; does nothing without a document.
|
|
18
|
+
* @param {Window | undefined} view
|
|
19
|
+
* @returns {(() => void) | undefined} releases the listeners
|
|
20
|
+
*/
|
|
21
|
+
function endKeyboardRipplesWithThePress(view) {
|
|
22
|
+
if (!view?.document) return undefined;
|
|
23
|
+
if (view[INSTALLED]) return view[INSTALLED];
|
|
24
|
+
// Where each key held down went down. Captured on the window, so a handler that stops the key does not hide it.
|
|
25
|
+
const pressed = new Map();
|
|
26
|
+
function notePress(event) {
|
|
27
|
+
if (!event.repeat) pressed.set(event.key, event.target);
|
|
28
|
+
}
|
|
29
|
+
function endRipplesLeftBehind(event) {
|
|
30
|
+
const origin = pressed.get(event.key);
|
|
31
|
+
pressed.delete(event.key);
|
|
32
|
+
const focused = view.document.activeElement;
|
|
33
|
+
for (let control = origin instanceof view.Element ? origin : null; control; control = control.parentElement) {
|
|
34
|
+
if (!control.contains(focused) && control.querySelector(LIVE_RIPPLE)) control.dispatchEvent(new view.FocusEvent("blur"));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
view.addEventListener("keydown", notePress, true);
|
|
38
|
+
view.addEventListener("keyup", endRipplesLeftBehind, true);
|
|
39
|
+
view[INSTALLED] = function release() {
|
|
40
|
+
view.removeEventListener("keydown", notePress, true);
|
|
41
|
+
view.removeEventListener("keyup", endRipplesLeftBehind, true);
|
|
42
|
+
delete view[INSTALLED];
|
|
43
|
+
};
|
|
44
|
+
return view[INSTALLED];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { endKeyboardRipplesWithThePress };
|
package/src/client/material.css
CHANGED
|
@@ -194,6 +194,70 @@
|
|
|
194
194
|
isolation: isolate;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
/* The same for the other components Vuetify draws a layer of their own over their text in: a tonal alert's tint
|
|
198
|
+
and an alert's border box, an editable stepper step's state layer and underlay, and a tonal snackbar's tint.
|
|
199
|
+
axe found each over its component's text and judged none of it (color-contrast incomplete, bgOverlap). Each tint
|
|
200
|
+
is the text's own colour, so drawing it under the text changes a pixel only by rounding; a border does not reach
|
|
201
|
+
the text. An icon button's text is judged as Vuetify draws it. A circular progress's reading keeps Vuetify's
|
|
202
|
+
order: its ring is an svg, which axe takes for an image whether it lies over the reading or under it
|
|
203
|
+
(bgOverlap, imgNode), so it judges the reading neither way. */
|
|
204
|
+
:is(.v-alert, .v-stepper-item, .v-snackbar__wrapper) {
|
|
205
|
+
isolation: isolate;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.v-alert > :is(.v-alert__underlay, .v-alert__border),
|
|
209
|
+
.v-stepper-item > :is(.v-stepper-item__overlay, .v-stepper-item__underlay),
|
|
210
|
+
.v-snackbar__wrapper > .v-snackbar__underlay {
|
|
211
|
+
z-index: -1;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.v-alert > :is(.v-alert__prepend, .v-alert__content, .v-alert__append, .v-alert__close),
|
|
215
|
+
.v-stepper-item > .v-stepper-item__content,
|
|
216
|
+
.v-snackbar__wrapper > :is(.v-snackbar__prepend, .v-snackbar__content, .v-snackbar__actions) {
|
|
217
|
+
isolation: isolate;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/* An expansion panel title's state, on an open `focusable` panel, on hover, on keyboard focus and on a disabled
|
|
221
|
+
panel, is the title's own background: the text's own colour at the state's opacity, as Vuetify's state layer
|
|
222
|
+
draws it. Vuetify draws the layer, a positioned box, over the title's text, a text of the title's own with no
|
|
223
|
+
part to lift above it, so axe judged none of it (color-contrast incomplete, bgOverlap). A title with a background
|
|
224
|
+
of its own (its `color`, a bg- class or an inline background) keeps Vuetify's layer: no rule can mix a tint into
|
|
225
|
+
a background another rule sets. Every browser JSKIT builds for has :focus-visible, so Vuetify's :focus rules for
|
|
226
|
+
one without it are not repeated. */
|
|
227
|
+
.v-expansion-panel-title:not([class*=" bg-"], [style*="background"]) {
|
|
228
|
+
background-color: color-mix(in srgb, currentColor calc(var(--jskit-panel-title-state, 0) * 100%), transparent);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.v-expansion-panel-title:not([class*=" bg-"], [style*="background"]) > .v-expansion-panel-title__overlay {
|
|
232
|
+
display: none;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.v-expansion-panel--disabled .v-expansion-panel-title {
|
|
236
|
+
--jskit-panel-title-state: 0.4615384615;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
.v-expansion-panel-title--hover:hover {
|
|
240
|
+
--jskit-panel-title-state: calc(var(--v-hover-opacity) * var(--v-theme-overlay-multiplier));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.v-expansion-panel-title--hover:focus-visible {
|
|
244
|
+
--jskit-panel-title-state: calc(var(--v-focus-opacity) * var(--v-theme-overlay-multiplier));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.v-expansion-panel-title--focusable.v-expansion-panel-title--active {
|
|
248
|
+
--jskit-panel-title-state: calc(var(--v-activated-opacity) * var(--v-theme-overlay-multiplier));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.v-expansion-panel-title--focusable.v-expansion-panel-title--active:hover {
|
|
252
|
+
--jskit-panel-title-state: calc((var(--v-activated-opacity) + var(--v-hover-opacity)) *
|
|
253
|
+
var(--v-theme-overlay-multiplier));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.v-expansion-panel-title--focusable.v-expansion-panel-title--active:focus-visible {
|
|
257
|
+
--jskit-panel-title-state: calc((var(--v-activated-opacity) + var(--v-focus-opacity)) *
|
|
258
|
+
var(--v-theme-overlay-multiplier));
|
|
259
|
+
}
|
|
260
|
+
|
|
197
261
|
/* A filled or elevated button has no activated state layer: Material 3 gives these buttons none (a selected
|
|
198
262
|
segment is secondary-container), and Vuetify's, the label's colour at 10% over the container, took a primary
|
|
199
263
|
button's white label under WCAG's 4.5:1 (4.11:1 in JSKIT's fixture theme) for as long as the button stayed
|
|
@@ -430,6 +494,17 @@
|
|
|
430
494
|
visibility: visible;
|
|
431
495
|
}
|
|
432
496
|
|
|
497
|
+
/* An overlay ranks by its own z-index for axe as it does on screen. Vuetify places every dialog, menu, tooltip and
|
|
498
|
+
snackbar in an overlay container with `contain: layout` and `display: contents`: it draws no box, so for the
|
|
499
|
+
browser it contains nothing and makes no stacking context. axe-core 4.14 counts `contain: layout` as a stacking
|
|
500
|
+
context whatever the element draws, so it ranked the container at the page's base level and every overlay in it
|
|
501
|
+
under any of the page's content with a z-index of 1 or more; over such content it found the page over a dialog's
|
|
502
|
+
text and judged none of it (color-contrast incomplete, bgOverlap), on mobilynet's dialogs. The container's
|
|
503
|
+
`contain` is none, which the browser draws the same. */
|
|
504
|
+
.v-overlay-container {
|
|
505
|
+
contain: none;
|
|
506
|
+
}
|
|
507
|
+
|
|
433
508
|
/* Segmented buttons (v-btn-toggle): a 40dp pill in the outline role whose segments share its width, each with a 48dp
|
|
434
509
|
touch target. An unselected segment has no container; the selected one is secondary-container and leads with a
|
|
435
510
|
check, which takes the place of its icon. */
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createApp, h, ref } from "vue";
|
|
2
|
+
import { createVuetify } from "vuetify";
|
|
3
|
+
import { VApp } from "vuetify/components/VApp";
|
|
4
|
+
import { VBtn } from "vuetify/components/VBtn";
|
|
5
|
+
import { VCard, VCardItem, VCardText } from "vuetify/components/VCard";
|
|
6
|
+
import { VMain } from "vuetify/components/VMain";
|
|
7
|
+
import "vuetify/styles";
|
|
8
|
+
import "../../../src/client/material.css";
|
|
9
|
+
import { createMaterialVuetifyOptions } from "../../../src/client/index.js";
|
|
10
|
+
|
|
11
|
+
// A card whose own Enter handler opens a panel and moves focus to its title at once, as mobilynet's map cards did, a
|
|
12
|
+
// control without a ripple that does the same, and a button pressed after them (keyboardRipple.browser.test.js). The
|
|
13
|
+
// handlers are attribute listeners, which Vue adds as it creates each element, before Vuetify's ripple directive adds
|
|
14
|
+
// its own on mounting. globalThis.blurs counts the blur events each control hears.
|
|
15
|
+
globalThis.blurs = { card: 0, plain: 0, title: 0, next: 0 };
|
|
16
|
+
const counted = (name) => () => {
|
|
17
|
+
globalThis.blurs[name] += 1;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const App = {
|
|
21
|
+
setup() {
|
|
22
|
+
const opened = ref(0);
|
|
23
|
+
const title = ref(null);
|
|
24
|
+
const open = (event) => {
|
|
25
|
+
if (event.key !== "Enter") return;
|
|
26
|
+
opened.value += 1;
|
|
27
|
+
title.value.focus();
|
|
28
|
+
};
|
|
29
|
+
return () => h(VApp, () => h(VMain, { class: "pa-6" }, () => [
|
|
30
|
+
h(VCard, {
|
|
31
|
+
link: true, role: "button", tabindex: 0, width: 320, onKeydown: open, onBlur: counted("card"), "data-testid": "card"
|
|
32
|
+
}, () => [
|
|
33
|
+
h(VCardItem, { title: "chat.example.com" }),
|
|
34
|
+
h(VCardText, () => "Serves the chat app")
|
|
35
|
+
]),
|
|
36
|
+
h("div", {
|
|
37
|
+
class: "mt-6", role: "button", tabindex: 0, onKeydown: open, onBlur: counted("plain"), "data-testid": "plain"
|
|
38
|
+
}, "Opens the panel, without a ripple"),
|
|
39
|
+
h("section", { class: "mt-6" }, [
|
|
40
|
+
h("h2", { ref: title, tabindex: -1, onBlur: counted("title"), "data-testid": "panel-title" }, `Opened ${opened.value} times`)
|
|
41
|
+
]),
|
|
42
|
+
h(VBtn, { class: "mt-6", onBlur: counted("next"), "data-testid": "next" }, () => "Next")
|
|
43
|
+
]));
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
createApp(App).use(createVuetify(createMaterialVuetifyOptions())).mount("#app");
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createApp, h } from "vue";
|
|
2
|
+
import { createVuetify } from "vuetify";
|
|
3
|
+
import { VApp } from "vuetify/components/VApp";
|
|
4
|
+
import { VBtn } from "vuetify/components/VBtn";
|
|
5
|
+
import { VCard, VCardActions, VCardText } from "vuetify/components/VCard";
|
|
6
|
+
import { VDialog } from "vuetify/components/VDialog";
|
|
7
|
+
import { VMain } from "vuetify/components/VMain";
|
|
8
|
+
import "vuetify/styles";
|
|
9
|
+
import "../../../src/client/material.css";
|
|
10
|
+
import { createMaterialVuetifyOptions } from "../../../src/client/index.js";
|
|
11
|
+
|
|
12
|
+
// A dialog open over a page whose content has a z-index of its own, with JSKIT's Material 3 options and stylesheet
|
|
13
|
+
// (overlayStacking.browser.test.js), as mobilynet's dialogs open over its pages: behind the dialog, forty lines of text
|
|
14
|
+
// in a bare div at `position: relative; z-index: 1`; in the dialog, a title, a line of text and two buttons, each
|
|
15
|
+
// text one line, so that the only thing axe can find over them is a box it ranks above the dialog.
|
|
16
|
+
const lines = Array.from({ length: 40 }, (_, index) => `Line ${index + 1} of the page behind the dialog, at z-index 1.`);
|
|
17
|
+
|
|
18
|
+
const page = () => h("div", { class: "pa-4" }, [
|
|
19
|
+
h("h1", { class: "text-headline-small mb-2" }, "A page behind a dialog"),
|
|
20
|
+
h("div", { style: "position: relative; z-index: 1", "data-testid": "page-behind" },
|
|
21
|
+
lines.map((line) => h("p", { class: "text-body-large mb-1" }, line)))
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
const dialog = () => h(VDialog, { modelValue: true, persistent: true, maxWidth: 560 }, () => (
|
|
25
|
+
h(VCard, { title: "Edit the name", "data-testid": "dialog-card" }, () => [
|
|
26
|
+
h(VCardText, null, () => "The name shows on every page of the project."),
|
|
27
|
+
h(VCardActions, { class: "justify-end" }, () => [
|
|
28
|
+
h(VBtn, { variant: "text" }, () => "Cancel"),
|
|
29
|
+
h(VBtn, { variant: "text", color: "primary" }, () => "Save")
|
|
30
|
+
])
|
|
31
|
+
])
|
|
32
|
+
));
|
|
33
|
+
|
|
34
|
+
const App = () => h(VApp, () => h(VMain, () => [page(), dialog()]));
|
|
35
|
+
|
|
36
|
+
createApp(App).use(createVuetify(createMaterialVuetifyOptions())).mount("#app");
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createApp, h } from "vue";
|
|
2
|
+
import { createVuetify } from "vuetify";
|
|
3
|
+
import { VAlert } from "vuetify/components/VAlert";
|
|
4
|
+
import { VApp } from "vuetify/components/VApp";
|
|
5
|
+
import { VExpansionPanel, VExpansionPanels } from "vuetify/components/VExpansionPanel";
|
|
6
|
+
import { VIconBtn } from "vuetify/components/VIconBtn";
|
|
7
|
+
import { VMain } from "vuetify/components/VMain";
|
|
8
|
+
import { VSnackbar } from "vuetify/components/VSnackbar";
|
|
9
|
+
import { VStepper } from "vuetify/components/VStepper";
|
|
10
|
+
import "vuetify/styles";
|
|
11
|
+
import "../../../src/client/material.css";
|
|
12
|
+
import { createMaterialVuetifyOptions } from "../../../src/client/index.js";
|
|
13
|
+
|
|
14
|
+
// Each Vuetify component that draws a layer of its own over its text, beyond the button, chip, list item, card and
|
|
15
|
+
// avatar material.css already restacks, with JSKIT's Material 3 options and stylesheet
|
|
16
|
+
// (underlayStacking.browser.test.js): a tonal alert (its tint), an alert with a border (its border box), icon buttons
|
|
17
|
+
// with a text at rest, tonal and active (their state layer and underlay), an editable stepper's step (its state layer
|
|
18
|
+
// and underlay), a tonal snackbar (its tint) and focusable expansion panels, the first open (each title's state
|
|
19
|
+
// layer, shown on the open one, on hover and on focus, and on a disabled one), one with a title of its own colour.
|
|
20
|
+
const App = () => h(VApp, () => h(VMain, { class: "pa-6" }, () => [
|
|
21
|
+
h(VAlert, {
|
|
22
|
+
variant: "tonal",
|
|
23
|
+
color: "primary",
|
|
24
|
+
title: "Backups",
|
|
25
|
+
text: "The last backup finished an hour ago.",
|
|
26
|
+
class: "mb-4",
|
|
27
|
+
"data-testid": "tonal-alert"
|
|
28
|
+
}),
|
|
29
|
+
h(VAlert, { border: "start", text: "Two-step sign-in is on.", class: "mb-4", "data-testid": "border-alert" }),
|
|
30
|
+
h("div", { class: "d-flex ga-4 mb-4" }, [
|
|
31
|
+
h(VIconBtn, { text: "Edit", width: 96, "data-testid": "icon-button" }),
|
|
32
|
+
h(VIconBtn, { text: "Copy", variant: "tonal", width: 96, "data-testid": "tonal-icon-button" }),
|
|
33
|
+
h(VIconBtn, { text: "Pinned", active: true, width: 96, "data-testid": "active-icon-button" })
|
|
34
|
+
]),
|
|
35
|
+
h(VStepper, { modelValue: 1, editable: true, hideActions: true, items: ["Shipping"], class: "mb-4", "data-testid": "stepper" }),
|
|
36
|
+
h(VExpansionPanels, { modelValue: [0], multiple: true, focusable: true, style: "max-width: 480px", "data-testid": "panels" }, () => [
|
|
37
|
+
h(VExpansionPanel, { title: "Billing", text: "Invoices go to the billing contact." }),
|
|
38
|
+
h(VExpansionPanel, { title: "Security" }),
|
|
39
|
+
h(VExpansionPanel, { title: "Plan", color: "primary" }),
|
|
40
|
+
h(VExpansionPanel, { title: "Archive", disabled: true })
|
|
41
|
+
]),
|
|
42
|
+
h(VSnackbar, { modelValue: true, variant: "tonal", timeout: -1, text: "Saved the report.", "data-testid": "snackbar" })
|
|
43
|
+
]));
|
|
44
|
+
|
|
45
|
+
createApp(App).use(createVuetify(createMaterialVuetifyOptions())).mount("#app");
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { expect } from "@playwright/test";
|
|
6
|
+
import { sharedBrowserFixture } from "../../../tooling/testUtils/browserFixture.mjs";
|
|
7
|
+
|
|
8
|
+
const SKIP = process.env.JSKIT_MATERIAL_WEB_BROWSER === "1" ? false : "set JSKIT_MATERIAL_WEB_BROWSER=1";
|
|
9
|
+
const open = sharedBrowserFixture({
|
|
10
|
+
fixtureRoot: fileURLToPath(new URL("./fixtures/keyboard-ripple", import.meta.url)),
|
|
11
|
+
configFile: "vite.config.js"
|
|
12
|
+
});
|
|
13
|
+
// Vuetify ends a ripple 250 ms after it began at the earliest, then fades it out for 300 ms.
|
|
14
|
+
const ENDED = { timeout: 3000 };
|
|
15
|
+
|
|
16
|
+
// A control's own Enter handler that moves focus (a card opening a panel and focusing its title) ran before Vuetify's
|
|
17
|
+
// ripple directive heard the key, so the card's ripple showed after the card had lost focus, its keyup reached the
|
|
18
|
+
// panel's title, and the ripple stayed drawn, over the text around the card for axe, while no other control showed a
|
|
19
|
+
// keyboard ripple. Material 3's pressed state ends with the press. The blur that ends it goes only to a control that
|
|
20
|
+
// shows a live ripple and no longer holds focus: not to one without a ripple, nor to one that keeps focus.
|
|
21
|
+
test("a keyboard press's ripple ends with the press when the control's own Enter handler moves focus away, and the next press ripples", {
|
|
22
|
+
skip: SKIP,
|
|
23
|
+
timeout: 120_000
|
|
24
|
+
}, async (t) => {
|
|
25
|
+
const { vite, browser } = await open(t);
|
|
26
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 1280, height: 800 } });
|
|
27
|
+
t.after(() => page.close());
|
|
28
|
+
await page.goto("/");
|
|
29
|
+
// The blur events each control heard during `press`, which starts on a control already focused.
|
|
30
|
+
const blursDuring = async (press) => {
|
|
31
|
+
const before = await page.evaluate(() => ({ ...globalThis.blurs }));
|
|
32
|
+
await press();
|
|
33
|
+
const after = await page.evaluate(() => ({ ...globalThis.blurs }));
|
|
34
|
+
return Object.fromEntries(Object.keys(after).map((name) => [name, after[name] - before[name]]));
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const card = page.getByTestId("card");
|
|
38
|
+
const title = page.getByTestId("panel-title");
|
|
39
|
+
await card.focus();
|
|
40
|
+
const cardPress = await blursDuring(async () => {
|
|
41
|
+
await page.keyboard.press("Enter");
|
|
42
|
+
await expect(title).toBeFocused();
|
|
43
|
+
await expect(title).toHaveText("Opened 1 times");
|
|
44
|
+
await expect(card.locator(".v-ripple__animation"), "the card's ripple ends once Enter comes up on the panel").toHaveCount(0, ENDED);
|
|
45
|
+
});
|
|
46
|
+
assert.deepEqual(cardPress, { card: 2, plain: 0, title: 0, next: 0 },
|
|
47
|
+
"the card hears its own blur as focus leaves, then the one its ripple missed; nothing else hears one");
|
|
48
|
+
|
|
49
|
+
const plain = page.getByTestId("plain");
|
|
50
|
+
await plain.focus();
|
|
51
|
+
const plainPress = await blursDuring(async () => {
|
|
52
|
+
await page.keyboard.press("Enter");
|
|
53
|
+
await expect(title).toHaveText("Opened 2 times");
|
|
54
|
+
await expect(title).toBeFocused();
|
|
55
|
+
});
|
|
56
|
+
assert.deepEqual(plainPress, { card: 0, plain: 1, title: 0, next: 0 },
|
|
57
|
+
"a control without a ripple hears only its own blur as focus leaves it");
|
|
58
|
+
|
|
59
|
+
const next = page.getByTestId("next");
|
|
60
|
+
await next.focus();
|
|
61
|
+
const nextPress = await blursDuring(async () => {
|
|
62
|
+
await page.keyboard.down("Enter");
|
|
63
|
+
await expect(next.locator(".v-ripple__animation"), "the next control shows its keyboard ripple while Enter is down").toHaveCount(1);
|
|
64
|
+
await page.keyboard.up("Enter");
|
|
65
|
+
await expect(next.locator(".v-ripple__animation"), "and ends it when Enter comes up").toHaveCount(0, ENDED);
|
|
66
|
+
await expect(next).toBeFocused();
|
|
67
|
+
});
|
|
68
|
+
assert.deepEqual(nextPress, { card: 0, plain: 0, title: 0, next: 0 }, "a control that keeps focus through its press hears no blur");
|
|
69
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import test from "node:test";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { expect } from "@playwright/test";
|
|
7
|
+
import { sharedBrowserFixture } from "../../../tooling/testUtils/browserFixture.mjs";
|
|
8
|
+
|
|
9
|
+
const SKIP = process.env.JSKIT_MATERIAL_WEB_BROWSER === "1" ? false : "set JSKIT_MATERIAL_WEB_BROWSER=1";
|
|
10
|
+
const AXE_PATH = createRequire(import.meta.url).resolve("axe-core/axe.min.js");
|
|
11
|
+
const open = sharedBrowserFixture({
|
|
12
|
+
fixtureRoot: fileURLToPath(new URL("./fixtures/overlay-stacking", import.meta.url)),
|
|
13
|
+
configFile: "vite.config.js"
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// The dialog's texts, as axe's color-contrast found them: judged and passed, judged and failed, or left unjudged with
|
|
17
|
+
// axe's reason.
|
|
18
|
+
async function dialogContrast(page) {
|
|
19
|
+
await page.addScriptTag({ path: AXE_PATH });
|
|
20
|
+
return page.evaluate(async () => {
|
|
21
|
+
const results = await globalThis.axe.run(document, { runOnly: { type: "rule", values: ["color-contrast"] } });
|
|
22
|
+
const inDialog = (outcome) => outcome.flatMap((rule) => rule.nodes)
|
|
23
|
+
.map((node) => ({ node, element: document.querySelector(node.target[0]) }))
|
|
24
|
+
.filter(({ element }) => element?.closest(".v-dialog"));
|
|
25
|
+
const text = (element) => element.textContent.trim();
|
|
26
|
+
return {
|
|
27
|
+
passed: inDialog(results.passes).map(({ element }) => text(element)).sort(),
|
|
28
|
+
failed: inDialog(results.violations).map(({ element }) => text(element)),
|
|
29
|
+
unjudged: inDialog(results.incomplete).map(({ node, element }) => (
|
|
30
|
+
`${node.any.map((check) => check.data?.messageKey || check.message).join("|")}: "${text(element)}"`
|
|
31
|
+
))
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// What the page draws: the elements under the middle of each of the dialog's texts and of the page's lines behind it,
|
|
37
|
+
// top first, as the browser hit-tests them, and the pixels of the whole window.
|
|
38
|
+
async function drawn(page) {
|
|
39
|
+
const points = await page.evaluate(() => {
|
|
40
|
+
const name = (element) => `${element.tagName.toLowerCase()}${[...element.classList].map((c) => `.${c}`).join("")}`;
|
|
41
|
+
const texts = [...document.querySelectorAll(".v-dialog .v-card-title, .v-dialog .v-card-text, .v-dialog .v-btn__content, [data-testid=page-behind] > p")];
|
|
42
|
+
return texts.map((text) => {
|
|
43
|
+
const box = text.getBoundingClientRect();
|
|
44
|
+
const under = document.elementsFromPoint(box.left + box.width / 2, box.top + box.height / 2);
|
|
45
|
+
return `${text.textContent.trim().slice(0, 12)}: ${under.slice(0, 4).map(name).join(" > ")}`;
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
return { points, pixels: await page.screenshot({ animations: "disabled" }) };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// axe-core 4.14 counts `contain: layout` as a stacking context without asking whether the element draws a box.
|
|
52
|
+
// Vuetify's overlay container (`.v-overlay-container`, where every dialog, menu, tooltip and snackbar is placed) has
|
|
53
|
+
// `contain: layout` with `display: contents`, which draws none, so for the browser it contains nothing; axe made it a
|
|
54
|
+
// stacking context at the page's base level and ranked every overlay in it under any of the page's elements with a
|
|
55
|
+
// z-index of 1 or more. Over such an element, axe found the page over the dialog's text and judged none of it
|
|
56
|
+
// (color-contrast incomplete, bgOverlap): mobilynet's dialogs, over its pages' content at z-index 1. axe-core 4.11
|
|
57
|
+
// read `contain` too, but ranked the container by its position, an entry the overlay's own stacking context took out
|
|
58
|
+
// of the order; 4.14 keeps a stacking context in the order. material.css sets the container's `contain` to none, which
|
|
59
|
+
// the browser draws the same: the same elements under every text, and the same pixels, as with Vuetify's own value.
|
|
60
|
+
test("axe judges every text of a dialog open over page content with a z-index of its own, and the page draws the same as with Vuetify's `contain: layout` on the overlay container", {
|
|
61
|
+
skip: SKIP,
|
|
62
|
+
timeout: 120_000
|
|
63
|
+
}, async (t) => {
|
|
64
|
+
const { vite, browser } = await open(t);
|
|
65
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 1280, height: 800 }, reducedMotion: "reduce" });
|
|
66
|
+
t.after(() => page.close());
|
|
67
|
+
await page.goto("/");
|
|
68
|
+
await expect(page.getByTestId("dialog-card")).toBeVisible();
|
|
69
|
+
await expect(page.getByTestId("page-behind")).toBeAttached();
|
|
70
|
+
// The dialog has finished opening: no animation is running (a card's progress line stays mounted, paused).
|
|
71
|
+
await page.waitForFunction(() => document.getAnimations().every((animation) => animation.playState !== "running"));
|
|
72
|
+
|
|
73
|
+
assert.deepEqual(await dialogContrast(page), {
|
|
74
|
+
passed: ["Cancel", "Edit the name", "Save", "The name shows on every page of the project."],
|
|
75
|
+
failed: [],
|
|
76
|
+
unjudged: []
|
|
77
|
+
}, "axe judges each of the dialog's texts and passes it");
|
|
78
|
+
|
|
79
|
+
const container = page.locator(".v-overlay-container");
|
|
80
|
+
await expect(container).toHaveCount(1);
|
|
81
|
+
assert.equal(await container.evaluate((element) => getComputedStyle(element).contain), "none");
|
|
82
|
+
const withNone = await drawn(page);
|
|
83
|
+
await container.evaluate((element) => { element.style.contain = "layout"; });
|
|
84
|
+
assert.equal(await container.evaluate((element) => getComputedStyle(element).contain), "layout");
|
|
85
|
+
const withLayout = await drawn(page);
|
|
86
|
+
assert.equal(withNone.points.length, 44, "the dialog's four texts and the page's forty lines");
|
|
87
|
+
assert.deepEqual(withNone.points, withLayout.points, "the same elements under every text");
|
|
88
|
+
assert.ok(withNone.pixels.equals(withLayout.pixels), "the same pixels");
|
|
89
|
+
});
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import test from "node:test";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { expect } from "@playwright/test";
|
|
7
|
+
import { sharedBrowserFixture } from "../../../tooling/testUtils/browserFixture.mjs";
|
|
8
|
+
|
|
9
|
+
const SKIP = process.env.JSKIT_MATERIAL_WEB_BROWSER === "1" ? false : "set JSKIT_MATERIAL_WEB_BROWSER=1";
|
|
10
|
+
const AXE_PATH = createRequire(import.meta.url).resolve("axe-core/axe.min.js");
|
|
11
|
+
const open = sharedBrowserFixture({
|
|
12
|
+
fixtureRoot: fileURLToPath(new URL("./fixtures/underlay-stacking", import.meta.url)),
|
|
13
|
+
configFile: "vite.config.js"
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// Vuetify's own stacking of the parts material.css restacks, as an unlayered stylesheet that overrides it: the page
|
|
17
|
+
// with it is the page as Vuetify draws it.
|
|
18
|
+
const VUETIFY_STACKING = `
|
|
19
|
+
:is(.v-alert, .v-stepper-item, .v-snackbar__wrapper),
|
|
20
|
+
.v-alert > :is(.v-alert__prepend, .v-alert__content, .v-alert__append, .v-alert__close),
|
|
21
|
+
.v-stepper-item > .v-stepper-item__content,
|
|
22
|
+
.v-snackbar__wrapper > :is(.v-snackbar__prepend, .v-snackbar__content, .v-snackbar__actions) { isolation: auto !important; }
|
|
23
|
+
.v-alert > :is(.v-alert__underlay, .v-alert__border),
|
|
24
|
+
.v-stepper-item > :is(.v-stepper-item__overlay, .v-stepper-item__underlay),
|
|
25
|
+
.v-snackbar__wrapper > .v-snackbar__underlay { z-index: auto !important; }
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
// Each component's texts, by the data-testid of the component (the snackbar's is its overlay's).
|
|
29
|
+
const TEXTS = Object.freeze({
|
|
30
|
+
"tonal-alert": ["Backups", "The last backup finished an hour ago."],
|
|
31
|
+
"border-alert": ["Two-step sign-in is on."],
|
|
32
|
+
"icon-button": ["Edit"],
|
|
33
|
+
"tonal-icon-button": ["Copy"],
|
|
34
|
+
"active-icon-button": ["Pinned"],
|
|
35
|
+
stepper: ["Shipping"],
|
|
36
|
+
snackbar: ["Saved the report."]
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Focusable expansion panels' texts, the first panel open: its title, its text and the closed panels' titles, one
|
|
40
|
+
// of its own colour (primary). A disabled panel's title, tinted as Vuetify tints it, has no text axe judges.
|
|
41
|
+
const PANEL_TEXTS = Object.freeze({ panels: ["Billing", "Invoices go to the billing contact.", "Security", "Plan"] });
|
|
42
|
+
|
|
43
|
+
// Vuetify's state layer for an expansion panel title without a background of its own, its __overlay over the title's
|
|
44
|
+
// text, as an unlayered stylesheet that overrides material.css's.
|
|
45
|
+
const VUETIFY_STATE_LAYER = `
|
|
46
|
+
.v-expansion-panel-title:not([class*=" bg-"], [style*="background"]) { background-color: transparent !important; }
|
|
47
|
+
.v-expansion-panel-title > .v-expansion-panel-title__overlay { display: inline !important; }
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
// What axe's color-contrast makes of each component's texts, and what lies on top of each text's first line: in
|
|
51
|
+
// axe's model of the page (its element stack, which counts a layer the browser's hit test skips for
|
|
52
|
+
// pointer-events: none) and for the browser (elementsFromPoint). "self" is the text's own element. A text of one or
|
|
53
|
+
// two characters (a step's number) is too short for axe to judge (shortTextContent).
|
|
54
|
+
async function judged(page, textsByComponent) {
|
|
55
|
+
if (!(await page.evaluate(() => Boolean(globalThis.axe)))) await page.addScriptTag({ path: AXE_PATH });
|
|
56
|
+
return page.evaluate(async (texts) => {
|
|
57
|
+
const results = await globalThis.axe.run(document, { runOnly: { type: "rule", values: ["color-contrast"] } });
|
|
58
|
+
const name = (element) => `${element.tagName.toLowerCase()}${[...element.classList].slice(0, 2).map((c) => `.${c}`).join("")}`;
|
|
59
|
+
const ownText = (element) => [...element.childNodes].filter((node) => node.nodeType === 3).map((node) => node.textContent).join("").trim();
|
|
60
|
+
const component = (element) => element.closest("[data-testid]")?.dataset.testid ||
|
|
61
|
+
(element.closest(".v-snackbar__wrapper") ? "snackbar" : "page");
|
|
62
|
+
const nodes = (outcome) => outcome.flatMap((rule) => rule.nodes)
|
|
63
|
+
.map((node) => ({ node, element: document.querySelector(node.target[0]) }))
|
|
64
|
+
.filter(({ element }) => element && component(element) in texts);
|
|
65
|
+
const top = (element) => {
|
|
66
|
+
const axeTop = (globalThis.axe.commons.dom.getTextElementStack(element)[0] || [])[0];
|
|
67
|
+
const line = [...element.childNodes].find((node) => node.nodeType === 3 && node.textContent.trim());
|
|
68
|
+
const range = document.createRange();
|
|
69
|
+
range.selectNodeContents(line);
|
|
70
|
+
const box = range.getClientRects()[0];
|
|
71
|
+
const browserTop = document.elementsFromPoint(box.left + box.width / 2, box.top + box.height / 2)[0];
|
|
72
|
+
const show = (over) => (over === element ? "self" : over ? name(over) : "nothing");
|
|
73
|
+
return `axe ${show(axeTop)}, browser ${show(browserTop)}`;
|
|
74
|
+
};
|
|
75
|
+
globalThis.axe.setup(document);
|
|
76
|
+
try {
|
|
77
|
+
const passed = Object.fromEntries(Object.keys(texts).map((key) => [key, []]));
|
|
78
|
+
for (const { element } of nodes(results.passes)) passed[component(element)].push(ownText(element));
|
|
79
|
+
for (const key of Object.keys(passed)) passed[key].sort();
|
|
80
|
+
const tops = {};
|
|
81
|
+
for (const key of Object.keys(texts)) {
|
|
82
|
+
for (const element of document.querySelectorAll("*")) {
|
|
83
|
+
if (component(element) === key && texts[key].includes(ownText(element))) tops[ownText(element)] = top(element);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
passed,
|
|
88
|
+
failed: nodes(results.violations).map(({ element }) => ownText(element)),
|
|
89
|
+
unjudged: nodes(results.incomplete)
|
|
90
|
+
.map(({ node, element }) => ({ reason: node.any.map((check) => check.data?.messageKey || check.message).join("|"), element }))
|
|
91
|
+
.filter(({ reason }) => reason !== "shortTextContent")
|
|
92
|
+
.map(({ reason, element }) => `${reason}: "${ownText(element)}" (${top(element)})`),
|
|
93
|
+
tops
|
|
94
|
+
};
|
|
95
|
+
} finally {
|
|
96
|
+
globalThis.axe.teardown();
|
|
97
|
+
}
|
|
98
|
+
}, textsByComponent);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// The pixels of two screenshots of the window that differ by more than two levels (of 255) in a channel, and the
|
|
102
|
+
// box they lie in. Drawing two translucent layers of one colour in the other order gives the same colour but for its
|
|
103
|
+
// rounding: each blend rounds by half a level at most, so the two orders' pixels differ by two levels at most (one in
|
|
104
|
+
// almost every pixel, at a text's edges; two in a few, where a snackbar's text meets its tint).
|
|
105
|
+
function pixelsBeyondRounding(page, first, second) {
|
|
106
|
+
return page.evaluate(async (screenshots) => {
|
|
107
|
+
const pixels = async (base64) => {
|
|
108
|
+
const bitmap = await createImageBitmap(await (await fetch(`data:image/png;base64,${base64}`)).blob());
|
|
109
|
+
const context = new OffscreenCanvas(bitmap.width, bitmap.height).getContext("2d");
|
|
110
|
+
context.drawImage(bitmap, 0, 0);
|
|
111
|
+
return context.getImageData(0, 0, bitmap.width, bitmap.height);
|
|
112
|
+
};
|
|
113
|
+
const [{ width, data: a }, { data: b }] = await Promise.all(screenshots.map(pixels));
|
|
114
|
+
let count = 0;
|
|
115
|
+
let box = null;
|
|
116
|
+
for (let index = 0; index < a.length; index += 4) {
|
|
117
|
+
if ([0, 1, 2, 3].every((channel) => Math.abs(a[index + channel] - b[index + channel]) <= 2)) continue;
|
|
118
|
+
const [x, y] = [(index / 4) % width, Math.floor(index / 4 / width)];
|
|
119
|
+
count += 1;
|
|
120
|
+
box = box ? { left: Math.min(box.left, x), top: Math.min(box.top, y), right: Math.max(box.right, x), bottom: Math.max(box.bottom, y) } :
|
|
121
|
+
{ left: x, top: y, right: x, bottom: y };
|
|
122
|
+
}
|
|
123
|
+
return { count, box };
|
|
124
|
+
}, [first.toString("base64"), second.toString("base64")]);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Vuetify draws a tonal alert's tint, an alert's border box, an editable step's state layer and underlay and a tonal
|
|
128
|
+
// snackbar's tint as positioned boxes after the text they cover, so they lie over it: axe found each over its
|
|
129
|
+
// component's text and judged none of it (color-contrast incomplete, bgOverlap). material.css draws them under the
|
|
130
|
+
// text, as it does a button's, chip's, list item's, card's and avatar's layers: each component is a stacking context
|
|
131
|
+
// with its layers at z-index -1 in it, and each part holding its text is one too, which axe-core 4.14 needs to rank
|
|
132
|
+
// the text above the layers. The tint is the text's own colour, so the window shows the same pixels either way, but
|
|
133
|
+
// for rounding. Icon buttons, at rest, tonal and active, are judged as Vuetify draws them, and stay so.
|
|
134
|
+
test("axe judges the text of a tonal alert, a bordered alert, icon buttons, an editable step and a tonal snackbar, each on top of its component's layers, and the page draws the same as with Vuetify's stacking", {
|
|
135
|
+
skip: SKIP,
|
|
136
|
+
timeout: 120_000
|
|
137
|
+
}, async (t) => {
|
|
138
|
+
const { vite, browser } = await open(t);
|
|
139
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 1280, height: 800 }, reducedMotion: "reduce" });
|
|
140
|
+
t.after(() => page.close());
|
|
141
|
+
await page.goto("/");
|
|
142
|
+
await expect(page.locator(".v-snackbar__content")).toHaveText("Saved the report.");
|
|
143
|
+
await page.waitForFunction(() => document.getAnimations().every((animation) => animation.playState !== "running"));
|
|
144
|
+
|
|
145
|
+
const restacked = await page.screenshot({ animations: "disabled" });
|
|
146
|
+
const style = await page.addStyleTag({ content: VUETIFY_STACKING });
|
|
147
|
+
const asVuetifyStacksThem = await page.screenshot({ animations: "disabled" });
|
|
148
|
+
await style.evaluate((element) => element.remove());
|
|
149
|
+
|
|
150
|
+
const texts = Object.values(TEXTS).flat();
|
|
151
|
+
assert.deepEqual({ ...(await judged(page, TEXTS)), pixels: await pixelsBeyondRounding(page, restacked, asVuetifyStacksThem) }, {
|
|
152
|
+
passed: Object.fromEntries(Object.entries(TEXTS).map(([key, list]) => [key, [...list].sort()])),
|
|
153
|
+
failed: [],
|
|
154
|
+
unjudged: [],
|
|
155
|
+
tops: Object.fromEntries(texts.map((text) => [text, "axe self, browser self"])),
|
|
156
|
+
pixels: { count: 0, box: null }
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// Vuetify draws an expansion panel title's state layer, shown on an open focusable panel, on hover and on keyboard
|
|
161
|
+
// focus, as a positioned box over the title's text, a text of the title's own: axe found the layer over the text and
|
|
162
|
+
// judged none of it (color-contrast incomplete, bgOverlap). material.css draws the state as the title's own
|
|
163
|
+
// background, the text's own colour at the state's opacity, as the layer drew it, so the window shows the same
|
|
164
|
+
// pixels either way, but for rounding. A title of its own colour keeps its background and Vuetify's layer: at rest
|
|
165
|
+
// axe judges its text on that background (the browser's hit test finds the layer, transparent, which takes clicks),
|
|
166
|
+
// and hovered axe finds the layer over its text, as Vuetify draws it.
|
|
167
|
+
test("axe judges an expansion panel title's text on top of its state layer, on an open focusable panel, on hover and on keyboard focus, and the page draws the same as with Vuetify's state layer", {
|
|
168
|
+
skip: SKIP,
|
|
169
|
+
timeout: 120_000
|
|
170
|
+
}, async (t) => {
|
|
171
|
+
const { vite, browser } = await open(t);
|
|
172
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 1280, height: 800 }, reducedMotion: "reduce" });
|
|
173
|
+
t.after(() => page.close());
|
|
174
|
+
await page.goto("/");
|
|
175
|
+
const titles = page.getByTestId("panels").locator(".v-expansion-panel-title");
|
|
176
|
+
await expect(titles).toHaveText(["Billing", "Security", "Plan", "Archive"]);
|
|
177
|
+
await expect(page.getByText("Invoices go to the billing contact.")).toBeVisible();
|
|
178
|
+
|
|
179
|
+
const states = {
|
|
180
|
+
"at rest": async () => {},
|
|
181
|
+
"Billing hovered": () => titles.nth(0).hover(),
|
|
182
|
+
"Security hovered": () => titles.nth(1).hover(),
|
|
183
|
+
"Plan hovered": () => titles.nth(2).hover(),
|
|
184
|
+
"Security focused": async () => {
|
|
185
|
+
await page.mouse.move(1, 1);
|
|
186
|
+
await titles.nth(0).focus();
|
|
187
|
+
await page.keyboard.press("Tab");
|
|
188
|
+
},
|
|
189
|
+
"Billing focused": () => page.keyboard.press("Shift+Tab")
|
|
190
|
+
};
|
|
191
|
+
const titlesThat = (state) => titles.evaluateAll((list, selector) => list.filter((title) => title.matches(selector))
|
|
192
|
+
.map((title) => [...title.childNodes].filter((node) => node.nodeType === 3).map((node) => node.textContent).join("").trim()), state);
|
|
193
|
+
const seen = {};
|
|
194
|
+
for (const [state, reach] of Object.entries(states)) {
|
|
195
|
+
await reach();
|
|
196
|
+
await page.waitForFunction(() => document.getAnimations().every((animation) => animation.playState !== "running"));
|
|
197
|
+
const drawn = await page.screenshot({ animations: "disabled" });
|
|
198
|
+
const style = await page.addStyleTag({ content: VUETIFY_STATE_LAYER });
|
|
199
|
+
const asVuetifyDrawsIt = await page.screenshot({ animations: "disabled" });
|
|
200
|
+
await style.evaluate((element) => element.remove());
|
|
201
|
+
seen[state] = {
|
|
202
|
+
hovered: await titlesThat(":hover"),
|
|
203
|
+
focused: await titlesThat(":focus-visible"),
|
|
204
|
+
...(await judged(page, PANEL_TEXTS)),
|
|
205
|
+
pixels: await pixelsBeyondRounding(page, drawn, asVuetifyDrawsIt)
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const texts = PANEL_TEXTS.panels;
|
|
210
|
+
const layer = "span.v-expansion-panel-title__overlay";
|
|
211
|
+
const tops = Object.fromEntries(texts.map((text) => [text, "axe self, browser self"]));
|
|
212
|
+
const judgedOnTop = (hovered, focused) => ({
|
|
213
|
+
hovered,
|
|
214
|
+
focused,
|
|
215
|
+
passed: { panels: [...texts].sort() },
|
|
216
|
+
failed: [],
|
|
217
|
+
unjudged: [],
|
|
218
|
+
tops: { ...tops, Plan: `axe self, browser ${layer}` },
|
|
219
|
+
pixels: { count: 0, box: null }
|
|
220
|
+
});
|
|
221
|
+
const planUnderItsLayer = {
|
|
222
|
+
...judgedOnTop(["Plan"], []),
|
|
223
|
+
passed: { panels: texts.filter((text) => text !== "Plan").sort() },
|
|
224
|
+
unjudged: [`bgOverlap: "Plan" (axe ${layer}, browser ${layer})`],
|
|
225
|
+
tops: { ...tops, Plan: `axe ${layer}, browser ${layer}` }
|
|
226
|
+
};
|
|
227
|
+
assert.deepEqual(seen, {
|
|
228
|
+
"at rest": judgedOnTop([], []),
|
|
229
|
+
"Billing hovered": judgedOnTop(["Billing"], []),
|
|
230
|
+
"Security hovered": judgedOnTop(["Security"], []),
|
|
231
|
+
"Plan hovered": planUnderItsLayer,
|
|
232
|
+
"Security focused": judgedOnTop([], ["Security"]),
|
|
233
|
+
"Billing focused": judgedOnTop([], ["Billing"])
|
|
234
|
+
});
|
|
235
|
+
});
|