@m3ui-vue/m3ui-vue 1.1.3 → 1.2.0

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.
Files changed (236) hide show
  1. package/README.md +1 -1
  2. package/dist/API.md +579 -40
  3. package/dist/MMenuItem-DI351kIf.js +929 -0
  4. package/dist/MMenuItem-DI351kIf.js.map +1 -0
  5. package/dist/MSlider-BnEy5ieZ.js +1500 -0
  6. package/dist/MSlider-BnEy5ieZ.js.map +1 -0
  7. package/dist/MTextField-BBmkaIbO.js +633 -0
  8. package/dist/MTextField-BBmkaIbO.js.map +1 -0
  9. package/dist/api.json +1 -1
  10. package/dist/chart.js +83 -49
  11. package/dist/chart.js.map +1 -1
  12. package/dist/code-editor.js +1 -1
  13. package/dist/components/MAnimatedNumber.vue.d.ts +3 -1
  14. package/dist/components/MButton.vue.d.ts +9 -1
  15. package/dist/components/MButtonGroup.vue.d.ts +40 -31
  16. package/dist/components/MCarousel.vue.d.ts +2 -0
  17. package/dist/components/MChart.vue.d.ts +6 -0
  18. package/dist/components/MCircleProgressBar.vue.d.ts +5 -3
  19. package/dist/components/MContainerTransform.vue.d.ts +59 -0
  20. package/dist/components/MContextMenu.vue.d.ts +2 -2
  21. package/dist/components/MCopyButton.vue.d.ts +1 -1
  22. package/dist/components/MDialog.vue.d.ts +8 -5
  23. package/dist/components/MExportButton.vue.d.ts +1 -1
  24. package/dist/components/MFab.vue.d.ts +2 -2
  25. package/dist/components/MFabMenu.vue.d.ts +1 -1
  26. package/dist/components/MFlex.vue.d.ts +1 -1
  27. package/dist/components/MIconButton.vue.d.ts +15 -1
  28. package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
  29. package/dist/components/MListItem.vue.d.ts +5 -5
  30. package/dist/components/MMap.vue.d.ts +20 -2
  31. package/dist/components/MMapBaseLayers.vue.d.ts +3 -0
  32. package/dist/components/MMapFilter.vue.d.ts +3 -0
  33. package/dist/components/MMapLayers.vue.d.ts +3 -0
  34. package/dist/components/MMenu.vue.d.ts +2 -2
  35. package/dist/components/MMenuItem.vue.d.ts +7 -3
  36. package/dist/components/MNavigationDrawer.vue.d.ts +13 -2
  37. package/dist/components/MNavigationRail.vue.d.ts +1 -1
  38. package/dist/components/MOverlay.vue.d.ts +12 -1
  39. package/dist/components/MProgressBar.vue.d.ts +5 -3
  40. package/dist/components/MPullToRefresh.vue.d.ts +7 -2
  41. package/dist/components/MRichTextEditor.vue.d.ts +7 -1
  42. package/dist/components/MSearchField.vue.d.ts +58 -0
  43. package/dist/components/MSegmentedButton.vue.d.ts +31 -23
  44. package/dist/components/MSimpleCarousel.vue.d.ts +2 -0
  45. package/dist/components/MSkeleton.vue.d.ts +6 -3
  46. package/dist/components/MSplitter.vue.d.ts +1 -1
  47. package/dist/components/MStack.vue.d.ts +1 -1
  48. package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
  49. package/dist/components/MSwitch.vue.d.ts +1 -1
  50. package/dist/components/MTextField.vue.d.ts +5 -1
  51. package/dist/components/MTimeline.vue.d.ts +85 -22
  52. package/dist/components/MToolbar.vue.d.ts +32 -5
  53. package/dist/components/MTooltip.vue.d.ts +1 -1
  54. package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
  55. package/dist/components/_MToolbarFab.vue.d.ts +16 -0
  56. package/dist/composables/_containerTransform.d.ts +48 -0
  57. package/dist/composables/_mapStyle.d.ts +13 -0
  58. package/dist/composables/_themeTransition.d.ts +2 -0
  59. package/dist/composables/_tooltipTrigger.d.ts +22 -0
  60. package/dist/composables/_useMenuNav.d.ts +28 -0
  61. package/dist/composables/useAutoGrow.d.ts +21 -0
  62. package/dist/composables/useColorPalette.d.ts +1 -1
  63. package/dist/composables/useContainerTransform.d.ts +30 -0
  64. package/dist/composables/useLocale.d.ts +6 -0
  65. package/dist/composables/useMap.d.ts +19 -3
  66. package/dist/composables/useMapFilter.d.ts +4 -1
  67. package/dist/composables/useMapLayers.d.ts +5 -2
  68. package/dist/composables/useScrollReveal.d.ts +44 -0
  69. package/dist/composables/useThemeTokens.d.ts +21 -0
  70. package/dist/composables/viewportHints.d.ts +27 -0
  71. package/dist/directives/vClickOutside.d.ts +25 -0
  72. package/dist/directives/vFocusRing.d.ts +22 -0
  73. package/dist/directives/vLongPress.d.ts +27 -0
  74. package/dist/directives/vReveal.d.ts +10 -0
  75. package/dist/directives/vScrollElevation.d.ts +31 -0
  76. package/dist/directives/vSkeleton.d.ts +19 -0
  77. package/dist/directives/vStateLayer.d.ts +20 -0
  78. package/dist/directives/vSwipe.d.ts +45 -0
  79. package/dist/directives/vTooltip.d.ts +23 -0
  80. package/dist/index.d.ts +31 -1
  81. package/dist/locales/index.js +35 -7
  82. package/dist/locales/index.js.map +1 -1
  83. package/dist/m3ui-vue.css +1 -1
  84. package/dist/m3ui.js +7692 -6273
  85. package/dist/m3ui.js.map +1 -1
  86. package/dist/map.d.ts +1 -1
  87. package/dist/map.js +823 -793
  88. package/dist/map.js.map +1 -1
  89. package/dist/motion-DZiXG09o.js +150 -0
  90. package/dist/motion-DZiXG09o.js.map +1 -0
  91. package/dist/plugin.d.ts +24 -0
  92. package/dist/rich-text-editor.js +20 -16
  93. package/dist/rich-text-editor.js.map +1 -1
  94. package/dist/styles/theme.css +63 -0
  95. package/dist/styles.css +1 -1
  96. package/dist/{useLocale-SfQHnJfp.js → useLocale-JYxDDeXC.js} +6 -2
  97. package/dist/useLocale-JYxDDeXC.js.map +1 -0
  98. package/dist/useThemeTokens-Bv-Uv8eX.js +135 -0
  99. package/dist/useThemeTokens-Bv-Uv8eX.js.map +1 -0
  100. package/package.json +2 -1
  101. package/src/__tests__/MAnimatedNumber.test.ts +24 -2
  102. package/src/__tests__/MButton.test.ts +22 -0
  103. package/src/__tests__/MCarousel.test.ts +9 -0
  104. package/src/__tests__/MChart.test.ts +77 -5
  105. package/src/__tests__/MContainerTransform.test.ts +279 -0
  106. package/src/__tests__/MDialog.test.ts +27 -0
  107. package/src/__tests__/MIconButton.test.ts +33 -0
  108. package/src/__tests__/MListItemExpandable.test.ts +48 -0
  109. package/src/__tests__/MListItemShape.test.ts +9 -6
  110. package/src/__tests__/MListKeyboard.test.ts +90 -0
  111. package/src/__tests__/MMap.test.ts +53 -1
  112. package/src/__tests__/MMapLayers.test.ts +46 -2
  113. package/src/__tests__/MMapTools.test.ts +2 -1
  114. package/src/__tests__/MMenu.test.ts +104 -1
  115. package/src/__tests__/MMenuItem.test.ts +18 -0
  116. package/src/__tests__/MNavigationDrawer.test.ts +80 -0
  117. package/src/__tests__/MNavigationRail.test.ts +33 -0
  118. package/src/__tests__/MOverlay.test.ts +49 -0
  119. package/src/__tests__/MProgressBar.test.ts +41 -0
  120. package/src/__tests__/MPullToRefresh.test.ts +33 -0
  121. package/src/__tests__/MRichTextEditor.test.ts +22 -0
  122. package/src/__tests__/MSearchField.test.ts +71 -0
  123. package/src/__tests__/MSkeleton.test.ts +38 -0
  124. package/src/__tests__/MSlider.test.ts +161 -0
  125. package/src/__tests__/MTimeline.test.ts +238 -0
  126. package/src/__tests__/MToolbar.test.ts +157 -0
  127. package/src/__tests__/_fakeMaplibre.ts +3 -1
  128. package/src/__tests__/attrsFallthrough.test.ts +9 -0
  129. package/src/__tests__/escapeStack.test.ts +93 -0
  130. package/src/__tests__/hydration.test.ts +25 -0
  131. package/src/__tests__/ssr.test.ts +21 -2
  132. package/src/__tests__/useAutoGrow.test.ts +103 -0
  133. package/src/__tests__/useScrollReveal.test.ts +102 -0
  134. package/src/__tests__/useThemeTokens.test.ts +114 -0
  135. package/src/__tests__/vClickOutside.test.ts +82 -0
  136. package/src/__tests__/vFocusRing.test.ts +36 -0
  137. package/src/__tests__/vLongPress.test.ts +81 -0
  138. package/src/__tests__/vScrollElevation.test.ts +89 -0
  139. package/src/__tests__/vSkeleton.test.ts +48 -0
  140. package/src/__tests__/vStateLayer.test.ts +53 -0
  141. package/src/__tests__/vSwipe.test.ts +93 -0
  142. package/src/__tests__/vTooltip.test.ts +95 -0
  143. package/src/__tests__/viewportHints.test.ts +41 -0
  144. package/src/components/MAnimatedNumber.vue +32 -6
  145. package/src/components/MAutocomplete.vue +5 -0
  146. package/src/components/MBottomSheet.vue +4 -1
  147. package/src/components/MButton.vue +19 -3
  148. package/src/components/MButtonGroup.vue +22 -17
  149. package/src/components/MCarousel.vue +7 -1
  150. package/src/components/MChart.vue +74 -34
  151. package/src/components/MCircleProgressBar.vue +14 -9
  152. package/src/components/MCommandPalette.vue +3 -2
  153. package/src/components/MContainerTransform.vue +321 -0
  154. package/src/components/MContextMenu.vue +19 -60
  155. package/src/components/MDialog.vue +31 -6
  156. package/src/components/MDragDropList.vue +2 -0
  157. package/src/components/MFab.vue +10 -5
  158. package/src/components/MIconButton.vue +43 -2
  159. package/src/components/MKanban.vue +2 -0
  160. package/src/components/MLightbox.vue +7 -2
  161. package/src/components/MList.vue +26 -2
  162. package/src/components/MListItem.vue +138 -84
  163. package/src/components/MMap.vue +38 -5
  164. package/src/components/MMapBaseLayers.vue +7 -3
  165. package/src/components/MMapFilter.vue +7 -4
  166. package/src/components/MMapGeoJson.vue +1 -1
  167. package/src/components/MMapLayers.vue +6 -2
  168. package/src/components/MMapMeasure.vue +5 -2
  169. package/src/components/MMenu.vue +18 -59
  170. package/src/components/MMenuItem.vue +11 -2
  171. package/src/components/MMultiAutocomplete.vue +5 -0
  172. package/src/components/MNavigationDrawer.vue +96 -11
  173. package/src/components/MNavigationRail.vue +44 -25
  174. package/src/components/MOverlay.vue +32 -13
  175. package/src/components/MProgressBar.vue +25 -27
  176. package/src/components/MPullToRefresh.vue +20 -1
  177. package/src/components/MRichTextEditor.vue +19 -5
  178. package/src/components/MSearchBar.vue +5 -0
  179. package/src/components/MSearchField.vue +142 -0
  180. package/src/components/MSegmentedButton.vue +19 -17
  181. package/src/components/MSelect.vue +10 -1
  182. package/src/components/MSideSheet.vue +5 -2
  183. package/src/components/MSimpleCarousel.vue +10 -1
  184. package/src/components/MSkeleton.vue +30 -8
  185. package/src/components/MSlider.vue +161 -42
  186. package/src/components/MSpotlightSearch.vue +3 -2
  187. package/src/components/MTextField.vue +15 -2
  188. package/src/components/MTimeline.vue +370 -81
  189. package/src/components/MToolbar.vue +256 -15
  190. package/src/components/MTooltip.vue +20 -152
  191. package/src/components/_MDrawerItemList.vue +25 -6
  192. package/src/components/_MToolbarFab.vue +14 -0
  193. package/src/composables/_containerTransform.ts +179 -0
  194. package/src/composables/_mapStyle.ts +45 -0
  195. package/src/composables/_themeTransition.ts +2 -0
  196. package/src/composables/_tooltipTrigger.ts +184 -0
  197. package/src/composables/_useEscapeStack.ts +2 -0
  198. package/src/composables/_useMenuNav.ts +209 -0
  199. package/src/composables/useAutoGrow.ts +78 -0
  200. package/src/composables/useContainerTransform.ts +59 -0
  201. package/src/composables/useLocale.ts +10 -0
  202. package/src/composables/useMap.ts +43 -5
  203. package/src/composables/useMapFilter.ts +6 -5
  204. package/src/composables/useMapLayers.ts +7 -6
  205. package/src/composables/useScrollReveal.ts +151 -0
  206. package/src/composables/useThemeTokens.ts +116 -0
  207. package/src/composables/viewportHints.ts +80 -0
  208. package/src/directives/vClickOutside.ts +90 -0
  209. package/src/directives/vFocusRing.ts +60 -0
  210. package/src/directives/vLongPress.ts +134 -0
  211. package/src/directives/vReveal.ts +57 -0
  212. package/src/directives/vScrollElevation.ts +116 -0
  213. package/src/directives/vSkeleton.ts +87 -0
  214. package/src/directives/vStateLayer.ts +83 -0
  215. package/src/directives/vSwipe.ts +197 -0
  216. package/src/directives/vTooltip.ts +128 -0
  217. package/src/index.ts +31 -1
  218. package/src/locales/de.ts +4 -0
  219. package/src/locales/es.ts +4 -0
  220. package/src/locales/fr.ts +4 -0
  221. package/src/locales/ja.ts +4 -0
  222. package/src/locales/ko.ts +4 -0
  223. package/src/locales/pt.ts +4 -0
  224. package/src/locales/zh.ts +4 -0
  225. package/src/map.ts +1 -1
  226. package/src/plugin.ts +34 -0
  227. package/src/styles/theme.css +63 -0
  228. package/dist/MMenuItem-BckcR0nW.js +0 -809
  229. package/dist/MMenuItem-BckcR0nW.js.map +0 -1
  230. package/dist/MSlider-LyH_gy8D.js +0 -1411
  231. package/dist/MSlider-LyH_gy8D.js.map +0 -1
  232. package/dist/MTextField-FCPOTB0o.js +0 -672
  233. package/dist/MTextField-FCPOTB0o.js.map +0 -1
  234. package/dist/composables/_useThemeTokens.d.ts +0 -7
  235. package/dist/useLocale-SfQHnJfp.js.map +0 -1
  236. package/src/composables/_useThemeTokens.ts +0 -42
