@m3ui-vue/m3ui-vue 1.1.2 → 1.1.4
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/README.md +1 -1
- package/dist/API.md +202 -10
- package/dist/{MIcon-DLOkQduI.js → MIcon-Bxh9j135.js} +15 -8
- package/dist/MIcon-Bxh9j135.js.map +1 -0
- package/dist/{MMenuItem-DVxKEv1W.js → MMenuItem-BfjqwcYP.js} +85 -64
- package/dist/MMenuItem-BfjqwcYP.js.map +1 -0
- package/dist/MSlider-JflHJ70q.js +1525 -0
- package/dist/MSlider-JflHJ70q.js.map +1 -0
- package/dist/{MTextField-rML9jnXs.js → MTextField-NaIB6RbM.js} +68 -66
- package/dist/MTextField-NaIB6RbM.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +2 -2
- package/dist/components/MAnimatedNumber.vue.d.ts +29 -0
- package/dist/components/MButton.vue.d.ts +2 -0
- package/dist/components/MContainerTransform.vue.d.ts +59 -0
- package/dist/components/MDialog.vue.d.ts +8 -5
- package/dist/components/MFlex.vue.d.ts +1 -1
- package/dist/components/MIcon.vue.d.ts +2 -0
- package/dist/components/MIconButton.vue.d.ts +2 -0
- package/dist/components/MListGroup.vue.d.ts +23 -0
- package/dist/components/MListItem.vue.d.ts +5 -5
- package/dist/components/MNavigationRail.vue.d.ts +1 -1
- package/dist/components/MScheduler.vue.d.ts +2 -2
- package/dist/components/MScheme.vue.d.ts +60 -0
- package/dist/components/MSparkline.vue.d.ts +41 -0
- package/dist/components/MSplitter.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +1 -1
- package/dist/components/MToolbar.vue.d.ts +32 -5
- package/dist/components/MWindow.vue.d.ts +2 -2
- package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
- package/dist/components/_MToolbarFab.vue.d.ts +16 -0
- package/dist/composables/_containerTransform.d.ts +48 -0
- package/dist/composables/_useSegmentRuns.d.ts +8 -0
- package/dist/composables/dynamicColor.d.ts +11 -0
- package/dist/composables/useColorPalette.d.ts +3 -1
- package/dist/composables/useConfetti.d.ts +32 -0
- package/dist/composables/useContainerTransform.d.ts +30 -0
- package/dist/composables/useLocale.d.ts +9 -0
- package/dist/index.d.ts +10 -1
- package/dist/locales/index.js +35 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +16844 -15530
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +55 -55
- package/dist/{material-color-utilities-Cktu8DBU.js → material-color-utilities-C_iikgRm.js} +928 -603
- package/dist/material-color-utilities-C_iikgRm.js.map +1 -0
- package/dist/rich-text-editor.js +11 -11
- package/dist/styles.css +1 -1
- package/dist/terminal.js +1 -1
- package/dist/{useLocale-CqQrhWFl.js → useLocale-CXibICQA.js} +6 -1
- package/dist/useLocale-CXibICQA.js.map +1 -0
- package/package.json +2 -1
- package/src/__tests__/MAnimatedNumber.test.ts +128 -0
- package/src/__tests__/MContainerTransform.test.ts +279 -0
- package/src/__tests__/MDialog.test.ts +27 -0
- package/src/__tests__/MIcon.test.ts +19 -0
- package/src/__tests__/MListItemExpandable.test.ts +48 -0
- package/src/__tests__/MListItemShape.test.ts +42 -5
- package/src/__tests__/MListKeyboard.test.ts +90 -0
- package/src/__tests__/MMapTools.test.ts +2 -1
- package/src/__tests__/MNavigationRail.test.ts +33 -0
- package/src/__tests__/MScheme.test.ts +107 -0
- package/src/__tests__/MSlider.test.ts +161 -0
- package/src/__tests__/MSparkline.test.ts +96 -0
- package/src/__tests__/MToolbar.test.ts +157 -0
- package/src/__tests__/attrsFallthrough.test.ts +6 -0
- package/src/__tests__/hydration.test.ts +25 -0
- package/src/__tests__/iconButtonNames.test.ts +124 -0
- package/src/__tests__/ssr.test.ts +1 -0
- package/src/__tests__/useConfetti.test.ts +81 -0
- package/src/components/MAnimatedNumber.vue +327 -0
- package/src/components/MAutocomplete.vue +34 -4
- package/src/components/MBottomSheet.vue +1 -0
- package/src/components/MButton.vue +4 -2
- package/src/components/MContainerTransform.vue +321 -0
- package/src/components/MDataTable.vue +1 -1
- package/src/components/MDialog.vue +31 -6
- package/src/components/MFab.vue +10 -5
- package/src/components/MIcon.vue +11 -4
- package/src/components/MIconButton.vue +3 -1
- package/src/components/MList.vue +33 -31
- package/src/components/MListGroup.vue +66 -0
- package/src/components/MListItem.vue +138 -84
- package/src/components/MMaskField.vue +3 -0
- package/src/components/MMultiAutocomplete.vue +5 -1
- package/src/components/MMultiSelect.vue +19 -9
- package/src/components/MNavigationRail.vue +40 -10
- package/src/components/MScheme.vue +162 -0
- package/src/components/MSearchBar.vue +2 -0
- package/src/components/MSelect.vue +44 -10
- package/src/components/MSideSheet.vue +3 -0
- package/src/components/MSimpleCarousel.vue +6 -0
- package/src/components/MSlider.vue +161 -42
- package/src/components/MSparkline.vue +250 -0
- package/src/components/MSplitButton.vue +3 -0
- package/src/components/MSpotlightSearch.vue +1 -0
- package/src/components/MTable.vue +1 -0
- package/src/components/MTagInput.vue +4 -0
- package/src/components/MTextField.vue +3 -0
- package/src/components/MToolbar.vue +256 -15
- package/src/components/MTour.vue +1 -0
- package/src/components/MTreeTable.vue +1 -0
- package/src/components/_MToolbarFab.vue +14 -0
- package/src/components/_MTreeNode.vue +3 -0
- package/src/composables/_containerTransform.ts +179 -0
- package/src/composables/_useEscapeStack.ts +2 -0
- package/src/composables/_useSegmentRuns.ts +39 -0
- package/src/composables/dynamicColor.ts +66 -0
- package/src/composables/useColorPalette.ts +2 -2
- package/src/composables/useConfetti.ts +204 -0
- package/src/composables/useContainerTransform.ts +59 -0
- package/src/composables/useLocale.ts +14 -0
- package/src/index.ts +10 -1
- package/src/locales/de.ts +5 -0
- package/src/locales/es.ts +5 -0
- package/src/locales/fr.ts +5 -0
- package/src/locales/ja.ts +5 -0
- package/src/locales/ko.ts +5 -0
- package/src/locales/pt.ts +5 -0
- package/src/locales/zh.ts +5 -0
- package/dist/MIcon-DLOkQduI.js.map +0 -1
- package/dist/MMenuItem-DVxKEv1W.js.map +0 -1
- package/dist/MSlider-BXsBv0ox.js +0 -1402
- package/dist/MSlider-BXsBv0ox.js.map +0 -1
- package/dist/MTextField-rML9jnXs.js.map +0 -1
- package/dist/material-color-utilities-Cktu8DBU.js.map +0 -1
- package/dist/useLocale-CqQrhWFl.js.map +0 -1
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach, vi } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick } from 'vue'
|
|
4
|
+
import MContainerTransform from '../components/MContainerTransform.vue'
|
|
5
|
+
import { useContainerTransform } from '../composables/useContainerTransform'
|
|
6
|
+
import { containerFrame, emphasized } from '../composables/_containerTransform'
|
|
7
|
+
|
|
8
|
+
let wrapper: VueWrapper | undefined
|
|
9
|
+
const boundingRect = HTMLElement.prototype.getBoundingClientRect
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
HTMLElement.prototype.getBoundingClientRect = boundingRect
|
|
12
|
+
wrapper?.unmount()
|
|
13
|
+
wrapper = undefined
|
|
14
|
+
document.body.style.overflow = ''
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const card = { left: 20, top: 300, width: 160, height: 200 }
|
|
18
|
+
const page = { left: 0, top: 0, width: 400, height: 800 }
|
|
19
|
+
|
|
20
|
+
const flush = async () => { await nextTick(); await nextTick() }
|
|
21
|
+
const panel = () => document.body.querySelector('[role=dialog]') as HTMLElement | null
|
|
22
|
+
const animations = () => [...document.body.querySelectorAll('*')].flatMap((el) => (el as HTMLElement).getAnimations?.() ?? [])
|
|
23
|
+
const running = () => animations().filter((a) => a.playState === 'running')
|
|
24
|
+
const finishAll = async () => { animations().forEach((a) => a.playState !== 'finished' && a.finish()); await new Promise((r) => setTimeout(r)); await flush() }
|
|
25
|
+
|
|
26
|
+
describe('container transform engine', () => {
|
|
27
|
+
it('starts on the source box and ends on the destination box', () => {
|
|
28
|
+
const first = containerFrame(0, card, page, 12, 0, true)
|
|
29
|
+
expect(first.clip).toEqual(card)
|
|
30
|
+
expect(first.radius).toBe(12)
|
|
31
|
+
expect(first.end.opacity).toBe(0)
|
|
32
|
+
expect(first.scrim).toBe(0)
|
|
33
|
+
const last = containerFrame(1, card, page, 12, 0, true)
|
|
34
|
+
expect(last.clip).toEqual(page)
|
|
35
|
+
expect(last.radius).toBe(0)
|
|
36
|
+
expect(last.end).toEqual({ x: 0, y: 0, scale: 1, opacity: 1 })
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('scales both views uniformly to the same width (fit to width), so nothing stretches', () => {
|
|
40
|
+
const f = containerFrame(0.5, card, page, 12, 0, true)
|
|
41
|
+
expect(card.width * f.start.scale).toBeCloseTo(page.width * f.end.scale)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('fades the detail in over the first quarter opening, out late closing (Android thresholds)', () => {
|
|
45
|
+
expect(containerFrame(0.25, card, page, 12, 0, true).end.opacity).toBe(1)
|
|
46
|
+
expect(containerFrame(0.125, card, page, 12, 0, true).end.opacity).toBeCloseTo(0.5)
|
|
47
|
+
expect(containerFrame(0.5, page, card, 0, 12, false).start.opacity).toBe(1)
|
|
48
|
+
expect(containerFrame(0.75, page, card, 0, 12, false).start.opacity).toBeCloseTo(0.5)
|
|
49
|
+
expect(containerFrame(0.95, page, card, 0, 12, false).start.opacity).toBe(0)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('follows Android\'s emphasized path through its control points', () => {
|
|
53
|
+
expect(emphasized(0)).toBe(0)
|
|
54
|
+
expect(emphasized(0.166666)).toBeCloseTo(0.4, 3)
|
|
55
|
+
expect(emphasized(1)).toBe(1)
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
describe('MContainerTransform', () => {
|
|
60
|
+
const mountCard = (props: Record<string, unknown> = {}) =>
|
|
61
|
+
mount(MContainerTransform, {
|
|
62
|
+
props,
|
|
63
|
+
slots: {
|
|
64
|
+
default: ({ open }: { open: () => void }) => h('button', { class: 'card', onClick: open }, 'Card'),
|
|
65
|
+
expanded: ({ close }: { close: () => void }) => h('div', [h('p', 'Detail'), h('button', { class: 'back', onClick: close }, 'Back')]),
|
|
66
|
+
},
|
|
67
|
+
attachTo: document.body,
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('grows the element into the expanded view and shrinks it back', async () => {
|
|
71
|
+
wrapper = mountCard()
|
|
72
|
+
const source = wrapper.find('.card').element as HTMLElement
|
|
73
|
+
// The card has its box, everything else (the panel) fills the screen
|
|
74
|
+
HTMLElement.prototype.getBoundingClientRect = function (this: HTMLElement) {
|
|
75
|
+
const b = this === source ? card : page
|
|
76
|
+
return { ...b, right: b.left + b.width, bottom: b.top + b.height, x: b.left, y: b.top, toJSON() {} } as DOMRect
|
|
77
|
+
}
|
|
78
|
+
await wrapper.find('.card').trigger('click')
|
|
79
|
+
await flush()
|
|
80
|
+
expect(panel()?.textContent).toContain('Detail')
|
|
81
|
+
expect(wrapper.emitted('update:open')).toEqual([[true]])
|
|
82
|
+
// The element hides while its clone plays the transition, then the clone goes
|
|
83
|
+
expect(source.style.visibility).toBe('hidden')
|
|
84
|
+
expect(document.body.querySelector('[aria-hidden=true].card')).not.toBeNull()
|
|
85
|
+
expect(running().length).toBeGreaterThan(0)
|
|
86
|
+
expect(document.body.style.overflow).toBe('hidden')
|
|
87
|
+
await finishAll()
|
|
88
|
+
expect(document.body.querySelector('[aria-hidden=true].card')).toBeNull()
|
|
89
|
+
|
|
90
|
+
;(document.body.querySelector('.back') as HTMLElement).click()
|
|
91
|
+
await flush()
|
|
92
|
+
expect(panel()).not.toBeNull()
|
|
93
|
+
await finishAll()
|
|
94
|
+
expect(panel()).toBeNull()
|
|
95
|
+
expect(source.style.visibility).toBe('')
|
|
96
|
+
expect(document.activeElement).toBe(source)
|
|
97
|
+
expect(document.body.style.overflow).toBe('')
|
|
98
|
+
expect(wrapper.emitted('update:open')).toEqual([[true], [false]])
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('survives rapid opening and closing, ending in the last state asked', async () => {
|
|
102
|
+
wrapper = mountCard({ 'onUpdate:open': (v: boolean) => wrapper!.setProps({ open: v }) })
|
|
103
|
+
const source = wrapper.find('.card').element as HTMLElement
|
|
104
|
+
HTMLElement.prototype.getBoundingClientRect = function (this: HTMLElement) {
|
|
105
|
+
const b = this === source ? card : page
|
|
106
|
+
return { ...b, right: b.left + b.width, bottom: b.top + b.height, x: b.left, y: b.top, toJSON() {} } as DOMRect
|
|
107
|
+
}
|
|
108
|
+
// Open and close over and over without letting a transition finish
|
|
109
|
+
for (let i = 0; i < 4; i++) {
|
|
110
|
+
await wrapper.setProps({ open: true })
|
|
111
|
+
await flush()
|
|
112
|
+
await wrapper.setProps({ open: false })
|
|
113
|
+
await flush()
|
|
114
|
+
}
|
|
115
|
+
await wrapper.setProps({ open: true })
|
|
116
|
+
await flush()
|
|
117
|
+
await finishAll()
|
|
118
|
+
expect(panel()).not.toBeNull()
|
|
119
|
+
expect(running()).toHaveLength(0)
|
|
120
|
+
// And it still closes
|
|
121
|
+
await wrapper.setProps({ open: false })
|
|
122
|
+
await flush()
|
|
123
|
+
await finishAll()
|
|
124
|
+
expect(panel()).toBeNull()
|
|
125
|
+
expect(source.style.visibility).toBe('')
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('closes when closed mid-opening, instead of jumping open and staying there', async () => {
|
|
129
|
+
wrapper = mountCard({ 'onUpdate:open': (v: boolean) => wrapper!.setProps({ open: v }) })
|
|
130
|
+
const source = wrapper.find('.card').element as HTMLElement
|
|
131
|
+
HTMLElement.prototype.getBoundingClientRect = function (this: HTMLElement) {
|
|
132
|
+
const b = this === source ? card : page
|
|
133
|
+
return { ...b, right: b.left + b.width, bottom: b.top + b.height, x: b.left, y: b.top, toJSON() {} } as DOMRect
|
|
134
|
+
}
|
|
135
|
+
await wrapper.find('.card').trigger('click')
|
|
136
|
+
await flush()
|
|
137
|
+
expect(running().length).toBeGreaterThan(0)
|
|
138
|
+
// The back button inside, before the opening ends: the run turns around
|
|
139
|
+
;(document.body.querySelector('.back') as HTMLElement).click()
|
|
140
|
+
await flush()
|
|
141
|
+
await finishAll()
|
|
142
|
+
expect(panel()).toBeNull()
|
|
143
|
+
expect(source.style.visibility).toBe('')
|
|
144
|
+
// And it opens again normally
|
|
145
|
+
await wrapper.find('.card').trigger('click')
|
|
146
|
+
await flush()
|
|
147
|
+
await finishAll()
|
|
148
|
+
expect(panel()).not.toBeNull()
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('closes on Escape', async () => {
|
|
152
|
+
wrapper = mountCard({ open: true })
|
|
153
|
+
await flush()
|
|
154
|
+
expect(panel()).not.toBeNull()
|
|
155
|
+
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))
|
|
156
|
+
await finishAll()
|
|
157
|
+
expect(panel()).toBeNull()
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
it('closes on a scrim click in dialog mode, unless persistent', async () => {
|
|
161
|
+
wrapper = mountCard({ open: true, mode: 'dialog', 'onUpdate:open': (v: boolean) => wrapper!.setProps({ open: v }) })
|
|
162
|
+
await flush()
|
|
163
|
+
;(document.body.querySelector('.bg-black') as HTMLElement).click()
|
|
164
|
+
await finishAll()
|
|
165
|
+
expect(panel()).toBeNull()
|
|
166
|
+
await wrapper.setProps({ open: true, persistent: true })
|
|
167
|
+
await flush()
|
|
168
|
+
;(document.body.querySelector('.bg-black') as HTMLElement).click()
|
|
169
|
+
await finishAll()
|
|
170
|
+
expect(panel()).not.toBeNull()
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
it('leaves placing the expanded view to the consumer\'s classes in custom mode', async () => {
|
|
174
|
+
wrapper = mount(MContainerTransform, {
|
|
175
|
+
props: { open: true, mode: 'custom' },
|
|
176
|
+
attrs: { class: 'bottom-4 right-4 w-80 bg-primary-container' },
|
|
177
|
+
slots: { default: () => h('button', 'Card'), expanded: () => h('p', 'Chat') },
|
|
178
|
+
attachTo: document.body,
|
|
179
|
+
})
|
|
180
|
+
await flush()
|
|
181
|
+
const cls = panel()!.className
|
|
182
|
+
expect(cls).toContain('bottom-4 right-4 w-80 bg-primary-container')
|
|
183
|
+
expect(cls).not.toContain('inset-0')
|
|
184
|
+
// Its default look is in the base layer (a class of its own), so the consumer's bg-* wins
|
|
185
|
+
expect(cls).toContain('m3-ct-panel')
|
|
186
|
+
expect(cls).not.toMatch(/(^|\s)bg-surface/)
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
it('without a scrim, leaves the page usable and closes on a press outside, unless persistent', async () => {
|
|
190
|
+
const outside = document.createElement('button')
|
|
191
|
+
document.body.appendChild(outside)
|
|
192
|
+
wrapper = mountCard({ open: true, mode: 'custom', scrim: false, 'onUpdate:open': (v: boolean) => wrapper!.setProps({ open: v }) })
|
|
193
|
+
await flush()
|
|
194
|
+
expect(panel()!.hasAttribute('aria-modal')).toBe(false)
|
|
195
|
+
expect(document.body.style.overflow).toBe('')
|
|
196
|
+
// A press inside stays open
|
|
197
|
+
panel()!.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }))
|
|
198
|
+
await flush()
|
|
199
|
+
expect(panel()).not.toBeNull()
|
|
200
|
+
outside.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }))
|
|
201
|
+
await finishAll()
|
|
202
|
+
expect(panel()).toBeNull()
|
|
203
|
+
await wrapper.setProps({ open: true, persistent: true })
|
|
204
|
+
await flush()
|
|
205
|
+
outside.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }))
|
|
206
|
+
await finishAll()
|
|
207
|
+
expect(panel()).not.toBeNull()
|
|
208
|
+
outside.remove()
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
describe('Android\'s back', () => {
|
|
212
|
+
// The platform's close requests (CloseWatcher, Chrome/Edge): a fake one we can fire
|
|
213
|
+
class FakeWatcher {
|
|
214
|
+
static all: FakeWatcher[] = []
|
|
215
|
+
onclose: (() => void) | null = null
|
|
216
|
+
destroyed = false
|
|
217
|
+
constructor() { FakeWatcher.all.push(this) }
|
|
218
|
+
destroy() { this.destroyed = true }
|
|
219
|
+
requestClose() { if (!this.destroyed) this.onclose?.() }
|
|
220
|
+
}
|
|
221
|
+
afterEach(() => {
|
|
222
|
+
FakeWatcher.all = []
|
|
223
|
+
delete (window as { CloseWatcher?: unknown }).CloseWatcher
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
it('closes it through a CloseWatcher, without touching the history', async () => {
|
|
227
|
+
;(window as { CloseWatcher?: unknown }).CloseWatcher = FakeWatcher
|
|
228
|
+
const push = vi.spyOn(history, 'pushState')
|
|
229
|
+
const back = vi.spyOn(history, 'back')
|
|
230
|
+
wrapper = mountCard({ 'onUpdate:open': (v: boolean) => wrapper!.setProps({ open: v }) })
|
|
231
|
+
await wrapper.find('.card').trigger('click')
|
|
232
|
+
await flush()
|
|
233
|
+
expect(FakeWatcher.all).toHaveLength(1)
|
|
234
|
+
FakeWatcher.all[0]!.requestClose()
|
|
235
|
+
await finishAll()
|
|
236
|
+
expect(panel()).toBeNull()
|
|
237
|
+
expect(push).not.toHaveBeenCalled()
|
|
238
|
+
expect(back).not.toHaveBeenCalled()
|
|
239
|
+
push.mockRestore()
|
|
240
|
+
back.mockRestore()
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
it('lets go of its watcher when closed some other way', async () => {
|
|
244
|
+
;(window as { CloseWatcher?: unknown }).CloseWatcher = FakeWatcher
|
|
245
|
+
wrapper = mountCard({ 'onUpdate:open': (v: boolean) => wrapper!.setProps({ open: v }) })
|
|
246
|
+
await wrapper.find('.card').trigger('click')
|
|
247
|
+
await flush()
|
|
248
|
+
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))
|
|
249
|
+
await finishAll()
|
|
250
|
+
expect(FakeWatcher.all[0]!.destroyed).toBe(true)
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
it('makes no watcher with closeOnBack off', async () => {
|
|
254
|
+
;(window as { CloseWatcher?: unknown }).CloseWatcher = FakeWatcher
|
|
255
|
+
wrapper = mountCard({ closeOnBack: false })
|
|
256
|
+
await wrapper.find('.card').trigger('click')
|
|
257
|
+
await flush()
|
|
258
|
+
expect(FakeWatcher.all).toHaveLength(0)
|
|
259
|
+
})
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
it('opens from elements elsewhere through a controller, with their item', async () => {
|
|
263
|
+
const Page = defineComponent({
|
|
264
|
+
setup() {
|
|
265
|
+
const detail = useContainerTransform<{ name: string }>()
|
|
266
|
+
return () => [
|
|
267
|
+
h('button', { class: 'a', onClick: (e: Event) => detail.open(e, { name: 'Alpha' }) }, 'A'),
|
|
268
|
+
h('button', { class: 'b', onClick: (e: Event) => detail.open(e, { name: 'Beta' }) }, 'B'),
|
|
269
|
+
h(MContainerTransform, { controller: detail }, { expanded: ({ item }: { item?: { name: string } }) => h('p', item?.name) }),
|
|
270
|
+
]
|
|
271
|
+
},
|
|
272
|
+
})
|
|
273
|
+
wrapper = mount(Page, { attachTo: document.body })
|
|
274
|
+
await wrapper.find('.b').trigger('click')
|
|
275
|
+
await flush()
|
|
276
|
+
expect(panel()?.textContent).toBe('Beta')
|
|
277
|
+
expect((wrapper.find('.b').element as HTMLElement).style.visibility).toBe('hidden')
|
|
278
|
+
})
|
|
279
|
+
})
|
|
@@ -103,4 +103,31 @@ describe('MDialog', () => {
|
|
|
103
103
|
expect(w.emitted('update:modelValue')?.[0]).toEqual([false])
|
|
104
104
|
w.unmount()
|
|
105
105
|
})
|
|
106
|
+
|
|
107
|
+
it('bare with fullscreen: the content fills the screen and draws its own top bar', () => {
|
|
108
|
+
const w = mount(MDialog, {
|
|
109
|
+
props: { modelValue: true, bare: true, fullscreen: true, title: 'Edit event' },
|
|
110
|
+
slots: { default: '<header class="mine">My bar</header>' },
|
|
111
|
+
attachTo: document.body,
|
|
112
|
+
})
|
|
113
|
+
const screen = document.body.querySelector('.dialog-fs') as HTMLElement
|
|
114
|
+
expect(screen.querySelector('.mine')).not.toBeNull()
|
|
115
|
+
expect(screen.querySelector('h2')).toBeNull()
|
|
116
|
+
expect(screen.querySelector('button')).toBeNull()
|
|
117
|
+
expect(screen.getAttribute('aria-label')).toBe('Edit event')
|
|
118
|
+
w.unmount()
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('puts the consumer\'s classes on its surface, over the default background', () => {
|
|
122
|
+
const w = mount(MDialog, {
|
|
123
|
+
props: { modelValue: true, title: 'T', fullscreen: true },
|
|
124
|
+
attrs: { class: 'bg-tertiary-container' },
|
|
125
|
+
attachTo: document.body,
|
|
126
|
+
})
|
|
127
|
+
const screen = document.body.querySelector('.dialog-fs') as HTMLElement
|
|
128
|
+
expect(screen.classList.contains('bg-tertiary-container')).toBe(true)
|
|
129
|
+
// The default is a base-layer class, not a competing bg-* utility
|
|
130
|
+
expect([...screen.classList].filter((c) => c.startsWith('bg-'))).toEqual(['bg-tertiary-container'])
|
|
131
|
+
w.unmount()
|
|
132
|
+
})
|
|
106
133
|
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MIcon from '../components/MIcon.vue'
|
|
4
|
+
|
|
5
|
+
describe('MIcon', () => {
|
|
6
|
+
// The glyph is a ligature: its text is the icon's name, which screen readers read aloud ("arrow_drop_down")
|
|
7
|
+
it('is hidden from assistive technology by default', () => {
|
|
8
|
+
const w = mount(MIcon, { props: { name: 'arrow_drop_down' } })
|
|
9
|
+
expect(w.attributes('aria-hidden')).toBe('true')
|
|
10
|
+
expect(w.attributes('role')).toBeUndefined()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('becomes a named image with label', () => {
|
|
14
|
+
const w = mount(MIcon, { props: { name: 'trending_up', label: 'Up 4%' } })
|
|
15
|
+
expect(w.attributes('role')).toBe('img')
|
|
16
|
+
expect(w.attributes('aria-label')).toBe('Up 4%')
|
|
17
|
+
expect(w.attributes('aria-hidden')).toBeUndefined()
|
|
18
|
+
})
|
|
19
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { h } from 'vue'
|
|
4
|
+
import MListItem from '../components/MListItem.vue'
|
|
5
|
+
|
|
6
|
+
let wrapper: VueWrapper | undefined
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
wrapper?.unmount()
|
|
9
|
+
wrapper = undefined
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
const mountExpandable = (props: Record<string, unknown> = {}) =>
|
|
13
|
+
mount(MListItem, {
|
|
14
|
+
props: { title: 'Settings', expandable: true, ...props },
|
|
15
|
+
slots: { children: () => h('p', 'Wi-Fi') },
|
|
16
|
+
global: { stubs: { transition: false } },
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
describe('MListItem expandable', () => {
|
|
20
|
+
it('makes its header a button that says whether its children are shown', async () => {
|
|
21
|
+
wrapper = mountExpandable()
|
|
22
|
+
const header = wrapper.find('[role=button]')
|
|
23
|
+
expect(header.attributes('tabindex')).toBe('0')
|
|
24
|
+
expect(header.attributes('aria-expanded')).toBe('false')
|
|
25
|
+
await header.trigger('click')
|
|
26
|
+
expect(header.attributes('aria-expanded')).toBe('true')
|
|
27
|
+
expect(wrapper.find(`#${header.attributes('aria-controls')}`).text()).toBe('Wi-Fi')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('toggles from the keyboard with Enter and Space', async () => {
|
|
31
|
+
wrapper = mountExpandable()
|
|
32
|
+
const header = wrapper.find('[role=button]')
|
|
33
|
+
await header.trigger('keydown', { key: 'Enter' })
|
|
34
|
+
expect(wrapper.emitted('update:expanded')).toEqual([[true]])
|
|
35
|
+
expect(wrapper.text()).toContain('Wi-Fi')
|
|
36
|
+
await header.trigger('keydown', { key: ' ' })
|
|
37
|
+
expect(wrapper.emitted('update:expanded')).toEqual([[true], [false]])
|
|
38
|
+
await header.trigger('keydown', { key: 'a' })
|
|
39
|
+
expect(wrapper.emitted('update:expanded')).toHaveLength(2)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('is out of the tab order while disabled', () => {
|
|
43
|
+
wrapper = mountExpandable({ disabled: true })
|
|
44
|
+
const header = wrapper.find('[role=button]')
|
|
45
|
+
expect(header.attributes('tabindex')).toBe('-1')
|
|
46
|
+
expect(header.attributes('aria-disabled')).toBe('true')
|
|
47
|
+
})
|
|
48
|
+
})
|
|
@@ -4,6 +4,7 @@ import { h } from 'vue'
|
|
|
4
4
|
import MList from '../components/MList.vue'
|
|
5
5
|
import MListItem from '../components/MListItem.vue'
|
|
6
6
|
import MListSubheader from '../components/MListSubheader.vue'
|
|
7
|
+
import MListGroup from '../components/MListGroup.vue'
|
|
7
8
|
|
|
8
9
|
let wrapper: VueWrapper | undefined
|
|
9
10
|
afterEach(() => {
|
|
@@ -19,7 +20,8 @@ const radius = (el: Element) => (el as HTMLElement).style.borderRadius
|
|
|
19
20
|
describe('MListItem shape morph', () => {
|
|
20
21
|
it('rests at 4px and grows on hover and press when clickable', async () => {
|
|
21
22
|
wrapper = mount(MListItem, { props: { title: 'A', clickable: true }, attachTo: document.body })
|
|
22
|
-
|
|
23
|
+
// A clickable row is a button inside its <li>
|
|
24
|
+
const row = wrapper.find('[role="button"]').element
|
|
23
25
|
await settle()
|
|
24
26
|
expect(radius(row)).toBe('4px')
|
|
25
27
|
row.dispatchEvent(new PointerEvent('pointerenter', { pointerType: 'mouse' }))
|
|
@@ -32,12 +34,13 @@ describe('MListItem shape morph', () => {
|
|
|
32
34
|
|
|
33
35
|
it('ignores hover when not interactive, but morphs when selected', async () => {
|
|
34
36
|
wrapper = mount(MListItem, { props: { title: 'A' }, attachTo: document.body })
|
|
35
|
-
wrapper.
|
|
37
|
+
const row = wrapper.find('.mli-row').element
|
|
38
|
+
row.dispatchEvent(new PointerEvent('pointerenter', { pointerType: 'mouse' }))
|
|
36
39
|
await settle()
|
|
37
|
-
expect(radius(
|
|
40
|
+
expect(radius(row)).toBe('4px')
|
|
38
41
|
await wrapper.setProps({ active: true })
|
|
39
42
|
await settle()
|
|
40
|
-
expect(radius(
|
|
43
|
+
expect(radius(row)).toBe('16px')
|
|
41
44
|
})
|
|
42
45
|
|
|
43
46
|
it('rounds the outer corners of each segmented run', async () => {
|
|
@@ -64,6 +67,40 @@ describe('MListItem shape morph', () => {
|
|
|
64
67
|
])
|
|
65
68
|
})
|
|
66
69
|
|
|
70
|
+
it('gives each MListGroup a segmented run of its own', async () => {
|
|
71
|
+
wrapper = mount(MList, {
|
|
72
|
+
props: { segmented: true },
|
|
73
|
+
slots: {
|
|
74
|
+
default: () => [
|
|
75
|
+
h(MListItem, { title: 'Alone' }),
|
|
76
|
+
h(MListGroup, null, () => [h(MListItem, { title: 'A' }), h(MListItem, { title: 'B' }), h(MListItem, { title: 'C' })]),
|
|
77
|
+
h(MListGroup, { title: 'Privacy' }, () => [h(MListItem, { title: 'D' })]),
|
|
78
|
+
h(MListItem, { title: 'After' }),
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
attachTo: document.body,
|
|
82
|
+
})
|
|
83
|
+
await settle()
|
|
84
|
+
const rows = wrapper.findAll('[role="listitem"]').map((w) => w.element)
|
|
85
|
+
expect(rows.map(radius)).toEqual(['16px', '16px 16px 4px 4px', '4px', '4px 4px 16px 16px', '16px', '16px'])
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('names an MListGroup by its title and keeps the list\'s selection inside it', async () => {
|
|
89
|
+
wrapper = mount(MList, {
|
|
90
|
+
props: { selectable: true, selected: 'b' },
|
|
91
|
+
slots: { default: () => [h(MListGroup, { title: 'Privacy' }, () => [h(MListItem, { title: 'A', value: 'a' }), h(MListItem, { title: 'B', value: 'b' })])] },
|
|
92
|
+
attachTo: document.body,
|
|
93
|
+
})
|
|
94
|
+
const group = wrapper.find('ul ul')
|
|
95
|
+
const title = wrapper.find(`#${group.attributes('aria-labelledby')}`)
|
|
96
|
+
expect(title.text()).toBe('Privacy')
|
|
97
|
+
// A selectable list is a listbox of options
|
|
98
|
+
const rows = wrapper.findAll('[role="option"]')
|
|
99
|
+
expect(rows[1]!.classes()).toContain('bg-secondary-container')
|
|
100
|
+
await rows[0]!.trigger('click')
|
|
101
|
+
expect(wrapper.emitted('update:selected')?.[0]).toEqual(['a'])
|
|
102
|
+
})
|
|
103
|
+
|
|
67
104
|
it('keeps the pill in nav lists', async () => {
|
|
68
105
|
wrapper = mount(MList, {
|
|
69
106
|
props: { nav: true },
|
|
@@ -71,6 +108,6 @@ describe('MListItem shape morph', () => {
|
|
|
71
108
|
attachTo: document.body,
|
|
72
109
|
})
|
|
73
110
|
await settle()
|
|
74
|
-
expect(radius(wrapper.find('
|
|
111
|
+
expect(radius(wrapper.find('.mli-row').element)).toBe('')
|
|
75
112
|
})
|
|
76
113
|
})
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { h, nextTick } from 'vue'
|
|
4
|
+
import MList from '../components/MList.vue'
|
|
5
|
+
import MListItem from '../components/MListItem.vue'
|
|
6
|
+
|
|
7
|
+
let wrapper: VueWrapper | undefined
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
wrapper?.unmount()
|
|
10
|
+
wrapper = undefined
|
|
11
|
+
document.body.innerHTML = ''
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
describe('MList and MListItem from the keyboard', () => {
|
|
15
|
+
const selectableList = (selected: string | null) =>
|
|
16
|
+
mount(MList, {
|
|
17
|
+
props: { selectable: true, selected, 'onUpdate:selected': (v: string) => wrapper!.setProps({ selected: v }) },
|
|
18
|
+
slots: { default: () => ['a', 'b', 'c'].map((v) => h(MListItem, { title: v.toUpperCase(), value: v, disabled: v === 'c' })) },
|
|
19
|
+
attachTo: document.body,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('makes a selectable list a listbox of options with one Tab stop, the selected one', async () => {
|
|
23
|
+
wrapper = selectableList('b')
|
|
24
|
+
await nextTick()
|
|
25
|
+
expect(wrapper.find('ul').attributes('role')).toBe('listbox')
|
|
26
|
+
const options = wrapper.findAll('[role="option"]')
|
|
27
|
+
expect(options.map((o) => o.attributes('aria-selected'))).toEqual(['false', 'true', 'false'])
|
|
28
|
+
expect(options.map((o) => o.attributes('tabindex'))).toEqual(['-1', '0', '-1'])
|
|
29
|
+
expect(options[2]!.attributes('aria-disabled')).toBe('true')
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('gives the Tab stop to the first option when nothing is selected', async () => {
|
|
33
|
+
wrapper = selectableList(null)
|
|
34
|
+
await nextTick()
|
|
35
|
+
expect((wrapper.findAll('[role="option"]')[0]!.element as HTMLElement).tabIndex).toBe(0)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('moves between options with the arrows (skipping disabled ones) and selects with Enter and Space', async () => {
|
|
39
|
+
wrapper = selectableList('a')
|
|
40
|
+
await nextTick()
|
|
41
|
+
const options = wrapper.findAll('[role="option"]').map((o) => o.element as HTMLElement)
|
|
42
|
+
options[0]!.focus()
|
|
43
|
+
options[0]!.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true }))
|
|
44
|
+
expect(document.activeElement).toBe(options[1])
|
|
45
|
+
// c is disabled: nowhere further down
|
|
46
|
+
options[1]!.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true }))
|
|
47
|
+
expect(document.activeElement).toBe(options[1])
|
|
48
|
+
options[1]!.dispatchEvent(new KeyboardEvent('keydown', { key: ' ', bubbles: true }))
|
|
49
|
+
expect(wrapper.emitted('update:selected')?.[0]).toEqual(['b'])
|
|
50
|
+
options[1]!.dispatchEvent(new KeyboardEvent('keydown', { key: 'Home', bubbles: true }))
|
|
51
|
+
expect(document.activeElement).toBe(options[0])
|
|
52
|
+
options[0]!.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }))
|
|
53
|
+
expect(wrapper.emitted('update:selected')?.[1]).toEqual(['a'])
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('makes a clickable row a button inside its list item, operable from the keyboard', async () => {
|
|
57
|
+
let clicks = 0
|
|
58
|
+
wrapper = mount(MList, { slots: { default: () => h(MListItem, { title: 'Open', onClick: () => clicks++ }) }, attachTo: document.body })
|
|
59
|
+
const li = wrapper.find('ul > li')
|
|
60
|
+
expect(li.attributes('role')).toBe('listitem')
|
|
61
|
+
const row = li.find('[role="button"]')
|
|
62
|
+
expect(row.attributes('tabindex')).toBe('0')
|
|
63
|
+
// @click alone makes it interactive (hover and press styles)
|
|
64
|
+
expect(row.classes()).toContain('cursor-pointer')
|
|
65
|
+
await row.trigger('keydown', { key: 'Enter' })
|
|
66
|
+
await row.trigger('keydown', { key: ' ' })
|
|
67
|
+
expect(clicks).toBe(2)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('keeps a link a link, inside its list item', () => {
|
|
71
|
+
wrapper = mount(MList, { slots: { default: () => h(MListItem, { title: 'Docs', href: '/docs' }) }, attachTo: document.body })
|
|
72
|
+
const a = wrapper.find('ul > li[role="listitem"] > a')
|
|
73
|
+
expect(a.attributes('href')).toBe('/docs')
|
|
74
|
+
expect(a.attributes('role')).toBeUndefined()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('leaves a plain row a plain list item, out of the tab order', () => {
|
|
78
|
+
wrapper = mount(MList, { slots: { default: () => h(MListItem, { title: 'Info' }) }, attachTo: document.body })
|
|
79
|
+
const li = wrapper.find('ul > li')
|
|
80
|
+
expect(li.attributes('role')).toBe('listitem')
|
|
81
|
+
expect(li.attributes('tabindex')).toBeUndefined()
|
|
82
|
+
expect(li.classes()).toContain('mli-row')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('puts the consumer\'s classes on the row', () => {
|
|
86
|
+
wrapper = mount(MList, { slots: { default: () => h(MListItem, { title: 'Open', onClick: () => {}, class: 'mine' }) }, attachTo: document.body })
|
|
87
|
+
expect(wrapper.find('[role="button"]').classes()).toContain('mine')
|
|
88
|
+
expect(wrapper.find('ul > li').classes()).not.toContain('mine')
|
|
89
|
+
})
|
|
90
|
+
})
|
|
@@ -207,7 +207,8 @@ describe('MMapSearch', () => {
|
|
|
207
207
|
input.form!.dispatchEvent(new Event('submit', { cancelable: true }))
|
|
208
208
|
await flushPromises()
|
|
209
209
|
expect(provider).toHaveBeenCalledWith('plaza', expect.any(AbortSignal))
|
|
210
|
-
|
|
210
|
+
// The innermost match: a clickable row is a button inside its <li>
|
|
211
|
+
const item = [...document.querySelectorAll<HTMLElement>('li, [role="listitem"], [role="button"]')].filter((e) => e.textContent?.includes('Plaza San Martín')).at(-1)!
|
|
211
212
|
expect(item).toBeTruthy()
|
|
212
213
|
item.click()
|
|
213
214
|
await nextTick()
|
|
@@ -90,4 +90,37 @@ describe('MNavigationRail', () => {
|
|
|
90
90
|
panel.dispatchEvent(new PointerEvent('pointerup', { ...opts, clientX: 40, clientY: 200 }))
|
|
91
91
|
expect(wrapper!.emitted('update:expanded')).toBeUndefined()
|
|
92
92
|
})
|
|
93
|
+
|
|
94
|
+
describe('expanded width', () => {
|
|
95
|
+
// happy-dom has no layout: give each label a natural width
|
|
96
|
+
const labelWidths = (w: VueWrapper, widths: number[]) =>
|
|
97
|
+
w.findAll('[data-rail-label]').forEach((l, i) => Object.defineProperty(l.element, 'scrollWidth', { configurable: true, get: () => widths[i] ?? 0 }))
|
|
98
|
+
const mountInline = (labels: string[]) =>
|
|
99
|
+
mount(MNavigationRail, { props: { modelValue: 'a', items: labels.map((label, i) => ({ value: String.fromCharCode(97 + i), label, icon: 'home' })) }, attachTo: document.body })
|
|
100
|
+
|
|
101
|
+
it('fits the longest label between 220 and 360px, like Compose\'s WideNavigationRail', async () => {
|
|
102
|
+
wrapper = mountInline(['Home', 'Notifications and alerts'])
|
|
103
|
+
labelWidths(wrapper, [38, 180])
|
|
104
|
+
// Labels change: remeasured
|
|
105
|
+
await wrapper.setProps({ items: [{ value: 'a', label: 'Home', icon: 'home' }, { value: 'b', label: 'Notifications and alerts!', icon: 'notifications' }] })
|
|
106
|
+
labelWidths(wrapper, [38, 180])
|
|
107
|
+
await wrapper.setProps({ items: [{ value: 'a', label: 'Home', icon: 'home' }, { value: 'b', label: 'Notifications and alerts', icon: 'notifications' }] })
|
|
108
|
+
await new Promise((r) => setTimeout(r))
|
|
109
|
+
await wrapper.setProps({ expanded: true })
|
|
110
|
+
expect((wrapper.find('nav').element as HTMLElement).style.width).toBe(`${180 + 88}px`)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('never goes under 220px nor over 360px', async () => {
|
|
114
|
+
wrapper = mountInline(['Home'])
|
|
115
|
+
labelWidths(wrapper, [38])
|
|
116
|
+
await wrapper.setProps({ items: [{ value: 'a', label: 'Home!', icon: 'home' }] })
|
|
117
|
+
await new Promise((r) => setTimeout(r))
|
|
118
|
+
await wrapper.setProps({ expanded: true })
|
|
119
|
+
expect((wrapper.find('nav').element as HTMLElement).style.width).toBe('220px')
|
|
120
|
+
labelWidths(wrapper, [900])
|
|
121
|
+
await wrapper.setProps({ items: [{ value: 'a', label: 'A very long label', icon: 'home' }] })
|
|
122
|
+
await new Promise((r) => setTimeout(r))
|
|
123
|
+
expect((wrapper.find('nav').element as HTMLElement).style.width).toBe('360px')
|
|
124
|
+
})
|
|
125
|
+
})
|
|
93
126
|
})
|