@m3ui-vue/m3ui-vue 1.10.2 → 1.11.1

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 (301) hide show
  1. package/README.md +19 -4
  2. package/dist/API.md +204 -59
  3. package/dist/MButton-BHKF1Tfd.js +284 -0
  4. package/dist/MButton-BHKF1Tfd.js.map +1 -0
  5. package/dist/MColorPickerModal-CNesUJUq.js +466 -0
  6. package/dist/MColorPickerModal-CNesUJUq.js.map +1 -0
  7. package/dist/MDialog-jAYkZ4M8.js +226 -0
  8. package/dist/MDialog-jAYkZ4M8.js.map +1 -0
  9. package/dist/{MIcon-BSsJZhK7.js → MIcon-CkUc9kuQ.js} +10 -4
  10. package/dist/MIcon-CkUc9kuQ.js.map +1 -0
  11. package/dist/MIconButton-DTFOfsTy.js +317 -0
  12. package/dist/MIconButton-DTFOfsTy.js.map +1 -0
  13. package/dist/MListItem-CgdM5sco.js +1306 -0
  14. package/dist/MListItem-CgdM5sco.js.map +1 -0
  15. package/dist/MLoadingIndicator-00XbLQSf.js +115 -0
  16. package/dist/MLoadingIndicator-00XbLQSf.js.map +1 -0
  17. package/dist/{MMenuItem-US0Zbglq.js → MMenuItem-CEIKYvaX.js} +216 -214
  18. package/dist/MMenuItem-CEIKYvaX.js.map +1 -0
  19. package/dist/{MPdfViewer-DL9mRsd2.js → MPdfViewer-KjUIJOIs.js} +674 -671
  20. package/dist/MPdfViewer-KjUIJOIs.js.map +1 -0
  21. package/dist/MProgressBar-BzZMxq7M.js.map +1 -1
  22. package/dist/MSeekBar-B4EEWw3B.js +435 -0
  23. package/dist/MSeekBar-B4EEWw3B.js.map +1 -0
  24. package/dist/{MSegmentedButton-DMou-8sG.js → MSegmentedButton-UOAJAd2i.js} +4 -4
  25. package/dist/{MSegmentedButton-DMou-8sG.js.map → MSegmentedButton-UOAJAd2i.js.map} +1 -1
  26. package/dist/{MSignaturePad-WuvE_Cyl.js → MSignaturePad-HZavgiGB.js} +2 -2
  27. package/dist/{MSignaturePad-WuvE_Cyl.js.map → MSignaturePad-HZavgiGB.js.map} +1 -1
  28. package/dist/{MSlider-7TzhFHKS.js → MSlider-BaQeaozI.js} +4 -4
  29. package/dist/{MSlider-7TzhFHKS.js.map → MSlider-BaQeaozI.js.map} +1 -1
  30. package/dist/{MSpinner-CkIVBuGE.js → MSpinner-CbEMPY4X.js} +2 -2
  31. package/dist/{MSpinner-CkIVBuGE.js.map → MSpinner-CbEMPY4X.js.map} +1 -1
  32. package/dist/{MTextField-B6_iOczK.js → MTextField-B9PwKHlP.js} +136 -134
  33. package/dist/MTextField-B9PwKHlP.js.map +1 -0
  34. package/dist/{_useFieldValidation-COBJ1tWr.js → _useFieldValidation-B7AAfa69.js} +2 -2
  35. package/dist/{_useFieldValidation-COBJ1tWr.js.map → _useFieldValidation-B7AAfa69.js.map} +1 -1
  36. package/dist/api.json +1 -1
  37. package/dist/chart.js +1 -1
  38. package/dist/code-editor.js +3 -3
  39. package/dist/code-editor.js.map +1 -1
  40. package/dist/components/MAlert.vue.d.ts +1 -1
  41. package/dist/components/MAudioPlayer.vue.d.ts +3 -3
  42. package/dist/components/MAudioRecorder.vue.d.ts +2 -2
  43. package/dist/components/MAvatar.vue.d.ts +19 -1
  44. package/dist/components/MButton.vue.d.ts +2 -1
  45. package/dist/components/MChatBubble.vue.d.ts +2 -0
  46. package/dist/components/MCheckbox.vue.d.ts +2 -0
  47. package/dist/components/MDataTable.vue.d.ts +33 -5
  48. package/dist/components/MFlow.vue.d.ts +1 -1
  49. package/dist/components/MHotkeys.vue.d.ts +1 -0
  50. package/dist/components/MIcon.vue.d.ts +6 -0
  51. package/dist/components/MIconButton.vue.d.ts +5 -0
  52. package/dist/components/MJsonViewer.vue.d.ts +2 -0
  53. package/dist/components/MKanban.vue.d.ts +1 -1
  54. package/dist/components/MLink.vue.d.ts +59 -0
  55. package/dist/components/MListItem.vue.d.ts +3 -1
  56. package/dist/components/MMapControl.vue.d.ts +1 -1
  57. package/dist/components/MNotificationCenter.vue.d.ts +1 -1
  58. package/dist/components/MNumberField.vue.d.ts +1 -1
  59. package/dist/components/MPagination.vue.d.ts +14 -1
  60. package/dist/components/MPdfSigner.vue.d.ts +3 -3
  61. package/dist/components/MRadio.vue.d.ts +2 -0
  62. package/dist/components/MRadioGroup.vue.d.ts +2 -0
  63. package/dist/components/MStatCard.vue.d.ts +2 -2
  64. package/dist/components/MSwitch.vue.d.ts +2 -0
  65. package/dist/components/MTable.vue.d.ts +1 -1
  66. package/dist/components/MText.vue.d.ts +4 -2
  67. package/dist/components/MTextField.vue.d.ts +2 -0
  68. package/dist/components/MTicket.vue.d.ts +1 -1
  69. package/dist/components/_MDrawerItemList.vue.d.ts +6 -0
  70. package/dist/composables/_countLabel.d.ts +6 -0
  71. package/dist/composables/_menuGroups.d.ts +10 -1
  72. package/dist/composables/_splitAttrs.d.ts +6 -0
  73. package/dist/composables/_springAnimation.d.ts +2 -2
  74. package/dist/composables/_useFocusTrap.d.ts +15 -0
  75. package/dist/composables/_usePaneResize.d.ts +1 -1
  76. package/dist/composables/_useSpring.d.ts +4 -4
  77. package/dist/composables/dynamicColor.d.ts +9 -1
  78. package/dist/composables/motion.d.ts +63 -0
  79. package/dist/composables/useConfirm.d.ts +28 -0
  80. package/dist/composables/useDevice.d.ts +8 -1
  81. package/dist/composables/useLocale.d.ts +18 -0
  82. package/dist/composables/useScrollReveal.d.ts +1 -1
  83. package/dist/composables/useTheme.d.ts +1 -0
  84. package/dist/composables/useToast.d.ts +7 -0
  85. package/dist/draw.js +556 -556
  86. package/dist/draw.js.map +1 -1
  87. package/dist/flow.js +854 -851
  88. package/dist/flow.js.map +1 -1
  89. package/dist/gantt.js +1118 -1096
  90. package/dist/gantt.js.map +1 -1
  91. package/dist/index.d.ts +8 -5
  92. package/dist/locales/index.d.ts +1 -0
  93. package/dist/locales/index.js +865 -33
  94. package/dist/locales/index.js.map +1 -1
  95. package/dist/locales/pl.d.ts +2 -0
  96. package/dist/m3ui-vue.css +1 -1
  97. package/dist/m3ui.js +10335 -9798
  98. package/dist/m3ui.js.map +1 -1
  99. package/dist/map.js +860 -860
  100. package/dist/map.js.map +1 -1
  101. package/dist/{material-color-utilities-CEFytLsr.js → material-color-utilities-BZsBNIhi.js} +276 -217
  102. package/dist/material-color-utilities-BZsBNIhi.js.map +1 -0
  103. package/dist/media.js +7 -7
  104. package/dist/{motion-BcejVTeX.js → motion-BqYcqcim.js} +15 -5
  105. package/dist/motion-BqYcqcim.js.map +1 -0
  106. package/dist/pdf-sign.js +140 -137
  107. package/dist/pdf-sign.js.map +1 -1
  108. package/dist/pdf.js +1 -1
  109. package/dist/plugin.d.ts +11 -0
  110. package/dist/rich-text-editor.js +7 -7
  111. package/dist/styles/theme.css +40 -0
  112. package/dist/styles.css +1 -1
  113. package/dist/terminal.js +1 -1
  114. package/dist/{useLocale-YRaOT12S.js → useLocale-BAPJ34Pq.js} +64 -8
  115. package/dist/useLocale-BAPJ34Pq.js.map +1 -0
  116. package/dist/{useThemeTokens-DyAdPQB0.js → useThemeTokens-D5nr5KHf.js} +28 -27
  117. package/dist/useThemeTokens-D5nr5KHf.js.map +1 -0
  118. package/package.json +17 -2
  119. package/src/__tests__/MAvatarImage.test.ts +37 -0
  120. package/src/__tests__/MDataTableControlled.test.ts +68 -0
  121. package/src/__tests__/MHotkeysSequence.test.ts +53 -0
  122. package/src/__tests__/MIconAxes.test.ts +16 -0
  123. package/src/__tests__/MIconButtonWidth.test.ts +22 -0
  124. package/src/__tests__/MLink.test.ts +46 -0
  125. package/src/__tests__/MPaginationPages.test.ts +43 -0
  126. package/src/__tests__/MTextEmphasized.test.ts +14 -0
  127. package/src/__tests__/controlDescription.test.ts +34 -0
  128. package/src/__tests__/countLabels.test.ts +66 -0
  129. package/src/__tests__/customColor.test.ts +27 -0
  130. package/src/__tests__/dynamicColor.test.ts +3 -2
  131. package/src/__tests__/focusTrap.test.ts +124 -0
  132. package/src/__tests__/formatMessage.test.ts +20 -0
  133. package/src/__tests__/inputAttrs.test.ts +103 -0
  134. package/src/__tests__/localePresets.test.ts +2 -0
  135. package/src/__tests__/menuGroupsRemount.test.ts +40 -0
  136. package/src/__tests__/menuHydration.test.ts +41 -0
  137. package/src/__tests__/motionPrefs.test.ts +28 -0
  138. package/src/__tests__/ssr.test.ts +11 -0
  139. package/src/__tests__/ssrToast.test.ts +20 -0
  140. package/src/__tests__/toastDetails.test.ts +39 -0
  141. package/src/__tests__/useConfirm.test.ts +47 -0
  142. package/src/__tests__/useTheme.test.ts +14 -0
  143. package/src/__tests__/warningRole.test.ts +22 -0
  144. package/src/components/MAlert.vue +2 -2
  145. package/src/components/MAnimatedNumber.vue +9 -3
  146. package/src/components/MAutocomplete.vue +16 -4
  147. package/src/components/MAvailabilityCalendar.vue +3 -3
  148. package/src/components/MAvatar.vue +32 -5
  149. package/src/components/MAvatarGroup.vue +7 -2
  150. package/src/components/MBottomSheet.vue +18 -2
  151. package/src/components/MButton.vue +18 -5
  152. package/src/components/MCarousel.vue +3 -3
  153. package/src/components/MChatBubble.vue +14 -1
  154. package/src/components/MCheckbox.vue +21 -4
  155. package/src/components/MChip.vue +4 -2
  156. package/src/components/MCollapse.vue +7 -1
  157. package/src/components/MCommandPalette.vue +6 -2
  158. package/src/components/MContextMenu.vue +4 -4
  159. package/src/components/MCreditCardInput.vue +5 -0
  160. package/src/components/MDashboardGrid.vue +2 -1
  161. package/src/components/MDataTable.vue +68 -20
  162. package/src/components/MDialog.vue +21 -3
  163. package/src/components/MDiffViewer.vue +3 -3
  164. package/src/components/MDrawLayers.vue +3 -3
  165. package/src/components/MFabMenu.vue +7 -0
  166. package/src/components/MFloorPlan.vue +3 -3
  167. package/src/components/MFloorPlanInspector.vue +3 -3
  168. package/src/components/MFlow.vue +9 -5
  169. package/src/components/MFlowControls.vue +6 -0
  170. package/src/components/MFormBuilder.vue +1 -1
  171. package/src/components/MGantt.vue +10 -10
  172. package/src/components/MHotkeys.vue +61 -16
  173. package/src/components/MIcon.vue +17 -1
  174. package/src/components/MIconButton.vue +29 -6
  175. package/src/components/MImageCropper.vue +1 -1
  176. package/src/components/MJsonViewer.vue +4 -1
  177. package/src/components/MKanban.vue +2 -1
  178. package/src/components/MLightbox.vue +5 -4
  179. package/src/components/MLink.vue +136 -0
  180. package/src/components/MListDetail.vue +7 -0
  181. package/src/components/MListItem.vue +7 -4
  182. package/src/components/MLoadingIndicator.vue +2 -1
  183. package/src/components/MMap.vue +3 -0
  184. package/src/components/MMapCluster.vue +2 -2
  185. package/src/components/MMapControl.vue +2 -2
  186. package/src/components/MMapMeasure.vue +1 -1
  187. package/src/components/MMaskField.vue +16 -3
  188. package/src/components/MMenu.vue +4 -4
  189. package/src/components/MMenuItem.vue +2 -2
  190. package/src/components/MMeterGroup.vue +3 -2
  191. package/src/components/MMortgageCalculator.vue +3 -3
  192. package/src/components/MMultiAutocomplete.vue +19 -7
  193. package/src/components/MMultiSelect.vue +19 -7
  194. package/src/components/MNavigationDrawer.vue +10 -3
  195. package/src/components/MNavigationRail.vue +5 -1
  196. package/src/components/MNotificationCenter.vue +2 -1
  197. package/src/components/MNotificationHost.vue +3 -3
  198. package/src/components/MNumberField.vue +23 -6
  199. package/src/components/MOdontogram.vue +4 -4
  200. package/src/components/MOrderBook.vue +4 -0
  201. package/src/components/MPagination.vue +91 -12
  202. package/src/components/MPdfSigner.vue +3 -3
  203. package/src/components/MPdfViewer.vue +7 -7
  204. package/src/components/MPhoneInput.vue +17 -4
  205. package/src/components/MProductConfigurator.vue +4 -4
  206. package/src/components/MProgressBar.vue +5 -0
  207. package/src/components/MQuiz.vue +8 -5
  208. package/src/components/MRadio.vue +24 -5
  209. package/src/components/MRadioGroup.vue +3 -0
  210. package/src/components/MReactions.vue +2 -2
  211. package/src/components/MResourceTimeline.vue +3 -3
  212. package/src/components/MResult.vue +1 -1
  213. package/src/components/MScrollField.vue +1 -1
  214. package/src/components/MSearchField.vue +6 -5
  215. package/src/components/MSeatMap.vue +5 -0
  216. package/src/components/MSeekBar.vue +3 -2
  217. package/src/components/MSelect.vue +16 -4
  218. package/src/components/MSideSheet.vue +25 -3
  219. package/src/components/MSimpleCarousel.vue +2 -2
  220. package/src/components/MSnackbar.vue +16 -13
  221. package/src/components/MSparkline.vue +2 -1
  222. package/src/components/MSpinner.vue +8 -0
  223. package/src/components/MSplitter.vue +1 -1
  224. package/src/components/MSpotlightSearch.vue +6 -2
  225. package/src/components/MSpreadsheet.vue +1 -1
  226. package/src/components/MStatCard.vue +2 -1
  227. package/src/components/MSwitch.vue +21 -4
  228. package/src/components/MTable.vue +3 -2
  229. package/src/components/MTabs.vue +2 -1
  230. package/src/components/MTagInput.vue +19 -6
  231. package/src/components/MText.vue +23 -4
  232. package/src/components/MTextField.vue +25 -6
  233. package/src/components/MTimeline.vue +5 -5
  234. package/src/components/MToolbar.vue +2 -2
  235. package/src/components/MTour.vue +3 -0
  236. package/src/components/MTrackingTimeline.vue +6 -0
  237. package/src/components/MTypewriter.vue +7 -1
  238. package/src/components/MWindow.vue +10 -1
  239. package/src/components/_MColorPanel.vue +4 -4
  240. package/src/components/_MComment.vue +3 -2
  241. package/src/components/_MFlowNodeShell.vue +1 -1
  242. package/src/components/_MPdfPage.vue +1 -1
  243. package/src/components/_MTransferPane.vue +10 -0
  244. package/src/composables/_countLabel.ts +10 -0
  245. package/src/composables/_effectCanvas.ts +2 -1
  246. package/src/composables/_menuGroups.ts +10 -1
  247. package/src/composables/_splitAttrs.ts +29 -0
  248. package/src/composables/_springAnimation.ts +3 -3
  249. package/src/composables/_themeTransition.ts +3 -2
  250. package/src/composables/_useFocusTrap.ts +142 -0
  251. package/src/composables/_useMenuNav.ts +3 -3
  252. package/src/composables/_usePaneResize.ts +2 -1
  253. package/src/composables/_useSheetMotion.ts +3 -4
  254. package/src/composables/_useSpring.ts +16 -10
  255. package/src/composables/cron.ts +7 -6
  256. package/src/composables/dynamicColor.ts +21 -2
  257. package/src/composables/motion.ts +27 -0
  258. package/src/composables/useConfirm.ts +116 -0
  259. package/src/composables/useDevice.ts +23 -3
  260. package/src/composables/useFieldBg.ts +4 -0
  261. package/src/composables/useLocale.ts +82 -4
  262. package/src/composables/useNotification.ts +3 -0
  263. package/src/composables/useScrollReveal.ts +3 -3
  264. package/src/composables/useTheme.ts +8 -2
  265. package/src/composables/useToast.ts +27 -4
  266. package/src/directives/vSparkle.ts +2 -1
  267. package/src/index.ts +8 -5
  268. package/src/locales/ar.ts +11 -4
  269. package/src/locales/de.ts +11 -4
  270. package/src/locales/es.ts +11 -4
  271. package/src/locales/fr.ts +11 -4
  272. package/src/locales/index.ts +1 -0
  273. package/src/locales/ja.ts +11 -4
  274. package/src/locales/ko.ts +11 -4
  275. package/src/locales/pl.ts +807 -0
  276. package/src/locales/pt.ts +11 -4
  277. package/src/locales/zh.ts +11 -4
  278. package/src/plugin.ts +16 -0
  279. package/src/styles/theme.css +40 -0
  280. package/dist/MButton-B9RCM06i.js +0 -171
  281. package/dist/MButton-B9RCM06i.js.map +0 -1
  282. package/dist/MColorPickerModal-ChRtcZOo.js +0 -577
  283. package/dist/MColorPickerModal-ChRtcZOo.js.map +0 -1
  284. package/dist/MDialog-dk07tify.js +0 -167
  285. package/dist/MDialog-dk07tify.js.map +0 -1
  286. package/dist/MIcon-BSsJZhK7.js.map +0 -1
  287. package/dist/MIconButton-CrBPZidd.js +0 -288
  288. package/dist/MIconButton-CrBPZidd.js.map +0 -1
  289. package/dist/MListItem-h9H223vx.js +0 -1239
  290. package/dist/MListItem-h9H223vx.js.map +0 -1
  291. package/dist/MLoadingIndicator-YTV1Ov5w.js +0 -114
  292. package/dist/MLoadingIndicator-YTV1Ov5w.js.map +0 -1
  293. package/dist/MMenuItem-US0Zbglq.js.map +0 -1
  294. package/dist/MPdfViewer-DL9mRsd2.js.map +0 -1
  295. package/dist/MSeekBar-JFZcoJ8y.js +0 -434
  296. package/dist/MSeekBar-JFZcoJ8y.js.map +0 -1
  297. package/dist/MTextField-B6_iOczK.js.map +0 -1
  298. package/dist/material-color-utilities-CEFytLsr.js.map +0 -1
  299. package/dist/motion-BcejVTeX.js.map +0 -1
  300. package/dist/useLocale-YRaOT12S.js.map +0 -1
  301. package/dist/useThemeTokens-DyAdPQB0.js.map +0 -1