@@ -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
- const item = [...document.querySelectorAll<HTMLElement>('li, [role="listitem"], [role="button"]')].find((e) => e.textContent?.includes('Plaza San Martín'))!
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()
@@ -1,8 +1,9 @@
1
- import { describe, it, expect, beforeEach } from 'vitest'
1
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest'
2
2
  import { defineComponent, h, nextTick, ref } from 'vue'
3
3
  import { mount } from '@vue/test-utils'
4
4
  import MMenu from '../components/MMenu.vue'
5
5
  import MContextMenu from '../components/MContextMenu.vue'
6
+ import MMenuItem from '../components/MMenuItem.vue'
6
7
 
7
8
  const frame = () => new Promise<void>((r) => requestAnimationFrame(() => r()))
8
9
  // Long enough for the open spring to finish, so the close has real distance to cover
@@ -44,6 +45,75 @@ describe('MMenu', () => {
44
45
 
45
46
  expect(document.querySelector('.item')).toBeNull()
46
47
  })
48
+
49
+ describe('push submenus: swipe back', () => {
50
+ let wrapper: ReturnType<typeof mount> | null = null
51
+ afterEach(() => { wrapper?.unmount(); wrapper = null })
52
+ const finishAnimations = () => document.querySelectorAll('*').forEach((el) => el.getAnimations().forEach((a) => a.finish()))
53
+
54
+ async function openSubmenu() {
55
+ wrapper = mount(
56
+ defineComponent({
57
+ setup: () => () =>
58
+ h(MMenu, { submenuMode: 'push' }, {
59
+ trigger: () => h('button', { class: 'trigger' }, 'open'),
60
+ default: () => h(MMenuItem, null, {
61
+ default: () => 'Share',
62
+ children: () => h('span', { class: 'leaf' }, 'Email'),
63
+ }),
64
+ }),
65
+ }),
66
+ { attachTo: document.body, global: { stubs: { transition: false } } },
67
+ )
68
+ document.querySelector<HTMLElement>('.trigger')!.click()
69
+ await nextTick()
70
+ await settle()
71
+ document.querySelector<HTMLElement>('[aria-haspopup="menu"]')!.click()
72
+ await nextTick()
73
+ const level = document.querySelector<HTMLElement>('[data-menu-level="1"]')!
74
+ const box = level.parentElement!
75
+ Object.defineProperty(box, 'clientWidth', { value: 300, configurable: true })
76
+ return { box }
77
+ }
78
+
79
+ function swipe(box: HTMLElement, to: number, steps = 6) {
80
+ const at = (type: string, x: number, target: EventTarget) =>
81
+ target.dispatchEvent(new PointerEvent(type, { pointerId: 1, pointerType: 'touch', clientX: x, clientY: 100, bubbles: true }))
82
+ at('pointerdown', 20, box)
83
+ for (let i = 1; i <= steps; i++) at('pointermove', 20 + (to - 20) * i / steps, window)
84
+ at('pointerup', to, window)
85
+ }
86
+
87
+ it('goes back to the parent level when swiped past a third of the panel', async () => {
88
+ const { box } = await openSubmenu()
89
+ expect(document.querySelector('.leaf')).not.toBeNull()
90
+ expect(box.style.touchAction).toBe('pan-y')
91
+ swipe(box, 160)
92
+ await nextTick()
93
+ finishAnimations()
94
+ await nextTick()
95
+ expect(document.querySelector('[data-menu-level]')).toBeNull()
96
+ expect(document.querySelector('[aria-haspopup="menu"]')).not.toBeNull()
97
+ })
98
+
99
+ it('stays on the submenu after a short, slow swipe, and ignores a mouse drag', async () => {
100
+ const { box } = await openSubmenu()
101
+ const at = (type: string, x: number, target: EventTarget, t: number) =>
102
+ target.dispatchEvent(new PointerEvent(type, { pointerId: 1, pointerType: 'touch', clientX: x, clientY: 100, bubbles: true, timeStamp: t } as PointerEventInit))
103
+ at('pointerdown', 20, box, 0)
104
+ at('pointermove', 40, window, 500)
105
+ at('pointermove', 50, window, 1000)
106
+ at('pointerup', 50, window, 1500)
107
+ await nextTick()
108
+ expect(document.querySelector('[data-menu-level="1"]')).not.toBeNull()
109
+
110
+ box.dispatchEvent(new PointerEvent('pointerdown', { pointerId: 2, pointerType: 'mouse', clientX: 20, clientY: 100, bubbles: true }))
111
+ window.dispatchEvent(new PointerEvent('pointermove', { pointerId: 2, pointerType: 'mouse', clientX: 250, clientY: 100 }))
112
+ window.dispatchEvent(new PointerEvent('pointerup', { pointerId: 2, pointerType: 'mouse', clientX: 250, clientY: 100 }))
113
+ await nextTick()
114
+ expect(document.querySelector('[data-menu-level="1"]')).not.toBeNull()
115
+ })
116
+ })
47
117
  })
