@jskit-ai/material-web 0.1.10 → 0.1.11
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 +8 -0
- package/README.md +26 -4
- package/package.json +1 -1
- package/src/client/defaults.js +23 -0
- package/src/client/material.css +75 -6
- package/test/accessibility.browser.test.js +31 -0
- package/test/chips.browser.test.js +71 -0
- package/test/fixtures/chips/index.html +2 -0
- package/test/fixtures/chips/main.js +27 -0
- package/test/fixtures/chips/vite.config.js +7 -0
- package/test/materialWeb.test.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- A chip's label longer than its chip ends in an ellipsis inside it, as a button's does: material.css lets a chip's text-only content shrink and clip (`.v-chip > .v-chip__content:not(:has(> *))`). Vuetify's inline-flex content could not shrink, so a long label was cut mid-word at the chip's edge, or drawn past it on a chip you press. A chip whose label holds elements of its own (an icon or avatar in its default slot) keeps Vuetify's layout; a short label is drawn as before.
|
|
6
|
+
- A tooltip opened by focus closes when its button loses focus to nothing, as `blur()` takes it. Vuetify 4.3.2 ignores such a blur (it keeps it for a click on an empty area inside an open menu), so the tooltip a keyboard user opened stayed over the page, and neither hovering nor leaving its button closed it (mobilynet's screen check met one). The `VTooltip` default's `activatorProps` listens for the `focusout` that follows and hands Vuetify's handler the blur it acts on, unless the pointer is on the tooltip itself, and the focus stays where `blur()` put it; a tooltip given its own `activator-props` replaces it. See the README's Upstream workarounds.
|
|
7
|
+
- axe judges the contrast of every text on a page again. Two things hid every text from it (color-contrast "incomplete", bgOverlap), so even text no one can read passed an accessibility check: a closed menu that stays mounted (`eager`, as shell-web's overflow menu does to keep the app bar's own items mounted on a phone) left Vuetify's overlay root over the whole window at z-index 2000, and Vuetify draws a button's, chip's, list item's, card's and avatar's state layer and underlay over its label. `material.css` now hides any overlay whose content is hidden (the rule it already had for tooltips, generalised), so a closing menu still animates out and its overlay goes once its content has; and draws state layers and tints under the content, as Material 3 orders them: each of those controls is its own stacking context with its layers at z-index -1, and its content parts are positioned (axe-core 4.14 reads the first, 4.11 the second; each alone still found layers over labels). Judged, three texts failed and are fixed or named:
|
|
8
|
+
- A tonal card of the default colour has `on-surface` text, tinted with `on-surface`: the `VCard` default `color` (`surface-container-low`) was its text colour, 1.04:1 on the page. Outlined, text and plain cards on the default colour get the same text colour.
|
|
9
|
+
- A filled or elevated button has no activated state layer (Material 3 gives it none): Vuetify's, the label's colour at 10% over the container, took a primary button's label to 4.11:1, under WCAG's 4.5:1, for as long as it stayed active. Hovered or focused, it shows that state's layer alone; a selected segmented button stays `secondary-container`.
|
|
10
|
+
- A disabled chip's label is Material 3's disabled colour (1.8:1), which WCAG 1.4.3 exempts as part of an inactive control, but Vuetify marks the chip disabled only with a `disabled` attribute on a span, which axe does not read: an app's contrast check names it as an exemption. So is an outlined field's text under its own outline (Vuetify's outline boxes are transparent but for their borders).
|
|
11
|
+
shell-web's `colorContrast.browser.test.js` runs axe on its fixture's pages at 390 and 1280: a deliberately unreadable line must be the one failure, and nothing else may stay unjudged.
|
|
12
|
+
|
|
5
13
|
- An app's start reuses the Material 3 colours an earlier start computed for the same theme. `materialThemes` (which `createMaterialVuetifyOptions` calls at every start) computed both schemes at every call: 30 ms in Chromium, 120 ms at 4x CPU slowdown, for a seed and two app colours (medians). The colours are now computed once per input, the seed (in any case) and the app's colours with their order and `blend`: a page or process reuses them, and a browser keeps the last four inputs' colours in `localStorage` (`jskit:material-themes`), so a later start takes 1.4 ms (6.6 ms at 4x). Computing them is quicker too, 23 ms (84 ms at 4x): it built three tonal-spot schemes where two are needed, one only to list the role names, and ran `customColor` once per scheme where one call gives both. The colours are the same, byte for byte (one sha256 of three inputs' light and dark themes before and after). A changed seed or colour is another input and is computed again. Stored colours that are not a complete set of hex roles, the scheme's and the input's app colours', or were stored under an earlier revision of the generator (`THEMES_REVISION` in `colorSchemes.js`, raised whenever the same input gives other colours) are computed again, and a browser that refuses storage computes them at each start, as a server does. materialWeb.test.js holds each revision's digest of the colours and fails when they change without a new revision. Measured with Chromium and Node 26 on a 20-thread test host under load, Vibe64's theme input; a seed alone went from 34 to 22 ms on a first visit and 27 to 1.3 ms on a later start.
|
|
6
14
|
|
|
7
15
|
- A radio group's own label and a checkbox's, radio's or switch's description are `on-surface-variant` at full strength, as a text field's label and supporting text are, instead of `on-surface` at Vuetify's medium-emphasis opacity: a group's label measured 4.19:1 in a dialog's `surface-container-high`, under WCAG's 4.5:1 (axe `color-contrast`). A control's own label was already `on-surface` at full strength, and a disabled group or control keeps its fade. `accessibility.browser.test.js` measures them in light and dark.
|
package/README.md
CHANGED
|
@@ -97,13 +97,19 @@ export const theme = {
|
|
|
97
97
|
character counters, radio group labels, checkbox, radio and switch
|
|
98
98
|
descriptions, and list item and card subtitles in on-surface-variant
|
|
99
99
|
at full strength (an invalid field's counter in error, as its messages),
|
|
100
|
-
one-line labels that
|
|
100
|
+
one-line button and chip labels that
|
|
101
101
|
end in an ellipsis, 12dp card corners, 28dp dialogs on
|
|
102
102
|
`surface-container-high` at level 3 and bottom sheets with a square card on
|
|
103
103
|
`surface-container-low`, square full-screen dialogs on `surface`, a 48dp touch target on clickable chips,
|
|
104
|
-
inverse-surface tooltips
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
inverse-surface tooltips, and every other overlay (menu, dialog, snackbar),
|
|
105
|
+
hidden whole while their content is (Vuetify keeps a mounted overlay around
|
|
106
|
+
its hidden content: a hidden tooltip was an empty tooltip to assistive
|
|
107
|
+
technology, and a closed eager menu lay over the whole page, so axe judged the
|
|
108
|
+
contrast of no text under it), state layers and tints under the label on
|
|
109
|
+
buttons, chips, list items, cards and avatars (axe judges the label's
|
|
110
|
+
contrast), no activated state layer on a filled or elevated button (it took a
|
|
111
|
+
primary button's label under 4.5:1), `on-surface` text on a tonal card of the
|
|
112
|
+
default colour, 40dp outlined segmented buttons and outlined
|
|
107
113
|
filter chips that lead with a check when selected (chips with
|
|
108
114
|
`aria-pressed` too), fixed tabs that share the width or else scroll, dialog
|
|
109
115
|
actions 24dp from the edges, a menu's own list as its container
|
|
@@ -155,6 +161,22 @@ Each one comes off when the upstream fix ships; its test says when.
|
|
|
155
161
|
would make an inline style). shell-web's browser test "a virtual-scroll list
|
|
156
162
|
in a dialog reaches its last item after the page around it re-renders"
|
|
157
163
|
guards it; it fails with `VDialog: { VCard: {} }` in the defaults.
|
|
164
|
+
- **Vuetify 4.3.2 (measured): a tooltip opened by focus stays open when its
|
|
165
|
+
activator loses focus to nothing.** Its activator ignores a blur with no
|
|
166
|
+
`relatedTarget` (as `blur()` gives), which it keeps for a click on an empty
|
|
167
|
+
area inside an open menu, so the tooltip a keyboard user opened stayed over
|
|
168
|
+
the page, and neither hovering nor leaving its button closed it. JSKIT's
|
|
169
|
+
`VTooltip` default `activatorProps` listens for the `focusout` that follows
|
|
170
|
+
(an event Vuetify's activator does not use) and hands Vuetify's handler the
|
|
171
|
+
blur it acts on, with the page as where focus went, unless the pointer is on
|
|
172
|
+
the tooltip itself. It first sets the tooltip's click-outside record
|
|
173
|
+
(`lastMousedownWasOutside`, as a click elsewhere does), so the closing
|
|
174
|
+
overlay leaves the focus where `blur()` put it instead of handing it back to
|
|
175
|
+
the activator. material-web's browser test "a tooltip opened by focus closes
|
|
176
|
+
when its button loses focus to nothing" guards both; it fails without the
|
|
177
|
+
default, and without the record the button is focused again. Drop the default once a Vuetify release passes that test
|
|
178
|
+
without it. A tooltip given its own `activator-props` replaces the default
|
|
179
|
+
and keeps Vuetify's behaviour.
|
|
158
180
|
- **Vuetify 4.3.2 and 4.3.3 (measured): idle loaders read layout as they
|
|
159
181
|
mount.** Every field built on `VField` (`v-text-field`, `v-select`,
|
|
160
182
|
`v-textarea` and the others) mounts an idle `VProgressLinear` in its loader
|
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.11",
|
|
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/defaults.js
CHANGED
|
@@ -7,6 +7,28 @@
|
|
|
7
7
|
// props cannot set, are in material.css. No VMenu sub-component defaults: under them, in Vuetify 4.2.1 to 4.3.2, an
|
|
8
8
|
// ancestor's re-render makes the menu's virtual list lose its item heights, so a v-select's typeahead never scrolls to
|
|
9
9
|
// its match (https://github.com/vuetifyjs/vuetify/issues/23366; README, Upstream workarounds).
|
|
10
|
+
// A tooltip opened by focus closes when its activator loses focus to nothing, as blur() takes it. Vuetify 4.3.2's
|
|
11
|
+
// activator ignores a blur with no relatedTarget, which it keeps for a click on an empty area inside an open menu, so
|
|
12
|
+
// the tooltip stayed over the page, and neither hovering nor leaving its activator closed it. On the focusout that
|
|
13
|
+
// follows (an event Vuetify's activator does not use, so this adds a listener rather than replacing or merging with
|
|
14
|
+
// Vuetify's own), Vuetify's handler gets the blur it acts on, with the page as where focus went, unless the pointer is
|
|
15
|
+
// on the tooltip itself (an interactive tooltip being clicked). The tooltip's overlay first records the focus as gone,
|
|
16
|
+
// as its click-outside record does after a click elsewhere, so closing leaves the focus where blur() put it: an overlay
|
|
17
|
+
// opened from its focused activator otherwise hands the focus back to the activator when it closes with the focus on
|
|
18
|
+
// the page.
|
|
19
|
+
function closeTooltipOnFocusLoss(event) {
|
|
20
|
+
if (event.relatedTarget || !event.isTrusted) return;
|
|
21
|
+
const activator = event.currentTarget;
|
|
22
|
+
const tooltips = String(activator.getAttribute("aria-describedby") || "").split(/\s+/u)
|
|
23
|
+
.filter(Boolean).map((id) => document.getElementById(id)).filter((element) => element?.classList.contains("v-tooltip"));
|
|
24
|
+
if (tooltips.some((tooltip) => tooltip.matches(":hover"))) return;
|
|
25
|
+
for (const tooltip of tooltips) {
|
|
26
|
+
const clickOutside = tooltip.querySelector(":scope > .v-overlay__content")?._clickOutside;
|
|
27
|
+
if (clickOutside) clickOutside.lastMousedownWasOutside = true;
|
|
28
|
+
}
|
|
29
|
+
activator.dispatchEvent(new FocusEvent("blur", { relatedTarget: document.body }));
|
|
30
|
+
}
|
|
31
|
+
|
|
10
32
|
const materialDefaults = Object.freeze({
|
|
11
33
|
VAppBar: {
|
|
12
34
|
color: "surface",
|
|
@@ -135,6 +157,7 @@ const materialDefaults = Object.freeze({
|
|
|
135
157
|
color: "surface"
|
|
136
158
|
},
|
|
137
159
|
VTooltip: {
|
|
160
|
+
activatorProps: { onFocusout: closeTooltipOnFocusLoss },
|
|
138
161
|
location: "bottom"
|
|
139
162
|
}
|
|
140
163
|
});
|
package/src/client/material.css
CHANGED
|
@@ -166,6 +166,47 @@
|
|
|
166
166
|
border-radius: inherit;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
/* A control's state layer and container tint lie under its content, as Material 3 orders them. Vuetify draws a
|
|
170
|
+
button's, chip's, list item's, card's and avatar's overlay and underlay over the label, so axe found a layer over
|
|
171
|
+
every label and judged the contrast of none (color-contrast incomplete, bgOverlap). Each control is its own
|
|
172
|
+
stacking context with its layers at z-index -1 in it, and its content parts are positioned: axe-core 4.14 reads
|
|
173
|
+
the first, 4.11 the second, and each still found layers over labels with only one of the two. */
|
|
174
|
+
:is(.v-btn, .v-chip, .v-list-item, .v-card, .v-avatar) {
|
|
175
|
+
isolation: isolate;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.v-btn > :is(.v-btn__overlay, .v-btn__underlay),
|
|
179
|
+
.v-chip > :is(.v-chip__overlay, .v-chip__underlay),
|
|
180
|
+
.v-list-item > :is(.v-list-item__overlay, .v-list-item__underlay),
|
|
181
|
+
.v-card > :is(.v-card__overlay, .v-card__underlay),
|
|
182
|
+
.v-avatar > .v-avatar__underlay {
|
|
183
|
+
z-index: -1;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.v-btn > :is(.v-btn__prepend, .v-btn__content, .v-btn__append),
|
|
187
|
+
.v-chip > :is(.v-chip__filter, .v-chip__prepend, .v-chip__content, .v-chip__append, .v-chip__close),
|
|
188
|
+
.v-list-item > :is(.v-list-item__prepend, .v-list-item__content, .v-list-item__append),
|
|
189
|
+
.v-card > :is(.v-card-item, .v-card-title, .v-card-subtitle, .v-card-text, .v-card-actions),
|
|
190
|
+
.v-avatar > :not(.v-avatar__underlay) {
|
|
191
|
+
position: relative;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/* A filled or elevated button has no activated state layer: Material 3 gives these buttons none (a selected
|
|
195
|
+
segment is secondary-container), and Vuetify's, the label's colour at 10% over the container, took a primary
|
|
196
|
+
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
|
|
197
|
+
active, as one whose route is current does. Hovered or focused, it shows that state's layer alone. */
|
|
198
|
+
.v-btn--active:is(.v-btn--variant-flat, .v-btn--variant-elevated) > .v-btn__overlay {
|
|
199
|
+
opacity: 0;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.v-btn--active:is(.v-btn--variant-flat, .v-btn--variant-elevated):hover > .v-btn__overlay {
|
|
203
|
+
opacity: calc(var(--v-hover-opacity) * var(--v-theme-overlay-multiplier));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.v-btn--active:is(.v-btn--variant-flat, .v-btn--variant-elevated):focus-visible > .v-btn__overlay {
|
|
207
|
+
opacity: calc(var(--v-focus-opacity) * var(--v-theme-overlay-multiplier));
|
|
208
|
+
}
|
|
209
|
+
|
|
169
210
|
/* A label stays on one line, as Material 3 draws it; one longer than its button ends in an ellipsis. */
|
|
170
211
|
.v-btn:not(.v-btn--stacked, .v-btn--icon) > .v-btn__content:not(:has(> *)) {
|
|
171
212
|
display: block;
|
|
@@ -174,6 +215,17 @@
|
|
|
174
215
|
text-overflow: ellipsis;
|
|
175
216
|
}
|
|
176
217
|
|
|
218
|
+
/* So does a chip's: a chip is at most as wide as its container and its label stays on one line, but Vuetify's
|
|
219
|
+
inline-flex content cannot shrink, so a longer label was cut mid-word at the chip's edge (or drawn past it on a
|
|
220
|
+
chip you press, which the touch target unclips). A label holding elements of its own (an icon or avatar in the
|
|
221
|
+
chip's default slot) keeps Vuetify's inline-flex content, which lays them out. */
|
|
222
|
+
.v-chip > .v-chip__content:not(:has(> *)) {
|
|
223
|
+
display: block;
|
|
224
|
+
min-width: 0;
|
|
225
|
+
overflow: hidden;
|
|
226
|
+
text-overflow: ellipsis;
|
|
227
|
+
}
|
|
228
|
+
|
|
177
229
|
/* Outlined buttons and outlined chips draw the outline role. */
|
|
178
230
|
.v-btn--variant-outlined:not([class*=" text-"]) {
|
|
179
231
|
border-color: rgb(var(--v-theme-outline));
|
|
@@ -282,12 +334,16 @@
|
|
|
282
334
|
padding: 4px 8px;
|
|
283
335
|
}
|
|
284
336
|
|
|
285
|
-
/* A hidden tooltip is hidden whole. Vuetify
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
337
|
+
/* A hidden overlay (tooltip, menu, dialog, snackbar) is hidden whole. Vuetify hides only an overlay's content when
|
|
338
|
+
it closes, and keeps the overlay around it whenever the content stays mounted: a tooltip, which Vuetify 4.3 mounts
|
|
339
|
+
before it first shows, or an eager menu, such as ShellLayout's overflow menu holding the app bar's own items on a
|
|
340
|
+
phone. A hidden tooltip's role="tooltip" overlay was an empty tooltip to assistive technology (axe
|
|
341
|
+
aria-tooltip-name), and its activator's aria-describedby read nothing, since hidden text counts only when the
|
|
342
|
+
element the activator names is hidden itself. A closed menu's overlay lay over the whole window at z-index 2000,
|
|
343
|
+
so axe found it over every text on the page and judged the contrast of none (color-contrast incomplete,
|
|
344
|
+
bgOverlap), letting text no one can read pass. The overlay hides only once its content has, so an opening or
|
|
345
|
+
closing one still animates. */
|
|
346
|
+
.v-overlay:has(> .v-overlay__content[style*="display: none"]) {
|
|
291
347
|
display: none;
|
|
292
348
|
}
|
|
293
349
|
|
|
@@ -680,6 +736,19 @@
|
|
|
680
736
|
color: rgb(var(--v-theme-on-surface-container-high));
|
|
681
737
|
}
|
|
682
738
|
|
|
739
|
+
/* A tonal card (or an outlined, text or plain one) draws its text and its tint in its colour, which for the default
|
|
740
|
+
surface-container-low colour was near-white on the near-white page: a tonal card's text read 1.04:1. Such a card
|
|
741
|
+
has on-surface text, tinted with on-surface, and on-surface-variant supporting text. A card given its own colour
|
|
742
|
+
keeps it. */
|
|
743
|
+
.v-card.text-surface-container-low {
|
|
744
|
+
color: rgb(var(--v-theme-on-surface));
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
.v-card.text-surface-container-low > .v-card-subtitle:not([class*=" text-"]),
|
|
748
|
+
.v-card.text-surface-container-low > .v-card-item > .v-card-item__content > .v-card-subtitle:not([class*=" text-"]) {
|
|
749
|
+
color: rgb(var(--v-theme-on-surface-variant));
|
|
750
|
+
}
|
|
751
|
+
|
|
683
752
|
.text-on-background {
|
|
684
753
|
color: rgb(var(--v-theme-on-background));
|
|
685
754
|
}
|
|
@@ -101,6 +101,37 @@ test("a hidden tooltip leaves no tooltip without a name and still describes its
|
|
|
101
101
|
await expect(button).toHaveAccessibleDescription("Delete this report");
|
|
102
102
|
});
|
|
103
103
|
|
|
104
|
+
// A tooltip opened by focus closes when its button loses focus, wherever focus goes, and leaves the focus there.
|
|
105
|
+
// Vuetify 4.3.2 kept it open when blur() took the focus nowhere, as it keeps a menu open for a click on an empty area
|
|
106
|
+
// inside it, so the tooltip stayed over the page, and neither hovering nor leaving the button closed it. A click on an
|
|
107
|
+
// empty part of the page closes it as a click outside.
|
|
108
|
+
test("a tooltip opened by focus closes when its button loses focus to nothing", {
|
|
109
|
+
skip: SKIP,
|
|
110
|
+
timeout: 120_000
|
|
111
|
+
}, async (t) => {
|
|
112
|
+
const { vite, browser } = await open(t);
|
|
113
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, reducedMotion: "reduce" });
|
|
114
|
+
t.after(() => page.close());
|
|
115
|
+
const button = page.getByTestId("tooltip-activator");
|
|
116
|
+
const tooltip = page.getByRole("tooltip", { name: "Delete this report" });
|
|
117
|
+
// Each way of losing focus on a fresh page: Vuetify ignores focus for 50ms after a tooltip closes.
|
|
118
|
+
const losses = [
|
|
119
|
+
["a click on an empty part of the page", () => page.mouse.click(4, 4)],
|
|
120
|
+
["the button's blur()", () => button.evaluate((element) => element.blur())]
|
|
121
|
+
];
|
|
122
|
+
for (const [loss, loseFocus] of losses) {
|
|
123
|
+
await page.goto("/");
|
|
124
|
+
await expect(button).toBeVisible();
|
|
125
|
+
await page.keyboard.press("Tab");
|
|
126
|
+
await expect(button).toBeFocused();
|
|
127
|
+
await expect(tooltip).toBeVisible();
|
|
128
|
+
await loseFocus();
|
|
129
|
+
await expect(tooltip, `closed after ${loss}`).toBeHidden();
|
|
130
|
+
// Closing leaves the focus where it went, rather than handing it back to the button.
|
|
131
|
+
await expect(button, `not focused again once closed after ${loss}`).not.toBeFocused();
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
104
135
|
// A card's subtitle is its supporting text, at full strength: on-surface-variant on a surface card or one without a
|
|
105
136
|
// colour, the card's own text colour on a coloured card, and its own class's colour when it has one. At Vuetify's
|
|
106
137
|
// medium-emphasis opacity it measured 4.35:1 on JSKIT's default surface-container-low card, under WCAG's 4.5:1.
|
|
@@ -0,0 +1,71 @@
|
|
|
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 { sharedBrowserFixture } from "../../../tooling/testUtils/browserFixture.mjs";
|
|
6
|
+
|
|
7
|
+
const SKIP = process.env.JSKIT_MATERIAL_WEB_BROWSER === "1" ? false : "set JSKIT_MATERIAL_WEB_BROWSER=1";
|
|
8
|
+
const open = sharedBrowserFixture({
|
|
9
|
+
fixtureRoot: fileURLToPath(new URL("./fixtures/chips", import.meta.url)),
|
|
10
|
+
configFile: "vite.config.js"
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// Where a chip, its content and its label's text are drawn (left, top, right, bottom, to a tenth of a pixel), and how
|
|
14
|
+
// its content lays out and clips.
|
|
15
|
+
function chipGeometry(locator) {
|
|
16
|
+
return locator.evaluate((chip) => {
|
|
17
|
+
const content = chip.querySelector(":scope > .v-chip__content");
|
|
18
|
+
const text = document.createRange();
|
|
19
|
+
text.selectNodeContents(content);
|
|
20
|
+
const box = (rect) => [rect.left, rect.top, rect.right, rect.bottom].map((value) => Math.round(value * 10) / 10);
|
|
21
|
+
const style = getComputedStyle(content);
|
|
22
|
+
return {
|
|
23
|
+
chip: box(chip.getBoundingClientRect()),
|
|
24
|
+
content: box(content.getBoundingClientRect()),
|
|
25
|
+
text: box(text.getBoundingClientRect()),
|
|
26
|
+
display: style.display,
|
|
27
|
+
overflow: style.overflowX,
|
|
28
|
+
textOverflow: style.textOverflow,
|
|
29
|
+
clipped: content.scrollWidth > content.clientWidth
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Vuetify's own chip content (inline-flex, unclipped), unlayered so it wins over material.css's layers.
|
|
35
|
+
const VUETIFY_CHIP_CONTENT = ".v-chip > .v-chip__content { display: inline-flex; min-width: auto; overflow: visible; text-overflow: clip; }";
|
|
36
|
+
|
|
37
|
+
// A chip is at most as wide as its container, and its label stays on one line, so a label longer than the chip was cut
|
|
38
|
+
// mid-word at the chip's edge, or drawn past it on a chip you press. It ends in an ellipsis inside the chip, as a
|
|
39
|
+
// button's does; a chip whose label holds elements of its own keeps Vuetify's layout, and a short label is unchanged.
|
|
40
|
+
test("a chip's label longer than its chip ends in an ellipsis inside it; a short label and one holding an element are drawn as before", {
|
|
41
|
+
skip: SKIP,
|
|
42
|
+
timeout: 120_000
|
|
43
|
+
}, async (t) => {
|
|
44
|
+
const { vite, browser } = await open(t);
|
|
45
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 390, height: 844 }, reducedMotion: "reduce" });
|
|
46
|
+
t.after(() => page.close());
|
|
47
|
+
await page.goto("/");
|
|
48
|
+
await page.getByTestId("slot-chip").waitFor();
|
|
49
|
+
const column = await page.getByTestId("column").evaluate((element) => element.getBoundingClientRect().right);
|
|
50
|
+
|
|
51
|
+
for (const testId of ["long-chip", "long-pressable-chip"]) {
|
|
52
|
+
const drawn = await chipGeometry(page.getByTestId(testId));
|
|
53
|
+
assert.ok(drawn.chip[2] <= column, `${testId} ends at ${drawn.chip[2]}, inside its ${column}px column`);
|
|
54
|
+
assert.ok(drawn.content[2] <= drawn.chip[2], `${testId}'s label ends at ${drawn.content[2]}, inside the chip (${drawn.chip[2]})`);
|
|
55
|
+
assert.deepEqual([drawn.overflow, drawn.textOverflow, drawn.clipped], ["hidden", "ellipsis", true],
|
|
56
|
+
`${testId}'s label is clipped with an ellipsis`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const unchanged = ["short-chip", "icon-chip", "slot-chip"];
|
|
60
|
+
const ours = [];
|
|
61
|
+
for (const testId of unchanged) ours.push(await chipGeometry(page.getByTestId(testId)));
|
|
62
|
+
// Vuetify's inline-flex content, as the chip's flex item, computes to flex; material.css's text-only content is block.
|
|
63
|
+
assert.deepEqual(ours.map(({ display }) => display), ["block", "block", "flex"],
|
|
64
|
+
"a text-only label is clipped as a block; one holding an element keeps Vuetify's inline-flex content");
|
|
65
|
+
await page.addStyleTag({ content: VUETIFY_CHIP_CONTENT });
|
|
66
|
+
for (const [index, testId] of unchanged.entries()) {
|
|
67
|
+
const theirs = await chipGeometry(page.getByTestId(testId));
|
|
68
|
+
const where = ({ chip, content, text }) => ({ chip, content, text });
|
|
69
|
+
assert.deepEqual(where(ours[index]), where(theirs), `${testId} is drawn as with Vuetify's own chip content`);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createApp, h } from "vue";
|
|
2
|
+
import { createVuetify } from "vuetify";
|
|
3
|
+
import { VApp } from "vuetify/components/VApp";
|
|
4
|
+
import { VChip } from "vuetify/components/VChip";
|
|
5
|
+
import { VIcon } from "vuetify/components/VIcon";
|
|
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
|
+
// Chips in a column narrower than a long label, with JSKIT's Material 3 options and stylesheet, as an app draws them
|
|
12
|
+
// (chips.browser.test.js): a long label on a chip and on a chip you press (whose touch target unclips it), a short one,
|
|
13
|
+
// a short one with a leading icon, and one whose label holds an element of its own (an icon in its default slot).
|
|
14
|
+
const LONG = "Quarterly invoices for the North Atlantic shipping project, second half";
|
|
15
|
+
const chips = [
|
|
16
|
+
{ testId: "long-chip", props: { text: LONG } },
|
|
17
|
+
{ testId: "long-pressable-chip", props: { text: LONG, link: true } },
|
|
18
|
+
{ testId: "short-chip", props: { text: "Draft" } },
|
|
19
|
+
{ testId: "icon-chip", props: { text: "Shared", prependIcon: "$info" } },
|
|
20
|
+
{ testId: "slot-chip", props: {}, label: () => [h(VIcon, { icon: "$info", start: true }), "Shared"] }
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const App = () => h(VApp, () => h(VMain, { class: "pa-6" }, () => h("div", { style: "width: 240px", "data-testid": "column" }, (
|
|
24
|
+
chips.map(({ testId, props, label }) => h("div", { class: "mb-2" }, h(VChip, { ...props, "data-testid": testId }, label)))
|
|
25
|
+
))));
|
|
26
|
+
|
|
27
|
+
createApp(App).use(createVuetify(createMaterialVuetifyOptions())).mount("#app");
|
package/test/materialWeb.test.js
CHANGED
|
@@ -485,8 +485,8 @@ test("material.css draws segmented buttons, filter chips, fixed tabs and dialog
|
|
|
485
485
|
css,
|
|
486
486
|
/\.v-card:not\(\[class\*="bg-"\], \[class\*=" text-"\]\) \.v-card-subtitle,\s*\.v-card\[class\*="bg-surface"\]:not\(\[class\*=" text-"\]\) \.v-card-subtitle \{\s*color: rgb\(var\(--v-theme-on-surface-variant\)\);\s*\}/u
|
|
487
487
|
);
|
|
488
|
-
//
|
|
489
|
-
assert.match(css, /\.v-
|
|
488
|
+
// An overlay (a tooltip, a closed eager menu) is hidden whole while its content is.
|
|
489
|
+
assert.match(css, /\.v-overlay:has\(> \.v-overlay__content\[style\*="display: none"\]\) \{\s*display: none;\s*\}/u);
|
|
490
490
|
// A disabled container button is on-surface 12% and 38%, unlayered over its colour class.
|
|
491
491
|
assert.match(
|
|
492
492
|
css,
|