@@ -0,0 +1,43 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MPagination from '../components/MPagination.vue'
4
+
5
+ const labels = (w: ReturnType<typeof mount>) =>
6
+ w.findAll('li').map((li) => li.text()).filter((t) => t && !/chevron|first_page|last_page/.test(t))
7
+
8
+ describe('MPagination pages variant', () => {
9
+ const props = (page: number, extra = {}) => ({ page, perPage: 10, total: 200, variant: 'pages' as const, ...extra })
10
+
11
+ it('shows first, last, a window around the current page and gaps', () => {
12
+ expect(labels(mount(MPagination, { props: props(1) }))).toEqual(['1', '2', '3', '4', '5', '…', '20'])
13
+ expect(labels(mount(MPagination, { props: props(10) }))).toEqual(['1', '…', '9', '10', '11', '…', '20'])
14
+ expect(labels(mount(MPagination, { props: props(20) }))).toEqual(['1', '…', '16', '17', '18', '19', '20'])
15
+ })
16
+
17
+ it('never hides a single page behind a gap', () => {
18
+ expect(labels(mount(MPagination, { props: props(4) }))).toEqual(['1', '2', '3', '4', '5', '…', '20'])
19
+ expect(labels(mount(MPagination, { props: props(17) }))).toEqual(['1', '…', '16', '17', '18', '19', '20'])
20
+ })
21
+
22
+ it('lists every page when they fit, and widens with siblings', () => {
23
+ expect(labels(mount(MPagination, { props: { ...props(2), total: 50 } }))).toEqual(['1', '2', '3', '4', '5'])
24
+ expect(labels(mount(MPagination, { props: props(10, { siblings: 2 }) }))).toEqual(['1', '…', '8', '9', '10', '11', '12', '…', '20'])
25
+ })
26
+
27
+ it('marks the current page and emits the clicked one', async () => {
28
+ const w = mount(MPagination, { props: props(10) })
29
+ const current = w.find('[aria-current="page"]')
30
+ expect(current.text()).toBe('10')
31
+ await w.findAll('button').find((b) => b.text() === '11')!.trigger('click')
32
+ expect(w.emitted('update:page')).toEqual([[11]])
33
+ expect(w.find('nav').attributes('aria-label')).toBe('Pagination')
34
+ })
35
+
36
+ it('first/last buttons, also in the simple variant', async () => {
37
+ const w = mount(MPagination, { props: { page: 3, perPage: 10, total: 100, showFirstLast: true } })
38
+ const buttons = w.findAll('button')
39
+ expect(buttons.map((b) => b.attributes('aria-label'))).toEqual(['First page', 'Previous page', 'Next page', 'Last page'])
40
+ await buttons[3]!.trigger('click')
41
+ expect(w.emitted('update:page')).toEqual([[10]])
42
+ })
43
+ })
@@ -0,0 +1,14 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MText from '../components/MText.vue'
4
+
5
+ describe('MText emphasized variants', () => {
6
+ it('applies the emphasized class and keeps the base variant tag', () => {
7
+ const w = mount(MText, { props: { variant: 'headline-large-emphasized' }, slots: { default: 'Hi' } })
8
+ expect(w.element.tagName).toBe('H1')
9
+ expect(w.classes()).toContain('text-headline-large-emphasized')
10
+ const l = mount(MText, { props: { variant: 'label-small-emphasized' }, slots: { default: 'x' } })
11
+ expect(l.element.tagName).toBe('SPAN')
12
+ expect(l.classes()).toContain('text-label-small-emphasized')
13
+ })
14
+ })
@@ -0,0 +1,34 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MCheckbox from '../components/MCheckbox.vue'
4
+ import MSwitch from '../components/MSwitch.vue'
5
+ import MRadio from '../components/MRadio.vue'
6
+ import MRadioGroup from '../components/MRadioGroup.vue'
7
+
8
+ describe('description on selection controls', () => {
9
+ for (const [name, C, props] of [
10
+ ['MCheckbox', MCheckbox, { modelValue: false }],
11
+ ['MSwitch', MSwitch, { modelValue: false }],
12
+ ['MRadio', MRadio, { modelValue: null, value: 'a' }],
13
+ ] as const) {
14
+ it(`${name} shows it and links it to the input`, () => {
15
+ const w = mount(C as any, { props: { ...props, label: 'Wi-Fi', description: 'Connect automatically' } })
16
+ const input = w.find('input')
17
+ const ids = (input.attributes('aria-describedby') ?? '').split(' ')
18
+ const desc = w.findAll('span').find((s) => s.text() === 'Connect automatically')!
19
+ expect(desc.exists()).toBe(true)
20
+ expect(ids).toContain(desc.attributes('id'))
21
+ })
22
+ it(`${name} without it adds no describedby`, () => {
23
+ const w = mount(C as any, { props: { ...props, label: 'Wi-Fi' } })
24
+ expect(w.find('input').attributes('aria-describedby')).toBeUndefined()
25
+ })
26
+ }
27
+
28
+ it('MRadioGroup passes option descriptions', () => {
29
+ const w = mount(MRadioGroup, {
30
+ props: { modelValue: 'a', options: [{ label: 'Standard', value: 'a', description: '3–5 days' }, { label: 'Express', value: 'b' }] },
31
+ })
32
+ expect(w.text()).toContain('3–5 days')
33
+ })
34
+ })
@@ -0,0 +1,66 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MDataTable from '../components/MDataTable.vue'
4
+ import MTable from '../components/MTable.vue'
5
+ import MJsonViewer from '../components/MJsonViewer.vue'
6
+ import { M3_LOCALE_KEY, defaultLocale } from '../composables/useLocale'
7
+ import { countLabel } from '../composables/_countLabel'
8
+ import { esLocale, deLocale, plLocale, jaLocale, arLocale, ptLocale } from '../locales'
9
+
10
+ // Count labels (selected rows, total records, JSON sizes) used to append an English "s" to a bare locale word:
11
+ // "3 selecteds", "3 seleccionadoss", "3 Datensatzs", "3 件s". They're templates resolved with plural rules now.
12
+ const columns = [{ key: 'name', label: 'Name' }]
13
+ const rows = [{ id: 1, name: 'Ana' }, { id: 2, name: 'Bruno' }, { id: 3, name: 'Carla' }]
14
+ const withLocale = (locale?: object) => (locale ? { provide: { [M3_LOCALE_KEY as symbol]: locale } } : undefined)
15
+ const stubs = { transition: false }
16
+
17
+ describe('count labels', () => {
18
+ it('MDataTable: selected badge and records footer follow the locale grammar', () => {
19
+ const cases: [object | undefined, string, string, string][] = [
20
+ [undefined, '2 selected', '3 records', '1 record'],
21
+ [esLocale, '2 seleccionados', '3 registros', '1 registro'],
22
+ [deLocale, '2 ausgewählt', '3 Datensätze', '1 Datensatz'],
23
+ [jaLocale, '2件選択中', '3件', '1件'],
24
+ ]
25
+ for (const [locale, sel, many, one] of cases) {
26
+ const w = mount(MDataTable, { props: { columns, rows, rowKey: 'id', selectable: true, modelValue: rows.slice(0, 2) }, global: { ...withLocale(locale), stubs } })
27
+ expect(w.text()).toContain(sel)
28
+ expect(w.text()).toContain(many)
29
+ expect(w.text()).not.toMatch(/selecteds|seleccionadoss|ausgewählts|件s/)
30
+ const single = mount(MDataTable, { props: { columns, rows: rows.slice(0, 1), rowKey: 'id' }, global: withLocale(locale) })
31
+ expect(single.text()).toContain(one)
32
+ }
33
+ })
34
+
35
+ it('MTable: selected badge', () => {
36
+ const w = mount(MTable, { props: { columns, rows, selectable: true, modelValue: rows.slice(0, 1) }, global: { ...withLocale(esLocale), stubs } })
37
+ expect(w.text()).toContain('1 seleccionado')
38
+ expect(w.text()).not.toContain('seleccionados')
39
+ })
40
+
41
+ it('MJsonViewer: collapsed sizes are singular for one', () => {
42
+ const w = mount(MJsonViewer, { props: { data: { list: [1], obj: { a: 1, b: 2 } }, expandDepth: 1 } })
43
+ expect(w.text()).toContain('1 element')
44
+ expect(w.text()).not.toContain('1 elements')
45
+ expect(w.text()).toContain('2 fields')
46
+ })
47
+
48
+ it('Portuguese, Polish and Arabic pick their plural forms', () => {
49
+ expect(countLabel(ptLocale.recordCount, 0, 'pt')).toBe('0 registros')
50
+ expect(countLabel(ptLocale.recordCount, 1, 'pt')).toBe('1 registro')
51
+ expect(countLabel(plLocale.recordCount, 1, 'pl')).toBe('1 rekord')
52
+ expect(countLabel(plLocale.recordCount, 22, 'pl')).toBe('22 rekordy')
53
+ expect(countLabel(plLocale.recordCount, 12, 'pl')).toBe('12 rekordów')
54
+ expect(countLabel(plLocale.recordCount, 3, 'pl')).toBe('3 rekordy')
55
+ expect(countLabel(plLocale.recordCount, 5, 'pl')).toBe('5 rekordów')
56
+ expect(countLabel(arLocale.recordCount, 2, 'ar')).toBe('سجلان')
57
+ expect(countLabel(arLocale.recordCount, 5, 'ar')).toBe('5 سجلات')
58
+ })
59
+
60
+ it('a bare word (old overrides, selectedText/recordsText props) goes after the number with nothing added', () => {
61
+ expect(countLabel('filas', 3)).toBe('3 filas')
62
+ const w = mount(MDataTable, { props: { columns, rows, rowKey: 'id', recordsText: 'clientes' } })
63
+ expect(w.text()).toContain('3 clientes')
64
+ expect(countLabel(defaultLocale.selectedCount, 4, 'en')).toBe('4 selected')
65
+ })
66
+ })
@@ -0,0 +1,27 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MButton from '../components/MButton.vue'
4
+ import MChip from '../components/MChip.vue'
5
+
6
+ describe('custom colors accept any CSS color', () => {
7
+ it('MChip mixes its background from the color instead of appending a hex alpha', () => {
8
+ for (const tone of ['#e91e63', 'rgb(10 20 30)', 'teal', 'var(--brand)']) {
9
+ const w = mount(MChip, { props: { tone, label: 'x' } })
10
+ const style = w.attributes('style') ?? ''
11
+ expect(style).toContain(`--chip-bg: color-mix(in srgb, ${tone} 13%, transparent)`)
12
+ expect(style).not.toMatch(/22;|22"/)
13
+ }
14
+ })
15
+
16
+ it('MButton container mixes from the color; on-color follows contrast for hex', () => {
17
+ const dark = mount(MButton, { props: { color: '#0d47a1' }, slots: { default: 'Go' } })
18
+ expect(dark.attributes('style')).toContain('--color-primary-container: color-mix(in srgb, #0d47a1 20%, transparent)')
19
+ expect(dark.attributes('style')).toContain('--color-on-primary: #ffffff')
20
+ const light = mount(MButton, { props: { color: '#ffeb3b' }, slots: { default: 'Go' } })
21
+ expect(light.attributes('style')).toContain('--color-on-primary: #000000')
22
+ const v = mount(MButton, { props: { color: 'var(--brand)' }, slots: { default: 'Go' } })
23
+ expect(v.attributes('style')).toContain('--color-primary-container: color-mix(in srgb, var(--brand) 20%, transparent)')
24
+ // tonal draws with the secondary container
25
+ expect(v.attributes('style')).toContain('--color-secondary-container: color-mix(in srgb, var(--brand) 20%, transparent)')
26
+ })
27
+ })
@@ -6,8 +6,9 @@ import { generateScheme, schemeRoles, schemeToCss } from '../composables/dynamic
6
6
  describe('generateScheme', () => {
7
7
  it('builds every role for light and dark, with the official tonal spot values', async () => {
8
8
  const scheme = await generateScheme('#6750A4')
9
- expect(Object.keys(scheme.light)).toEqual([...schemeRoles])
10
- expect(Object.keys(scheme.dark)).toEqual([...schemeRoles])
9
+ const status = ['success', 'warning'].flatMap((c) => [c, `on-${c}`, `${c}-container`, `on-${c}-container`])
10
+ expect(Object.keys(scheme.light)).toEqual([...schemeRoles, ...status])
11
+ expect(Object.keys(scheme.dark)).toEqual([...schemeRoles, ...status])
11
12
  // SchemeTonalSpot of the M3 baseline seed (material-color-utilities)
12
13
  expect(scheme.light.primary).toBe('#65558f')
13
14
  expect(scheme.light['primary-container']).toBe('#e9ddff')
@@ -0,0 +1,124 @@
1
+ import { describe, it, expect, afterEach } from 'vitest'
2
+ import { mount as vtuMount, flushPromises, type VueWrapper } from '@vue/test-utils'
3
+ import { defineComponent, h, nextTick, ref } from 'vue'
4
+ import MDialog from '../components/MDialog.vue'
5
+ import MBottomSheet from '../components/MBottomSheet.vue'
6
+ import MSideSheet from '../components/MSideSheet.vue'
7
+
8
+ const settle = async () => { await flushPromises(); await nextTick(); await nextTick() }
9
+
10
+ function tab(shift = false) {
11
+ const e = new KeyboardEvent('keydown', { key: 'Tab', shiftKey: shift, bubbles: true, cancelable: true })
12
+ ;(document.activeElement ?? document.body).dispatchEvent(e)
13
+ return e
14
+ }
15
+
16
+ function harness(open = ref(false), extra: Record<string, unknown> = {}) {
17
+ return defineComponent({
18
+ setup: () => () => [
19
+ h('button', { id: 'opener', onClick: () => (open.value = true) }, 'Open'),
20
+ h(MDialog, { modelValue: open.value, 'onUpdate:modelValue': (v: boolean) => (open.value = v), title: 'Hi', ...extra }, {
21
+ default: () => [h('input', { id: 'first' }), h('button', { id: 'middle' }, 'x')],
22
+ actions: () => [h('button', { id: 'last' }, 'OK')],
23
+ }),
24
+ ],
25
+ })
26
+ }
27
+
28
+ const mounted: VueWrapper[] = []
29
+ const mount: typeof vtuMount = ((c: any, o: any) => { const w = vtuMount(c, o); mounted.push(w); return w }) as any
30
+ afterEach(() => { mounted.splice(0).forEach((w) => w.unmount()); document.body.innerHTML = '' })
31
+
32
+ describe('modal focus', () => {
33
+ it('MDialog moves focus to its first control (not the close button) on open', async () => {
34
+ const open = ref(false)
35
+ mount(harness(open), { attachTo: document.body, global: { stubs: { transition: false } } })
36
+ ;(document.getElementById('opener') as HTMLElement).focus()
37
+ open.value = true
38
+ await settle()
39
+ expect(document.activeElement?.id).toBe('first')
40
+ })
41
+
42
+ it('honors autofocus', async () => {
43
+ const open = ref(false)
44
+ const C = defineComponent({
45
+ setup: () => () => h(MDialog, { modelValue: open.value, title: 'Hi' }, {
46
+ default: () => [h('input', { id: 'a' }), h('input', { id: 'b', autofocus: true })],
47
+ }),
48
+ })
49
+ mount(C, { attachTo: document.body, global: { stubs: { transition: false } } })
50
+ open.value = true
51
+ await settle()
52
+ expect(document.activeElement?.id).toBe('b')
53
+ })
54
+
55
+ it('Tab wraps from the last control to the first and Shift+Tab back', async () => {
56
+ const open = ref(false)
57
+ mount(harness(open), { attachTo: document.body, global: { stubs: { transition: false } } })
58
+ open.value = true
59
+ await settle()
60
+ ;(document.getElementById('last') as HTMLElement).focus()
61
+ const e = tab()
62
+ expect(e.defaultPrevented).toBe(true)
63
+ // The first focusable in DOM order is the close button, at the top
64
+ expect(document.activeElement?.closest('[data-dialog-close]')).not.toBeNull()
65
+ tab(true)
66
+ expect(document.activeElement?.id).toBe('last')
67
+ })
68
+
69
+ it('returns focus to the opener on close', async () => {
70
+ const open = ref(false)
71
+ mount(harness(open), { attachTo: document.body, global: { stubs: { transition: false } } })
72
+ const opener = document.getElementById('opener') as HTMLElement
73
+ opener.focus()
74
+ open.value = true
75
+ await settle()
76
+ expect(document.activeElement).not.toBe(opener)
77
+ open.value = false
78
+ await settle()
79
+ expect(document.activeElement).toBe(opener)
80
+ })
81
+
82
+ it('only the top-most dialog traps Tab', async () => {
83
+ const outer = ref(true)
84
+ const inner = ref(false)
85
+ const C = defineComponent({
86
+ setup: () => () => h(MDialog, { modelValue: outer.value, title: 'Outer' }, {
87
+ default: () => [
88
+ h('button', { id: 'o1' }, 'o1'),
89
+ h(MDialog, { modelValue: inner.value, title: 'Inner' }, { default: () => [h('button', { id: 'i1' }, 'i1')] }),
90
+ ],
91
+ }),
92
+ })
93
+ mount(C, { attachTo: document.body, global: { stubs: { transition: false } } })
94
+ await settle()
95
+ expect(document.activeElement?.id).toBe('o1')
96
+ inner.value = true
97
+ await settle()
98
+ expect(document.activeElement?.id).toBe('i1')
99
+ tab()
100
+ // Inside the inner dialog: i1 and its close button only
101
+ expect(document.activeElement?.closest('[role="dialog"]')?.textContent).toContain('i1')
102
+ inner.value = false
103
+ await settle()
104
+ expect(document.activeElement?.id).toBe('o1')
105
+ })
106
+
107
+ it('sheets are labelled modal dialogs that take focus', async () => {
108
+ const open = ref(false)
109
+ const C = defineComponent({
110
+ setup: () => () => [
111
+ h(MBottomSheet, { modelValue: open.value, title: 'Filters' }, { default: () => h('button', { id: 'bs' }, 'x') }),
112
+ h(MSideSheet, { modelValue: false, title: 'Side' }),
113
+ ],
114
+ })
115
+ mount(C, { attachTo: document.body, global: { stubs: { transition: false } } })
116
+ open.value = true
117
+ await settle()
118
+ const panel = document.querySelector('[data-sheet-panel]') as HTMLElement
119
+ expect(panel.getAttribute('role')).toBe('dialog')
120
+ expect(panel.getAttribute('aria-modal')).toBe('true')
121
+ expect(document.getElementById(panel.getAttribute('aria-labelledby')!)?.textContent).toBe('Filters')
122
+ expect(document.activeElement?.id).toBe('bs')
123
+ })
124
+ })
@@ -0,0 +1,20 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { formatMessage } from '../composables/useLocale'
3
+
4
+ describe('formatMessage', () => {
5
+ it('fills simple placeholders and leaves unknown ones', () => {
6
+ expect(formatMessage('{from}–{to} of {total}', { from: 1, to: 10, total: 25 })).toBe('1–10 of 25')
7
+ expect(formatMessage('Hi {name}', {})).toBe('Hi {name}')
8
+ })
9
+
10
+ it('picks the plural form for the language', () => {
11
+ const pl = '{count, plural, one {# plik} few {# pliki} many {# plików} other {# pliku}}'
12
+ expect([1, 2, 5, 22, 25, 1.5].map((n) => formatMessage(pl, { count: n }, 'pl'))).toEqual(['1 plik', '2 pliki', '5 plików', '22 pliki', '25 plików', '1.5 pliku'])
13
+ expect(formatMessage('{n, plural, =0 {none} one {one night} other {# nights}}', { n: 0 })).toBe('none')
14
+ expect(formatMessage('{n, plural, one {# night} other {# nights}}', { n: '3' })).toBe('3 nights')
15
+ })
16
+
17
+ it('fills placeholders inside a plural form', () => {
18
+ expect(formatMessage('{count, plural, one {# reply to {name}} other {# replies to {name}}}', { count: 2, name: 'Ana' })).toBe('2 replies to Ana')
19
+ })
20
+ })
@@ -0,0 +1,103 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MTextField from '../components/MTextField.vue'
4
+ import MNumberField from '../components/MNumberField.vue'
5
+ import MMaskField from '../components/MMaskField.vue'
6
+ import MTagInput from '../components/MTagInput.vue'
7
+ import MSelect from '../components/MSelect.vue'
8
+ import MAutocomplete from '../components/MAutocomplete.vue'
9
+ import MCheckbox from '../components/MCheckbox.vue'
10
+ import MSwitch from '../components/MSwitch.vue'
11
+ import MRadio from '../components/MRadio.vue'
12
+
13
+ const native = { inputmode: 'numeric', enterkeyhint: 'next', maxlength: '5', 'aria-label': 'Code' }
14
+
15
+ describe('field attrs reach the native control', () => {
16
+ it('MTextField: native attrs on the input, class/style/data-* on the box', () => {
17
+ const w = mount(MTextField, {
18
+ props: { modelValue: '', label: 'Code' },
19
+ attrs: { ...native, class: 'my-field', style: 'width: 10px', 'data-testid': 'code' },
20
+ })
21
+ const input = w.find('input')
22
+ for (const [k, v] of Object.entries(native)) expect(input.attributes(k)).toBe(v)
23
+ expect(w.classes()).toContain('my-field')
24
+ expect(w.attributes('style')).toContain('width: 10px')
25
+ expect(w.attributes('data-testid')).toBe('code')
26
+ expect(input.attributes('data-testid')).toBeUndefined()
27
+ expect(w.attributes('inputmode')).toBeUndefined()
28
+ })
29
+
30
+ it('MTextField: a consumer id becomes the input id and the label points at it', () => {
31
+ const w = mount(MTextField, { props: { modelValue: '', label: 'Code' }, attrs: { id: 'code' } })
32
+ expect(w.find('input').attributes('id')).toBe('code')
33
+ expect(w.find('label').attributes('for')).toBe('code')
34
+ expect(w.attributes('id')).toBeUndefined()
35
+ })
36
+
37
+ it('MTextField: merges a consumer aria-describedby with its hint', () => {
38
+ const w = mount(MTextField, { props: { modelValue: '', label: 'Code', hint: 'Five digits' }, attrs: { 'aria-describedby': 'extra' } })
39
+ const ids = w.find('input').attributes('aria-describedby')!.split(' ')
40
+ expect(ids).toContain('extra')
41
+ expect(ids).toHaveLength(2)
42
+ })
43
+
44
+ it('MTextField: textarea gets them too, and a placeholder prop', () => {
45
+ const w = mount(MTextField, { props: { modelValue: '', label: 'Notes', multiline: true, placeholder: 'Write…' }, attrs: { maxlength: '10' } })
46
+ expect(w.find('textarea').attributes('maxlength')).toBe('10')
47
+ expect(w.find('textarea').attributes('placeholder')).toBe('Write…')
48
+ })
49
+
50
+ it('MTextField: native listeners fire from the input', async () => {
51
+ let n = 0
52
+ const w = mount(MTextField, { props: { modelValue: '', label: 'Code' }, attrs: { onKeydown: () => n++ } })
53
+ await w.find('input').trigger('keydown', { key: 'a' })
54
+ expect(n).toBe(1)
55
+ })
56
+
57
+ it('MNumberField: attrs and name on the input, localized stepper labels', () => {
58
+ const w = mount(MNumberField, { props: { modelValue: 1, label: 'Qty', name: 'qty' }, attrs: { 'aria-label': 'Quantity' } })
59
+ const input = w.find('input')
60
+ expect(input.attributes('name')).toBe('qty')
61
+ expect(input.attributes('aria-label')).toBe('Quantity')
62
+ const labels = w.findAll('button').map((b) => b.attributes('aria-label'))
63
+ expect(labels).toEqual(['Decrease', 'Increase'])
64
+ })
65
+
66
+ it('MMaskField and MTagInput', () => {
67
+ const m = mount(MMaskField, { props: { modelValue: '', label: 'Card', mask: '#### ####' }, attrs: { autocomplete: 'cc-number' } })
68
+ expect(m.find('input').attributes('autocomplete')).toBe('cc-number')
69
+ const t = mount(MTagInput, { props: { modelValue: [], label: 'Tags' }, attrs: { 'aria-label': 'Tags', id: 'tags' } })
70
+ expect(t.find('input').attributes('aria-label')).toBe('Tags')
71
+ expect(t.find('input').attributes('id')).toBe('tags')
72
+ expect(t.find('label').attributes('for')).toBe('tags')
73
+ })
74
+
75
+ it('MSelect: attrs on the combobox trigger', () => {
76
+ const w = mount(MSelect, {
77
+ props: { modelValue: null, label: 'Fruit', options: [{ label: 'Apple', value: 'a' }] },
78
+ attrs: { 'aria-label': 'Fruit picker', id: 'fruit', class: 'w-40' },
79
+ })
80
+ const trigger = w.find('[role="combobox"]')
81
+ expect(trigger.attributes('aria-label')).toBe('Fruit picker')
82
+ expect(trigger.attributes('id')).toBe('fruit')
83
+ expect(w.find('div').classes()).toContain('w-40')
84
+ })
85
+
86
+ it('MAutocomplete: attrs on the input', () => {
87
+ const w = mount(MAutocomplete, {
88
+ props: { modelValue: null, label: 'City', options: [{ label: 'Rome', value: 'r' }] },
89
+ attrs: { enterkeyhint: 'search' },
90
+ })
91
+ expect(w.find('input').attributes('enterkeyhint')).toBe('search')
92
+ })
93
+
94
+ it('MCheckbox, MSwitch and MRadio: attrs on the native input', () => {
95
+ const c = mount(MCheckbox, { props: { modelValue: false, label: 'A' }, attrs: { name: 'terms', class: 'mt-2' } })
96
+ expect(c.find('input').attributes('name')).toBe('terms')
97
+ expect(c.classes()).toContain('mt-2')
98
+ const s = mount(MSwitch, { props: { modelValue: false }, attrs: { 'aria-label': 'Wifi' } })
99
+ expect(s.find('input').attributes('aria-label')).toBe('Wifi')
100
+ const r = mount(MRadio, { props: { modelValue: null, value: 'a', label: 'A' }, attrs: { id: 'opt-a' } })
101
+ expect(r.find('input').attributes('id')).toBe('opt-a')
102
+ })
103
+ })
@@ -9,6 +9,7 @@ import { jaLocale } from '../locales/ja'
9
9
  import { zhLocale } from '../locales/zh'
10
10
  import { koLocale } from '../locales/ko'
11
11
  import { arLocale } from '../locales/ar'
12
+ import { plLocale } from '../locales/pl'
12
13
 
13
14
  const allLocales: [string, M3Locale][] = [
14
15
  ['es', esLocale],
@@ -19,6 +20,7 @@ const allLocales: [string, M3Locale][] = [
19
20
  ['zh', zhLocale],
20
21
  ['ko', koLocale],
21
22
  ['ar', arLocale],
23
+ ['pl', plLocale],
22
24
  ]
23
25
 
24
26
  const defaultKeys = Object.keys(defaultLocale) as (keyof M3Locale)[]
@@ -0,0 +1,40 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest'
2
+ import { defineComponent, h, nextTick, ref } from 'vue'
3
+ import { mount } from '@vue/test-utils'
4
+ import MMenu from '../components/MMenu.vue'
5
+ import MMenuItem from '../components/MMenuItem.vue'
6
+ import MMenuDivider from '../components/MMenuDivider.vue'
7
+
8
+ // The expressive variant renders its groups through a dynamic component; with an inline `() => group` as its type,
9
+ // every re-render of the menu was a new component type, so Vue tore down and re-created every item (losing focus,
10
+ // state and DOM identity) whenever anything in the menu changed.
11
+ describe('MMenu expressive groups', () => {
12
+ beforeEach(() => { document.body.innerHTML = '' })
13
+
14
+ it('keeps the same item elements across re-renders', async () => {
15
+ const color = ref<'standard' | 'vibrant'>('standard')
16
+ mount(
17
+ defineComponent({
18
+ setup: () => () =>
19
+ h(MMenu, { variant: 'expressive', color: color.value }, {
20
+ trigger: () => h('button', { class: 'trigger' }, 'open'),
21
+ default: () => [
22
+ h(MMenuItem, { label: 'Cut', class: 'first' }),
23
+ h(MMenuDivider, { gap: true }),
24
+ h(MMenuItem, { label: 'Paste' }),
25
+ ],
26
+ }),
27
+ }),
28
+ { attachTo: document.body, global: { stubs: { transition: false } } },
29
+ )
30
+ document.querySelector<HTMLElement>('.trigger')!.click()
31
+ await nextTick()
32
+ await nextTick()
33
+ const before = document.querySelector('.first')
34
+ expect(before).not.toBeNull()
35
+ color.value = 'vibrant'
36
+ await nextTick()
37
+ await nextTick()
38
+ expect(document.querySelector('.first')).toBe(before)
39
+ })
40
+ })
@@ -0,0 +1,41 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { createSSRApp, defineComponent, h, nextTick } from 'vue'
3
+ import { renderToString } from 'vue/server-renderer'
4
+ import MMenu from '../components/MMenu.vue'
5
+ import MMenuItem from '../components/MMenuItem.vue'
6
+ import MMenuDivider from '../components/MMenuDivider.vue'
7
+
8
+ // Reported from a Nuxt app: an expressive MMenu with `<MMenuDivider gap />` logged "Hydration node mismatch" (and
9
+ // doubled its item labels) on the first click. The groups were rendered through `<component :is="() => group">`, a
10
+ // new component type on every render.
11
+ describe('MMenu after SSR hydration', () => {
12
+ it('opens an expressive grouped menu without hydration mismatches', async () => {
13
+ const App = defineComponent({
14
+ setup: () => () =>
15
+ h(MMenu, { variant: 'expressive' }, {
16
+ trigger: () => h('button', { class: 'trigger' }, 'open'),
17
+ default: () => [h(MMenuItem, null, () => 'Cut'), h(MMenuDivider, { gap: true }), h(MMenuItem, null, () => 'Paste')],
18
+ }),
19
+ })
20
+ const ctx: { teleports?: Record<string, string> } = {}
21
+ const html = await renderToString(createSSRApp(App), ctx)
22
+ // As Nuxt does: teleports to body are prepended to it
23
+ document.body.innerHTML = `${ctx.teleports?.body ?? ''}<div id="app">${html}</div>`
24
+
25
+ const warnings: string[] = []
26
+ const app = createSSRApp(App)
27
+ app.config.warnHandler = (msg) => warnings.push(msg)
28
+ app.mount('#app')
29
+ await nextTick()
30
+ document.querySelector<HTMLElement>('.trigger')!.click()
31
+ await nextTick()
32
+ await new Promise((r) => setTimeout(r, 50))
33
+
34
+ expect(warnings.filter((w) => /hydration/i.test(w))).toEqual([])
35
+ // Each label once (the mismatch left "CutCut")
36
+ const text = document.body.textContent ?? ''
37
+ expect(text.match(/Cut/g)).toHaveLength(1)
38
+ expect(text.match(/Paste/g)).toHaveLength(1)
39
+ app.unmount()
40
+ })
41
+ })
@@ -0,0 +1,28 @@
1
+ import { describe, it, expect, afterEach } from 'vitest'
2
+ import { createApp, h } from 'vue'
3
+ import { createM3UI } from '../plugin'
4
+ import { getMotionScheme, shouldReduceMotion, motionSprings } from '../composables/motion'
5
+ import { DEFAULT_SPATIAL, FAST_EFFECTS } from '../composables/_useSpring'
6
+
7
+ describe('app motion options', () => {
8
+ afterEach(() => {
9
+ delete document.documentElement.dataset.m3MotionScheme
10
+ delete document.documentElement.dataset.m3Motion
11
+ })
12
+
13
+ it('motionScheme switches the springs components read', () => {
14
+ expect(getMotionScheme()).toBe('standard')
15
+ expect(DEFAULT_SPATIAL.stiffness).toBe(motionSprings.standard.defaultSpatial.stiffness)
16
+ createApp({ render: () => h('div') }).use(createM3UI({ motionScheme: 'expressive' }))
17
+ expect(getMotionScheme()).toBe('expressive')
18
+ expect(DEFAULT_SPATIAL.dampingRatio).toBe(motionSprings.expressive.defaultSpatial.dampingRatio)
19
+ expect(FAST_EFFECTS.stiffness).toBe(3800)
20
+ })
21
+
22
+ it("reducedMotion: 'always' forces reduced motion", () => {
23
+ expect(shouldReduceMotion()).toBe(false)
24
+ createApp({ render: () => h('div') }).use(createM3UI({ reducedMotion: 'always' }))
25
+ expect(document.documentElement.dataset.m3Motion).toBe('reduce')
26
+ expect(shouldReduceMotion()).toBe(true)
27
+ })
28
+ })
@@ -183,6 +183,17 @@ describe('SSR', () => {
183
183
  expect(await renderToString(app)).toBe('<p>large medium</p>')
184
184
  })
185
185
 
186
+ it('reports a phone viewport through useDevice()', async () => {
187
+ const render = async (width?: number) => {
188
+ const app = createSSRApp({ setup: () => { const { isMobile } = lib.useDevice(); return () => h('p', String(isMobile.value)) } })
189
+ app.use(lib.createM3UI(width ? { initialState: { viewport: { width, height: 800 } } } : {}))
190
+ return renderToString(app)
191
+ }
192
+ expect(await render(390)).toBe('<p>true</p>')
193
+ expect(await render(1280)).toBe('<p>false</p>')
194
+ expect(await render()).toBe('<p>false</p>')
195
+ })
196
+
186
197
  it('without it, keeps reporting the module defaults', async () => {
187
198
  expect(await state({ palette: 'red' })).toBe('system purple standard standard')
188
199
  })
@@ -0,0 +1,20 @@
1
+ import { describe, it, expect, vi, afterEach } from 'vitest'
2
+ import { useToast } from '../composables/useToast'
3
+ import { useNotification } from '../composables/useNotification'
4
+
5
+ afterEach(() => vi.unstubAllGlobals())
6
+
7
+ describe('toasts on the server', () => {
8
+ it('show() does nothing without a document (no shared module state, no timers)', () => {
9
+ const toast = useToast()
10
+ const notes = useNotification()
11
+ const before = toast.toasts.value.length
12
+ const beforeN = notes.notifications.value.length
13
+ vi.stubGlobal('document', undefined)
14
+ expect(toast.show('leaks?', 'info')).toBe(-1)
15
+ expect(notes.show('leaks?')).toBe(-1)
16
+ vi.unstubAllGlobals()
17
+ expect(toast.toasts.value.length).toBe(before)
18
+ expect(notes.notifications.value.length).toBe(beforeN)
19
+ })
20
+ })