48
118
 
49
119
  describe('MContextMenu', () => {
@@ -82,3 +152,36 @@ describe('MContextMenu', () => {
82
152
  expect(document.querySelector('.item')).toBeNull()
83
153
  })
84
154
  })
155
+
156
+ describe('menus on the Escape stack', () => {
157
+ beforeEach(() => {
158
+ document.body.innerHTML = ''
159
+ })
160
+ const escape = () => document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', cancelable: true }))
161
+
162
+ it('a menu open in a dialog takes Escape alone; the next one closes the dialog', async () => {
163
+ const { default: MDialog } = await import('../components/MDialog.vue')
164
+ const dialog = mount(MDialog, {
165
+ props: { modelValue: true, title: 'T' },
166
+ slots: {
167
+ default: () =>
168
+ h(MMenu, null, {
169
+ trigger: () => h('button', { class: 'trigger' }, 'open'),
170
+ default: () => h('span', { class: 'item' }, 'Copy'),
171
+ }),
172
+ },
173
+ attachTo: document.body,
174
+ })
175
+ await nextTick()
176
+ document.querySelector<HTMLElement>('.trigger')!.click()
177
+ await nextTick()
178
+
179
+ escape()
180
+ await nextTick()
181
+ expect(dialog.emitted('update:modelValue')).toBeUndefined()
182
+
183
+ escape()
184
+ expect(dialog.emitted('update:modelValue')).toEqual([[false]])
185
+ dialog.unmount()
186
+ })
187
+ })
@@ -81,4 +81,22 @@ describe('MMenuItem', () => {
81
81
  const filled = inMenu({ selected: true, icon: 'star' }).button.find('.material-symbols-outlined')
82
82
  expect(filled.attributes('style')).toContain('FILL')
83
83
  })
84
+
85
+ it('renders the #icon slot in the icon box, with its color and the on state', () => {
86
+ const w = mount(MMenuItem, {
87
+ props: { icon: 'flip', selected: true },
88
+ slots: { default: 'Flip vertical', icon: (p: { on: boolean }) => h('i', { class: 'custom', 'data-on': String(p.on) }) },
89
+ })
90
+ const box = w.find('.custom').element.parentElement!
91
+ expect(box.className).toContain('size-5')
92
+ expect(w.find('.custom').attributes('data-on')).toBe('true')
93
+ // the slot replaces the icon prop's MIcon
94
+ expect(w.find('button').text()).not.toContain('flip')
95
+ })
96
+
97
+ it('keeps the #icon slot instead of the sliding check on a selectable item', () => {
98
+ const w = mount(MMenuItem, { props: { selected: false }, slots: { default: 'A', icon: '<i class="custom" />' } })
99
+ expect(w.find('.custom').exists()).toBe(true)
100
+ expect(w.text()).not.toContain('check')
101
+ })
84
102
  })
@@ -183,3 +183,83 @@ describe('MNavigationDrawer swipe to close', () => {
183
183
  vi.unstubAllGlobals()
184
184
  })
185
185
  })
186
+
187
+ describe('MNavigationDrawer open groups', () => {
188
+ const groups = [{
189
+ items: [
190
+ { value: 'mail', label: 'Mail', children: [{ value: 'inbox', label: 'Inbox' }, { value: 'sent', label: 'Sent' }] },
191
+ { value: 'files', label: 'Files', children: [
192
+ { value: 'docs', label: 'Docs', children: [{ value: 'report', label: 'Report' }] },
193
+ ] },
194
+ ],
195
+ }]
196
+ const openItems = () => (wrapper!.vm as unknown as { openItems: Record<string, boolean> }).openItems
197
+
198
+ function inline(props: Record<string, unknown> = {}) {
199
+ wrapper = mount(MNavigationDrawer, { props: { modelValue: true, modal: false, sections: groups, ...props } })
200
+ }
201
+
202
+ it('opens every group that holds the selected item', () => {
203
+ inline({ selected: 'report' })
204
+ expect(openItems()).toMatchObject({ files: true, docs: true })
205
+ expect(openItems().mail).toBeFalsy()
206
+ })
207
+
208
+ it('follows selected, leaving other groups open unless accordion', async () => {
209
+ inline({ selected: 'inbox' })
210
+ await wrapper!.setProps({ selected: 'report' })
211
+ expect(openItems()).toMatchObject({ mail: true, files: true, docs: true })
212
+
213
+ wrapper!.unmount()
214
+ inline({ selected: 'inbox', accordion: true })
215
+ await wrapper!.setProps({ selected: 'report' })
216
+ expect(openItems()).toMatchObject({ mail: false, files: true, docs: true })
217
+ })
218
+
219
+ it('accordion closes the siblings of a group opened by hand', async () => {
220
+ inline({ accordion: true, selected: 'inbox' })
221
+ const files = wrapper!.findAll('button').find((b) => b.text().includes('Files'))!
222
+ await files.trigger('click')
223
+ expect(openItems()).toMatchObject({ mail: false, files: true })
224
+ })
225
+
226
+ it('leaves groups alone with expandSelected false', () => {
227
+ inline({ selected: 'report', expandSelected: false })
228
+ expect(openItems().files).toBeFalsy()
229
+ })
230
+ })
231
+
232
+ describe('MNavigationDrawer collapsedLabels', () => {
233
+ const tree = [{
234
+ items: [
235
+ { value: 'inbox', label: 'Inbox', icon: 'inbox', badge: 4 },
236
+ { value: 'labels', label: 'Labels', icon: 'label', badge: 'New', children: [{ value: 'work', label: 'Work', icon: 'work' }] },
237
+ ],
238
+ }]
239
+ const mountInline = (props: Record<string, unknown> = {}) =>
240
+ (wrapper = mount(MNavigationDrawer, { props: { modelValue: true, modal: false, sections: tree, selected: 'work', ...props } }))
241
+
242
+ it('shows each label under its icon, nested items included, with the selection on the pill', () => {
243
+ const w = mountInline({ collapsed: true, collapsedLabels: true })
244
+ expect(w.find('nav').classes()).toContain('nd-rail')
245
+ expect(w.findAll('.nd-rail-label').map((l) => l.text())).toEqual(['Inbox', 'Labels', 'Work'])
246
+ const work = w.findAll('button').find((b) => b.text().includes('Work'))!
247
+ expect(work.classes()).not.toContain('bg-secondary-container')
248
+ expect(work.find('span[aria-hidden="true"]').classes()).toContain('bg-secondary-container')
249
+ })
250
+
251
+ it('puts badges on the icon when collapsed: a number as a count, text as a dot', () => {
252
+ const w = mountInline({ collapsed: true })
253
+ const badges = w.findAll('.bg-error')
254
+ expect(badges.map((b) => b.text())).toEqual(['4', ''])
255
+ })
256
+
257
+ it('keeps the row look when expanded or without the prop', () => {
258
+ const expanded = mountInline({ collapsed: false, collapsedLabels: true })
259
+ expect(expanded.find('nav').classes()).not.toContain('nd-rail')
260
+ expect(expanded.findAll('button').find((b) => b.text().includes('Work'))!.classes()).toContain('bg-secondary-container')
261
+ expanded.unmount()
262
+ const plain = mountInline({ collapsed: true })
263
+ expect(plain.findAll('.nd-rail-label')).toHaveLength(0)
264
+ })
265
+ })
@@ -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
  })
@@ -0,0 +1,49 @@
1
+ import { describe, it, expect, afterEach } from 'vitest'
2
+ import { mount, type VueWrapper } from '@vue/test-utils'
3
+ import MOverlay from '../components/MOverlay.vue'
4
+ import MDialog from '../components/MDialog.vue'
5
+
6
+ let wrappers: VueWrapper[] = []
7
+ afterEach(() => {
8
+ wrappers.forEach((w) => w.unmount())
9
+ wrappers = []
10
+ document.body.innerHTML = ''
11
+ document.body.style.overflow = ''
12
+ })
13
+ const open = (props: Record<string, unknown> = {}) => {
14
+ const w = mount(MOverlay, { props: { modelValue: true, ...props }, attachTo: document.body })
15
+ wrappers.push(w)
16
+ return w
17
+ }
18
+ const escape = () => document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', cancelable: true }))
19
+
20
+ describe('MOverlay', () => {
21
+ it('ignores Escape and leaves the scroll alone by default', () => {
22
+ const w = open()
23
+ escape()
24
+ expect(w.emitted('update:modelValue')).toBeUndefined()
25
+ expect(document.body.style.overflow).toBe('')
26
+ })
27
+
28
+ it('closes on Escape with closeOnEscape', () => {
29
+ const w = open({ closeOnEscape: true })
30
+ escape()
31
+ expect(w.emitted('update:modelValue')).toEqual([[false]])
32
+ })
33
+
34
+ it('leaves Escape to a dialog opened over it', () => {
35
+ const w = open({ closeOnEscape: true })
36
+ const d = mount(MDialog, { props: { modelValue: true, title: 'T' }, attachTo: document.body })
37
+ wrappers.push(d)
38
+ escape()
39
+ expect(d.emitted('update:modelValue')).toEqual([[false]])
40
+ expect(w.emitted('update:modelValue')).toBeUndefined()
41
+ })
42
+
43
+ it('locks the page scroll while open with lockScroll', async () => {
44
+ const w = open({ lockScroll: true })
45
+ expect(document.body.style.overflow).toBe('hidden')
46
+ await w.setProps({ modelValue: false })
47
+ expect(document.body.style.overflow).toBe('')
48
+ })
49
+ })
@@ -0,0 +1,41 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MProgressBar from '../components/MProgressBar.vue'
4
+ import MCircleProgressBar from '../components/MCircleProgressBar.vue'
5
+
6
+ const vars = (el: Element) => {
7
+ const s = (el as HTMLElement).style
8
+ return { bar: s.getPropertyValue('--m3-progress-bar'), track: s.getPropertyValue('--m3-progress-track') }
9
+ }
10
+
11
+ describe('MProgressBar colors', () => {
12
+ it('uses the role and its container by default', () => {
13
+ const w = mount(MProgressBar, { props: { value: 40, color: 'tertiary' } })
14
+ expect(vars(w.element)).toEqual({ bar: 'var(--color-tertiary)', track: 'var(--color-tertiary-container)' })
15
+ })
16
+
17
+ it('takes any CSS color, with a translucent track of it', () => {
18
+ const w = mount(MProgressBar, { props: { value: 40, color: '#fff' } })
19
+ expect(vars(w.element)).toEqual({ bar: '#fff', track: 'color-mix(in srgb, #fff 24%, transparent)' })
20
+ })
21
+
22
+ it('takes a track color as a role or a CSS color', () => {
23
+ expect(vars(mount(MProgressBar, { props: { value: 40, trackColor: 'rgb(255 255 255 / 0.35)' } }).element).track).toBe('rgb(255 255 255 / 0.35)')
24
+ expect(vars(mount(MProgressBar, { props: { value: 40, trackColor: 'secondary-container' } }).element).track).toBe('var(--color-secondary-container)')
25
+ })
26
+
27
+ it('paints the bar and track from those variables', () => {
28
+ const w = mount(MProgressBar, { props: { value: 40 } })
29
+ expect(w.find('.bg-\\(--m3-progress-bar\\)').exists()).toBe(true)
30
+ expect(w.find('.bg-\\(--m3-progress-track\\)').exists()).toBe(true)
31
+ })
32
+ })
33
+
34
+ describe('MCircleProgressBar colors', () => {
35
+ it('takes any CSS color for the ring and track', () => {
36
+ const w = mount(MCircleProgressBar, { props: { value: 40, color: '#fff', trackColor: 'transparent' } })
37
+ const strokes = w.findAll('circle, path').map((c) => (c.element as SVGElement).style.stroke).filter(Boolean)
38
+ expect(strokes).toContain('#fff')
39
+ expect(strokes).toContain('transparent')
40
+ })
41
+ })
@@ -121,3 +121,36 @@ describe('MPullToRefresh (mouse)', () => {
121
121
  vi.unstubAllGlobals()
122
122
  })
123
123
  })
124
+
125
+ describe('MPullToRefresh (scroll)', () => {
126
+ it('exposes its scrolling element and scrollTo', () => {
127
+ const { wrapper, scrollEl } = mountPtr()
128
+ const vm = wrapper.vm as unknown as { scrollEl: HTMLElement; scrollTo: (o: ScrollToOptions) => void }
129
+ expect(vm.scrollEl).toBe(scrollEl)
130
+ const spy = vi.fn()
131
+ ;(scrollEl as HTMLElement).scrollTo = spy
132
+ vm.scrollTo({ top: 0, behavior: 'smooth' })
133
+ expect(spy).toHaveBeenCalledWith({ top: 0, behavior: 'smooth' })
134
+ wrapper.unmount()
135
+ })
136
+
137
+ it('restores its scroll position when a <KeepAlive> brings it back', async () => {
138
+ const { defineComponent, h, KeepAlive, ref, nextTick } = await import('vue')
139
+ const show = ref(true)
140
+ const Other = defineComponent({ render: () => h('p', 'other') })
141
+ const Host = defineComponent({
142
+ setup: () => () => h(KeepAlive, null, [show.value ? h(MPullToRefresh, null, () => h('div', 'list')) : h(Other)]),
143
+ })
144
+ const wrapper = mount(Host, { attachTo: document.body })
145
+ const el = wrapper.find('.overflow-y-auto').element as HTMLElement
146
+ el.scrollTop = 300
147
+ el.dispatchEvent(new Event('scroll'))
148
+ show.value = false
149
+ await nextTick()
150
+ el.scrollTop = 0 // what a detached element reports
151
+ show.value = true
152
+ await nextTick()
153
+ expect(el.scrollTop).toBe(300)
154
+ wrapper.unmount()
155
+ })
156
+ })
@@ -0,0 +1,22 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MRichTextEditor from '../components/MRichTextEditor.vue'
4
+
5
+ describe('MRichTextEditor fill', () => {
6
+ it('grows with its content by default, from minHeight', () => {
7
+ const w = mount(MRichTextEditor, { props: { modelValue: '', minHeight: '120px' } })
8
+ const content = w.find('.rte-content')
9
+ expect((content.element as HTMLElement).style.minHeight).toBe('120px')
10
+ expect(content.classes()).not.toContain('overflow-y-auto')
11
+ w.unmount()
12
+ })
13
+
14
+ it('fills its height and scrolls the text inside with fill', () => {
15
+ const w = mount(MRichTextEditor, { props: { modelValue: '', fill: true } })
16
+ expect(w.classes()).toContain('flex-col')
17
+ const content = w.find('.rte-content')
18
+ expect(content.classes()).toEqual(expect.arrayContaining(['flex-1', 'min-h-0', 'overflow-y-auto']))
19
+ expect((content.element as HTMLElement).style.minHeight).toBe('')
20
+ w.unmount()
21
+ })
22
+ })
@@ -0,0 +1,71 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MSearchField from '../components/MSearchField.vue'
4
+
5
+ describe('MSearchField', () => {
6
+ it('works with v-model and emits search on Enter', async () => {
7
+ const w = mount(MSearchField, { props: { modelValue: '' } })
8
+ const input = w.find('input')
9
+ await input.setValue('lamp')
10
+ expect(w.emitted('update:modelValue')).toEqual([['lamp']])
11
+ await w.setProps({ modelValue: 'lamp' })
12
+ await input.trigger('keydown', { key: 'Enter' })
13
+ expect(w.emitted('search')).toEqual([['lamp']])
14
+ })
15
+
16
+ it('clears with the button, which shows only while there is text', async () => {
17
+ const w = mount(MSearchField, { props: { modelValue: '' } })
18
+ expect(w.find('button').exists()).toBe(false)
19
+ await w.setProps({ modelValue: 'x' })
20
+ await w.find('button').trigger('click')
21
+ expect(w.emitted('update:modelValue')).toEqual([['']])
22
+ expect(w.emitted('clear')).toHaveLength(1)
23
+ })
24
+
25
+ it('Escape empties it first and keeps the event from reaching the document', async () => {
26
+ const w = mount(MSearchField, { props: { modelValue: 'x' }, attachTo: document.body })
27
+ let reached = false
28
+ const spy = () => (reached = true)
29
+ document.addEventListener('keydown', spy)
30
+ w.find('input').element.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true }))
31
+ document.removeEventListener('keydown', spy)
32
+ expect(w.emitted('update:modelValue')).toEqual([['']])
33
+ expect(reached).toBe(false)
34
+ w.unmount()
35
+ })
36
+
37
+ it('lets Escape through once the field is empty', () => {
38
+ const w = mount(MSearchField, { props: { modelValue: '' }, attachTo: document.body })
39
+ let reached = false
40
+ const spy = () => (reached = true)
41
+ document.addEventListener('keydown', spy)
42
+ w.find('input').element.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true }))
43
+ document.removeEventListener('keydown', spy)
44
+ expect(reached).toBe(true)
45
+ expect(w.emitted('clear')).toBeUndefined()
46
+ w.unmount()
47
+ })
48
+
49
+ it('puts class and style on the pill, other attributes on the input', () => {
50
+ const w = mount(MSearchField, { attrs: { class: 'bg-surface-container-highest', name: 'q', 'aria-describedby': 'hint' } })
51
+ expect(w.classes()).toContain('bg-surface-container-highest')
52
+ expect(w.classes()).toContain('m3-search-field-lg')
53
+ const input = w.find('input')
54
+ expect(input.attributes('name')).toBe('q')
55
+ expect(input.attributes('aria-describedby')).toBe('hint')
56
+ expect(w.attributes('name')).toBeUndefined()
57
+ })
58
+
59
+ it('defaults the placeholder and accessible name to the locale', () => {
60
+ const input = mount(MSearchField).find('input')
61
+ expect(input.attributes('placeholder')).toBe('Search...')
62
+ expect(input.attributes('aria-label')).toBe('Search...')
63
+ })
64
+
65
+ it('spaces a slotted leading button like M3 (8px in), and keeps 16px with the default icon', () => {
66
+ expect(mount(MSearchField).classes()).not.toContain('m3-search-field-slotted')
67
+ const w = mount(MSearchField, { slots: { leading: '<button class="menu">m</button>' } })
68
+ expect(w.classes()).toContain('m3-search-field-slotted')
69
+ expect(w.find('.menu').element.parentElement!.className).toContain('-me-2')
70
+ })
71
+ })
@@ -0,0 +1,38 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MSkeleton from '../components/MSkeleton.vue'
4
+
5
+ // (the template starts with a comment, so the root is found by class, not wrapper.element)
6
+ const style = (props: Record<string, unknown>) => (mount(MSkeleton, { props }).find('.m3-skeleton').element as HTMLElement).style
7
+
8
+ describe('MSkeleton', () => {
9
+ it('leaves its default size and corners to a base-layer class, so consumer classes win', () => {
10
+ const w = mount(MSkeleton, { props: { variant: 'rounded' }, attrs: { class: 'w-40 rounded-xl' } })
11
+ const root = w.find('.m3-skeleton')
12
+ expect(root.classes()).toEqual(expect.arrayContaining(['m3-skeleton-rounded', 'w-40', 'rounded-xl']))
13
+ const s = (root.element as HTMLElement).style
14
+ expect(s.width).toBe('')
15
+ expect(s.height).toBe('')
16
+ expect(s.borderRadius).toBe('')
17
+ })
18
+
19
+ it('takes width and height props inline', () => {
20
+ const s = style({ width: '120px', height: 'auto' })
21
+ expect(s.width).toBe('120px')
22
+ expect(s.height).toBe('auto')
23
+ })
24
+
25
+ it('takes a radius as a shape step or any CSS length', () => {
26
+ expect(style({ radius: 'xl' }).borderRadius).toBe('var(--radius-xl)')
27
+ expect(style({ radius: 'full' }).borderRadius).toBe('9999px')
28
+ expect(style({ radius: 'none' }).borderRadius).toBe('0px')
29
+ expect(style({ radius: '6px' }).borderRadius).toBe('6px')
30
+ })
31
+
32
+ it('rounds every line of a multi-line text skeleton with radius', () => {
33
+ const w = mount(MSkeleton, { props: { lines: 3, radius: 'xs' } })
34
+ const lines = w.findAll('.h-3\\.5')
35
+ expect(lines).toHaveLength(3)
36
+ lines.forEach((l) => expect((l.element as HTMLElement).style.borderRadius).toBe('var(--radius-xs)'))
37
+ })
38
+ })