@m3ui-vue/m3ui-vue 1.4.0 → 1.4.2

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 (95) hide show
  1. package/dist/API.md +295 -11
  2. package/dist/{MButton-DQMTIlaV.js → MButton-D7M324r9.js} +2 -2
  3. package/dist/{MButton-DQMTIlaV.js.map → MButton-D7M324r9.js.map} +1 -1
  4. package/dist/{MDialog-cdgapGfZ.js → MDialog-DuOnNF9s.js} +2 -2
  5. package/dist/{MDialog-cdgapGfZ.js.map → MDialog-DuOnNF9s.js.map} +1 -1
  6. package/dist/{MListItem-ZkSGIIrb.js → MListItem-Bb84X6ex.js} +144 -120
  7. package/dist/{MListItem-ZkSGIIrb.js.map → MListItem-Bb84X6ex.js.map} +1 -1
  8. package/dist/{MLoadingIndicator-U6_oGx8z.js → MLoadingIndicator-BUGRo2Tu.js} +2 -2
  9. package/dist/{MLoadingIndicator-U6_oGx8z.js.map → MLoadingIndicator-BUGRo2Tu.js.map} +1 -1
  10. package/dist/{MSeekBar-DTZVizZg.js → MSeekBar-BQUvUqb9.js} +2 -2
  11. package/dist/{MSeekBar-DTZVizZg.js.map → MSeekBar-BQUvUqb9.js.map} +1 -1
  12. package/dist/{MSlider-CqJkEYRZ.js → MSlider-SFdjE1Hy.js} +2 -2
  13. package/dist/{MSlider-CqJkEYRZ.js.map → MSlider-SFdjE1Hy.js.map} +1 -1
  14. package/dist/{MSpinner-Btgc-0nb.js → MSpinner-DKGNN64_.js} +2 -2
  15. package/dist/{MSpinner-Btgc-0nb.js.map → MSpinner-DKGNN64_.js.map} +1 -1
  16. package/dist/{MTextField-B6M0gJEO.js → MTextField-Utsef6Kk.js} +2 -2
  17. package/dist/{MTextField-B6M0gJEO.js.map → MTextField-Utsef6Kk.js.map} +1 -1
  18. package/dist/{MTooltip-Dspji4XG.js → MTooltip-BhTFQ9Z2.js} +4 -4
  19. package/dist/{MTooltip-Dspji4XG.js.map → MTooltip-BhTFQ9Z2.js.map} +1 -1
  20. package/dist/api.json +1 -1
  21. package/dist/code-editor.js +1 -1
  22. package/dist/components/MAvailabilityCalendar.vue.d.ts +1 -1
  23. package/dist/components/MCalendarHeatmap.vue.d.ts +120 -0
  24. package/dist/components/MCountdown.vue.d.ts +80 -0
  25. package/dist/components/MDatePicker.vue.d.ts +5 -0
  26. package/dist/components/MDatePickerModal.vue.d.ts +5 -0
  27. package/dist/components/MDateRangePicker.vue.d.ts +5 -0
  28. package/dist/components/MDateRangePickerModal.vue.d.ts +5 -0
  29. package/dist/components/MLightbox.vue.d.ts +1 -1
  30. package/dist/components/MListItem.vue.d.ts +10 -6
  31. package/dist/components/MMeterGroup.vue.d.ts +98 -0
  32. package/dist/components/MPhoneInput.vue.d.ts +72 -0
  33. package/dist/components/MSeekBar.vue.d.ts +1 -1
  34. package/dist/components/MTreeTable.vue.d.ts +1 -1
  35. package/dist/components/MTypewriter.vue.d.ts +57 -0
  36. package/dist/components/MVideoPlayer.vue.d.ts +1 -1
  37. package/dist/components/_MMonthYearButton.vue.d.ts +16 -0
  38. package/dist/components/_MYearGrid.vue.d.ts +19 -0
  39. package/dist/composables/_useCalendarMonth.d.ts +7 -0
  40. package/dist/composables/phoneNumber.d.ts +39 -0
  41. package/dist/composables/useLocale.d.ts +18 -0
  42. package/dist/data/phone-countries.d.ts +2 -0
  43. package/dist/draw.js +2 -2
  44. package/dist/flow.js +1 -1
  45. package/dist/gantt.js +1 -1
  46. package/dist/index.d.ts +10 -0
  47. package/dist/locales/index.js +63 -0
  48. package/dist/locales/index.js.map +1 -1
  49. package/dist/m3ui-vue.css +1 -1
  50. package/dist/m3ui.js +5133 -3366
  51. package/dist/m3ui.js.map +1 -1
  52. package/dist/map.js +5 -5
  53. package/dist/media.js +4 -4
  54. package/dist/pdf.js +4 -4
  55. package/dist/rich-text-editor.js +4 -4
  56. package/dist/styles.css +1 -1
  57. package/dist/{useLocale-DLKJIRFi.js → useLocale-B8YKWg-H.js} +10 -1
  58. package/dist/useLocale-B8YKWg-H.js.map +1 -0
  59. package/package.json +1 -1
  60. package/src/__tests__/MCalendarHeatmap.test.ts +79 -0
  61. package/src/__tests__/MCountdown.test.ts +75 -0
  62. package/src/__tests__/MListItemNestedControl.test.ts +88 -0
  63. package/src/__tests__/MMeterGroup.test.ts +43 -0
  64. package/src/__tests__/MPhoneInput.test.ts +97 -0
  65. package/src/__tests__/MTypewriter.test.ts +50 -0
  66. package/src/__tests__/calendarMonth.test.ts +104 -0
  67. package/src/__tests__/clearToNull.test.ts +30 -0
  68. package/src/__tests__/ssr.test.ts +4 -0
  69. package/src/components/MAutocomplete.vue +2 -2
  70. package/src/components/MCalendarHeatmap.vue +349 -0
  71. package/src/components/MCountdown.vue +200 -0
  72. package/src/components/MDatePicker.vue +74 -34
  73. package/src/components/MDatePickerModal.vue +79 -36
  74. package/src/components/MDateRangePicker.vue +73 -33
  75. package/src/components/MDateRangePickerModal.vue +75 -35
  76. package/src/components/MListItem.vue +54 -8
  77. package/src/components/MMeterGroup.vue +196 -0
  78. package/src/components/MPhoneInput.vue +480 -0
  79. package/src/components/MSelect.vue +2 -2
  80. package/src/components/MTypewriter.vue +195 -0
  81. package/src/components/_MMonthYearButton.vue +36 -0
  82. package/src/components/_MYearGrid.vue +106 -0
  83. package/src/composables/_useCalendarMonth.ts +32 -2
  84. package/src/composables/phoneNumber.ts +137 -0
  85. package/src/composables/useLocale.ts +27 -0
  86. package/src/data/phone-countries.ts +62 -0
  87. package/src/index.ts +10 -0
  88. package/src/locales/de.ts +9 -0
  89. package/src/locales/es.ts +9 -0
  90. package/src/locales/fr.ts +9 -0
  91. package/src/locales/ja.ts +9 -0
  92. package/src/locales/ko.ts +9 -0
  93. package/src/locales/pt.ts +9 -0
  94. package/src/locales/zh.ts +9 -0
  95. package/dist/useLocale-DLKJIRFi.js.map +0 -1
@@ -0,0 +1,79 @@
1
+ import { describe, it, expect, afterEach } from 'vitest'
2
+ import { nextTick } from 'vue'
3
+ import { mount } from '@vue/test-utils'
4
+ import MCalendarHeatmap from '../components/MCalendarHeatmap.vue'
5
+
6
+ afterEach(() => { document.body.innerHTML = '' })
7
+
8
+ const cells = (w: ReturnType<typeof mount>) => w.findAll('[role="gridcell"]')
9
+ const cell = (w: ReturnType<typeof mount>, date: string) => w.find(`[data-date="${date}"]`)
10
+
11
+ describe('MCalendarHeatmap', () => {
12
+ it('lays out the range as weeks of 7 rows, Monday first, with the days outside it hidden', () => {
13
+ // 2026-11-01 is a Sunday: its week starts on Monday 2026-10-26
14
+ const w = mount(MCalendarHeatmap, { props: { data: {}, start: '2026-11-01', end: '2026-11-14', locale: 'en-US' } })
15
+ expect(cells(w)).toHaveLength(14)
16
+ expect(w.findAll('[role="row"]')).toHaveLength(7)
17
+ // Sunday is the last row; its first column holds 1 Nov
18
+ const rows = w.findAll('[role="row"]')
19
+ expect(rows[6]!.findAll('[role="gridcell"]')[0]!.attributes('data-date')).toBe('2026-11-01')
20
+ expect(rows[0]!.find('[role="presentation"]').exists()).toBe(true)
21
+ })
22
+
23
+ it('tints days by level, relative to the largest value or max', async () => {
24
+ const w = mount(MCalendarHeatmap, {
25
+ props: { data: [{ date: '2026-11-02', value: 1 }, { date: '2026-11-03', value: 4 }, { date: '2026-11-03', value: 4 }], start: '2026-11-02', end: '2026-11-08', locale: 'en-US' },
26
+ })
27
+ const level = (d: string) => cell(w, d).attributes('data-level')
28
+ // 0 → empty; 1 of 8 → the first tint; 8 of 8 → the last (levels 5: 0..4)
29
+ expect([level('2026-11-04'), level('2026-11-02'), level('2026-11-03')]).toEqual(['0', '1', '4'])
30
+ await w.setProps({ max: 2 })
31
+ expect(level('2026-11-02')).toBe('2')
32
+ })
33
+
34
+ it('selects with a click and moves with the arrows (a day up/down, a week left/right)', async () => {
35
+ const w = mount(MCalendarHeatmap, { props: { data: { '2026-11-10': 3 }, start: '2026-11-02', end: '2026-11-22', locale: 'en-US', modelValue: '2026-11-10' }, attachTo: document.body })
36
+ await cell(w, '2026-11-12').trigger('click')
37
+ expect(w.emitted('update:modelValue')![0]).toEqual(['2026-11-12'])
38
+ expect(w.emitted('select')![0]).toEqual([{ date: '2026-11-12', value: 0, level: 0 }])
39
+ await w.setProps({ modelValue: '2026-11-12' })
40
+ expect(cell(w, '2026-11-12').attributes('tabindex')).toBe('0')
41
+ const grid = w.find('[role="grid"]')
42
+ await grid.trigger('keydown', { key: 'ArrowRight' })
43
+ await nextTick()
44
+ expect(document.activeElement?.getAttribute('data-date')).toBe('2026-11-19')
45
+ await grid.trigger('keydown', { key: 'ArrowUp' })
46
+ await nextTick()
47
+ expect(document.activeElement?.getAttribute('data-date')).toBe('2026-11-18')
48
+ // Past the end: stays
49
+ await grid.trigger('keydown', { key: 'ArrowRight' })
50
+ await nextTick()
51
+ expect(document.activeElement?.getAttribute('data-date')).toBe('2026-11-18')
52
+ await grid.trigger('keydown', { key: 'Enter' })
53
+ expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['2026-11-18'])
54
+ w.unmount()
55
+ })
56
+
57
+ it('names days for screen readers and the tooltip, with a custom format', async () => {
58
+ const w = mount(MCalendarHeatmap, {
59
+ props: { data: { '2026-11-10': 1234 }, start: '2026-11-09', end: '2026-11-15', locale: 'en-US' },
60
+ attachTo: document.body,
61
+ })
62
+ expect(cell(w, '2026-11-10').attributes('aria-label')).toBe('1,234 · Tue, Nov 10, 2026')
63
+ await cell(w, '2026-11-10').trigger('mouseenter')
64
+ expect(w.text()).toContain('1,234 · Tue, Nov 10, 2026')
65
+ await w.setProps({ formatTooltip: (c: { value: number }) => `${c.value} commits` })
66
+ expect(cell(w, '2026-11-10').attributes('aria-label')).toBe('1234 commits')
67
+ w.unmount()
68
+ })
69
+
70
+ it('labels months and Mon/Wed/Fri, in the locale given', () => {
71
+ const w = mount(MCalendarHeatmap, { props: { data: {}, start: '2026-09-01', end: '2026-11-30', locale: 'es-ES' } })
72
+ const text = w.text()
73
+ expect(text).toMatch(/sept?/i)
74
+ expect(text).toMatch(/oct/i)
75
+ expect(text).toMatch(/nov/i)
76
+ // The legend's words come from the app's locale strings
77
+ expect(text).toContain('Less')
78
+ })
79
+ })
@@ -0,0 +1,75 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import { nextTick } from 'vue'
4
+ import MCountdown from '../components/MCountdown.vue'
5
+
6
+ const T0 = new Date('2026-01-01T00:00:00Z').getTime()
7
+ const D = 86_400_000, H = 3_600_000, M = 60_000, S = 1000
8
+
9
+ describe('MCountdown', () => {
10
+ beforeEach(() => {
11
+ vi.useFakeTimers()
12
+ vi.setSystemTime(T0)
13
+ })
14
+ afterEach(() => vi.useRealTimers())
15
+
16
+ it('splits the time left into the units', () => {
17
+ const w = mount(MCountdown, { props: { to: T0 + 2 * D + 3 * H + 4 * M + 5 * S, animate: false } })
18
+ const p = (w.vm as any).parts
19
+ expect([p.days, p.hours, p.minutes, p.seconds]).toEqual([2, 3, 4, 5])
20
+ expect(w.attributes('role')).toBe('timer')
21
+ })
22
+
23
+ it('folds units left out into the next larger one shown', () => {
24
+ const w = mount(MCountdown, { props: { to: T0 + 2 * D + 3 * H + 30 * S, units: ['hours', 'minutes'], animate: false } })
25
+ const p = (w.vm as any).parts
26
+ // 51h, and the 30s round up into the minutes.
27
+ expect([p.hours, p.minutes]).toEqual([51, 1])
28
+ })
29
+
30
+ it('ticks down and emits finished once', async () => {
31
+ const w = mount(MCountdown, { props: { to: T0 + 3 * S, animate: false } })
32
+ expect((w.vm as any).parts.seconds).toBe(3)
33
+ await vi.advanceTimersByTimeAsync(1000)
34
+ expect((w.vm as any).parts.seconds).toBe(2)
35
+ await vi.advanceTimersByTimeAsync(5000)
36
+ expect((w.vm as any).parts.finished).toBe(true)
37
+ expect(w.emitted('finished')).toHaveLength(1)
38
+ expect(w.emitted('tick')!.length).toBeGreaterThanOrEqual(3)
39
+ })
40
+
41
+ it("doesn't emit finished when mounted with a past date, and shows the #finished slot", async () => {
42
+ const w = mount(MCountdown, { props: { to: T0 - 1000 }, slots: { finished: '<b>Done</b>' } })
43
+ await vi.advanceTimersByTimeAsync(2000)
44
+ expect(w.emitted('finished')).toBeUndefined()
45
+ expect(w.html()).toContain('<b>Done</b>')
46
+ })
47
+
48
+ it('restarts when `to` moves to the future', async () => {
49
+ const w = mount(MCountdown, { props: { to: T0 - 1000, animate: false } })
50
+ await w.setProps({ to: T0 + 2 * S })
51
+ await vi.advanceTimersByTimeAsync(3000)
52
+ expect(w.emitted('finished')).toHaveLength(1)
53
+ })
54
+
55
+ it('hideEmpty drops leading zero units but keeps the last', async () => {
56
+ const w = mount(MCountdown, { props: { to: T0 + 5 * M, hideEmpty: true, animate: false } })
57
+ await nextTick()
58
+ expect(w.findAll('.rounded-md')).toHaveLength(2) // minutes + seconds
59
+ })
60
+
61
+ it('names units in the given language, plural-aware', () => {
62
+ const w = mount(MCountdown, { props: { to: T0 + 1 * D + 2 * H, units: ['days', 'hours'], locale: 'es', animate: false } })
63
+ expect(w.text()).toContain('día')
64
+ expect(w.text()).toContain('horas')
65
+ expect(w.attributes('aria-label')).toMatch(/1 día, 2 horas/)
66
+ })
67
+
68
+ it('hands the parts to a custom default slot', () => {
69
+ const w = mount(MCountdown, {
70
+ props: { to: T0 + 90 * S },
71
+ slots: { default: `<template #default="{ minutes, seconds }">{{ minutes }}m{{ seconds }}s</template>` },
72
+ })
73
+ expect(w.text()).toBe('1m30s')
74
+ })
75
+ })
@@ -0,0 +1,88 @@
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 MListItem from '../components/MListItem.vue'
5
+ import MIconButton from '../components/MIconButton.vue'
6
+ import MSwitch from '../components/MSwitch.vue'
7
+
8
+ let wrapper: VueWrapper | undefined
9
+ afterEach(() => {
10
+ wrapper?.unmount()
11
+ wrapper = undefined
12
+ document.body.innerHTML = ''
13
+ })
14
+
15
+ const settle = () => new Promise((r) => setTimeout(r, 600))
16
+ const radius = (el: Element) => (el as HTMLElement).style.borderRadius
17
+ const layer = (row: Element) => (row.querySelector('.mli-state-layer') as HTMLElement).style.opacity
18
+ const down = (el: Element) => el.dispatchEvent(new PointerEvent('pointerdown', { button: 0, pointerType: 'mouse', bubbles: true }))
19
+ const move = (el: Element) => el.dispatchEvent(new PointerEvent('pointermove', { pointerType: 'mouse', bubbles: true }))
20
+
21
+ describe('MListItem with a control inside', () => {
22
+ it('pressing a button in #trailing leaves the row unpressed; pressing the text presses it', async () => {
23
+ wrapper = mount(MListItem, {
24
+ props: { title: 'Wi-Fi', clickable: true },
25
+ slots: { trailing: () => h(MIconButton, { icon: 'settings', label: 'Settings' }) },
26
+ attachTo: document.body,
27
+ })
28
+ const row = wrapper.find('.mli-row').element
29
+ const button = row.querySelector('button')!
30
+ await settle()
31
+ expect(radius(row)).toBe('4px')
32
+
33
+ move(button.querySelector('*') ?? button)
34
+ down(button.querySelector('*') ?? button)
35
+ await settle()
36
+ expect(radius(row)).toBe('4px')
37
+ expect(layer(row)).toBe('0')
38
+
39
+ const text = row.querySelector('p')!
40
+ move(text)
41
+ await nextTick()
42
+ expect(layer(row)).toBe('0.08')
43
+ down(text)
44
+ await settle()
45
+ expect(radius(row)).toBe('16px')
46
+ expect(layer(row)).toBe('0.12')
47
+ })
48
+
49
+ it('no CSS hover/active background on the row anymore (they match through nested controls)', () => {
50
+ wrapper = mount(MListItem, { props: { title: 'A', clickable: true }, attachTo: document.body })
51
+ const cls = wrapper.find('.mli-row').classes().join(' ')
52
+ expect(cls).not.toMatch(/(hover|active):bg-/)
53
+ })
54
+
55
+ it('an expandable header takes a #trailing switch that does not toggle it', async () => {
56
+ let on = false
57
+ wrapper = mount(MListItem, {
58
+ props: { title: 'Notifications', expandable: true },
59
+ slots: {
60
+ trailing: () => h(MSwitch, { modelValue: on, 'onUpdate:modelValue': (v: boolean) => (on = v) }),
61
+ children: () => h('p', 'child'),
62
+ },
63
+ attachTo: document.body,
64
+ })
65
+ const header = wrapper.find('[aria-expanded]')
66
+ const sw = header.find('input')
67
+ down(sw.element)
68
+ await settle()
69
+ expect(radius(header.element)).toBe('4px')
70
+ await sw.trigger('click')
71
+ expect(header.attributes('aria-expanded')).toBe('false')
72
+ expect(wrapper.emitted('update:expanded')).toBeUndefined()
73
+ // The header itself still toggles
74
+ await header.trigger('click')
75
+ expect(header.attributes('aria-expanded')).toBe('true')
76
+ })
77
+
78
+ it('indent sets the children padding', async () => {
79
+ wrapper = mount(MListItem, {
80
+ props: { title: 'Group', expandable: true, expanded: true, indent: 12 },
81
+ slots: { children: () => h('p', 'child') },
82
+ })
83
+ await nextTick()
84
+ expect((wrapper.find('.mli-expand-body').element as HTMLElement).style.paddingLeft).toBe('12px')
85
+ await wrapper.setProps({ indent: '0.5rem' })
86
+ expect((wrapper.find('.mli-expand-body').element as HTMLElement).style.paddingLeft).toBe('0.5rem')
87
+ })
88
+ })
@@ -0,0 +1,43 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MMeterGroup from '../components/MMeterGroup.vue'
4
+
5
+ const items = [
6
+ { label: 'Photos', value: 52 },
7
+ { label: 'Apps', value: 28, color: 'tertiary' },
8
+ { label: 'System', value: 18, color: '#123456' },
9
+ ]
10
+
11
+ describe('MMeterGroup', () => {
12
+ it('sizes each segment by its share of max, minus the gaps, and lists what is left', () => {
13
+ const w = mount(MMeterGroup, { props: { items, max: 128, unit: 'GB', animate: false, locale: 'en-US', label: 'Storage' } })
14
+ const segs = w.findAll('.m3-meter-segment')
15
+ expect(segs).toHaveLength(3)
16
+ // 3 segments + the track: 3 gaps of 4px
17
+ expect((segs[0]!.element as HTMLElement).style.width).toBe(`calc((100% - 12px) * ${52 / 128})`)
18
+ expect((segs[1]!.element as HTMLElement).style.backgroundColor).toBe('var(--color-tertiary)')
19
+ expect(w.text()).toContain('98 GB of 128 GB')
20
+ expect(w.text()).toContain('Remaining')
21
+ expect(w.text()).toContain('30 GB')
22
+ })
23
+
24
+ it('without max fills the bar with no track, and scales values over max down', () => {
25
+ const w = mount(MMeterGroup, { props: { items, animate: false } })
26
+ expect((w.findAll('.m3-meter-segment')[0]!.element as HTMLElement).style.width).toBe(`calc((100% - 8px) * ${52 / 98})`)
27
+ expect(w.find('.bg-secondary-container.flex-1').exists()).toBe(false)
28
+ const over = mount(MMeterGroup, { props: { items, max: 50, animate: false } })
29
+ expect((over.findAll('.m3-meter-segment')[2]!.element as HTMLElement).style.width).toBe(`calc((100% - 8px) * ${18 / 98})`)
30
+ })
31
+
32
+ it('shows percentages, a custom format, and emits select', async () => {
33
+ const w = mount(MMeterGroup, { props: { items, max: 200, percent: true, format: (v: number) => `${v}u`, animate: false, locale: 'en-US' } })
34
+ expect(w.text()).toContain('52u · 26%')
35
+ await w.findAll('li')[1]!.trigger('click')
36
+ expect(w.emitted('select')![0]).toEqual([items[1], 1])
37
+ })
38
+
39
+ it('describes every part to screen readers in one label', () => {
40
+ const w = mount(MMeterGroup, { props: { items, max: 128, unit: 'GB', animate: false, locale: 'en-US', label: 'Storage' } })
41
+ expect(w.find('[role="img"]').attributes('aria-label')).toBe('Storage, Photos: 52 GB, Apps: 28 GB, System: 18 GB, Remaining: 30 GB')
42
+ })
43
+ })
@@ -0,0 +1,97 @@
1
+ import { describe, it, expect, afterEach } from 'vitest'
2
+ import { nextTick } from 'vue'
3
+ import { mount } from '@vue/test-utils'
4
+ import MPhoneInput from '../components/MPhoneInput.vue'
5
+ import { formatPhone, isValidPhone, parsePhone } from '../composables/phoneNumber'
6
+
7
+ afterEach(() => { document.body.innerHTML = '' })
8
+
9
+ describe('phoneNumber', () => {
10
+ it('formats stored numbers with the country mask, or groups without one', () => {
11
+ expect(formatPhone('+541123456789')).toBe('+54 11 2345-6789')
12
+ expect(formatPhone('+5491123456789')).toBe('+54 9 11 2345-6789')
13
+ expect(formatPhone('+12125551234')).toBe('+1 (212) 555-1234')
14
+ expect(formatPhone('+5511987654321')).toBe('+55 (11) 98765-4321')
15
+ expect(formatPhone('+4930123456')).toBe('+49 3012 3456')
16
+ expect(formatPhone('not a number')).toBe('not a number')
17
+ })
18
+
19
+ it('parses 00 prefixes, shared calling codes and the trunk 0', () => {
20
+ expect(parsePhone('0034 612 34 56 78')!.country.iso2).toBe('ES')
21
+ expect(parsePhone('+14165551234')!.country.iso2).toBe('US')
22
+ expect(parsePhone('+14165551234', 'CA')!.country.iso2).toBe('CA')
23
+ expect(parsePhone('+44 07911 123456')!.national).toBe('7911123456')
24
+ // Italy keeps its 0
25
+ expect(parsePhone('+39 06 1234 5678')!.national).toBe('0612345678')
26
+ })
27
+
28
+ it('validates lengths against the masks', () => {
29
+ expect(isValidPhone('+541123456789')).toBe(true)
30
+ expect(isValidPhone('+54112345678')).toBe(false)
31
+ expect(isValidPhone('+4930123456')).toBe(true)
32
+ })
33
+ })
34
+
35
+ describe('MPhoneInput', () => {
36
+ const input = (w: ReturnType<typeof mount>) => w.find('input[type="tel"]')
37
+
38
+ it('formats while typing and binds E.164', async () => {
39
+ const w = mount(MPhoneInput, { props: { label: 'Phone', country: 'AR', modelValue: null } })
40
+ await input(w).setValue('01123456789')
41
+ expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['+541123456789'])
42
+ expect((input(w).element as HTMLInputElement).value).toBe('11 2345-6789')
43
+ expect(w.emitted('update:valid')!.at(-1)).toEqual([true])
44
+ })
45
+
46
+ it('shows a bound number formatted and its country', () => {
47
+ const w = mount(MPhoneInput, { props: { label: 'Phone', modelValue: '+5511987654321' } })
48
+ expect((input(w).element as HTMLInputElement).value).toBe('(11) 98765-4321')
49
+ expect(w.text()).toContain('+55')
50
+ })
51
+
52
+ it('switches country when a full international number is pasted', async () => {
53
+ const w = mount(MPhoneInput, { props: { label: 'Phone', country: 'AR', modelValue: null } })
54
+ await input(w).setValue('+34 612345678')
55
+ expect(w.emitted('update:country')!.at(-1)).toEqual(['ES'])
56
+ expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['+34612345678'])
57
+ })
58
+
59
+ it('backspace after a separator deletes the digit before it', async () => {
60
+ const w = mount(MPhoneInput, { props: { label: 'Phone', country: 'US', modelValue: '+12125' }, attachTo: document.body })
61
+ const el = input(w).element as HTMLInputElement
62
+ expect(el.value).toBe('(212) 5')
63
+ el.setSelectionRange(5, 5) // after "(212)"
64
+ await input(w).trigger('keydown', { key: 'Backspace' })
65
+ expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['+1215'])
66
+ w.unmount()
67
+ })
68
+
69
+ it('flags an incomplete number after leaving the field', async () => {
70
+ const w = mount(MPhoneInput, { props: { label: 'Phone', country: 'AR', modelValue: '+54112', locale: 'en' } })
71
+ expect(w.text()).not.toContain('Incomplete')
72
+ await input(w).trigger('blur')
73
+ expect(w.text()).toContain('Incomplete phone number')
74
+ })
75
+
76
+ it('picks a country from the searchable list', async () => {
77
+ const w = mount(MPhoneInput, { props: { label: 'Phone', country: 'AR', modelValue: '+541123456789', locale: 'en', preferred: ['MX'] }, attachTo: document.body })
78
+ await w.find('button[aria-haspopup="listbox"]').trigger('click')
79
+ await nextTick()
80
+ const opts = document.querySelectorAll('[role="option"]')
81
+ // Preferred first, then a separator, then everything
82
+ expect(opts[0]!.textContent).toContain('Mexico')
83
+ const search = document.querySelector<HTMLInputElement>('[role="combobox"]')!
84
+ search.value = 'spai'
85
+ search.dispatchEvent(new Event('input'))
86
+ await nextTick()
87
+ const found = document.querySelectorAll('[role="option"]')
88
+ expect(found).toHaveLength(1)
89
+ expect(found[0]!.textContent).toContain('Spain')
90
+ search.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter' }))
91
+ await nextTick()
92
+ expect(w.emitted('update:country')!.at(-1)).toEqual(['ES'])
93
+ expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['+341123456789'])
94
+ expect(document.querySelector('[role="listbox"]')).toBeNull()
95
+ w.unmount()
96
+ })
97
+ })
@@ -0,0 +1,50 @@
1
+ import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest'
2
+ import { nextTick } from 'vue'
3
+ import { mount } from '@vue/test-utils'
4
+ import MTypewriter from '../components/MTypewriter.vue'
5
+
6
+ beforeEach(() => vi.useFakeTimers())
7
+ afterEach(() => vi.useRealTimers())
8
+
9
+ const typed = (w: ReturnType<typeof mount>) => w.find('[aria-hidden="true"]').element.textContent
10
+ const opts = { typeSpeed: 10, deleteSpeed: 5, pause: 100, startDelay: 0, humanize: false, startOnVisible: false }
11
+
12
+ describe('MTypewriter', () => {
13
+ it('types a phrase out, one grapheme at a time', async () => {
14
+ const w = mount(MTypewriter, { props: { text: 'Hola 👋🏽', ...opts } })
15
+ await vi.advanceTimersByTimeAsync(0)
16
+ expect(typed(w)).toBe('H')
17
+ await vi.advanceTimersByTimeAsync(30)
18
+ expect(typed(w)).toBe('Hola')
19
+ // The waving hand with its skin tone is one keystroke
20
+ await vi.advanceTimersByTimeAsync(20)
21
+ expect(typed(w)).toBe('Hola 👋🏽')
22
+ await vi.advanceTimersByTimeAsync(10)
23
+ expect(w.emitted('typed')).toEqual([[0]])
24
+ })
25
+
26
+ it('erases only the end that differs, then types the next phrase, in a loop', async () => {
27
+ const w = mount(MTypewriter, { props: { text: ['build faster', 'build better'], ...opts } })
28
+ await vi.advanceTimersByTimeAsync(12 * 10 + 1)
29
+ expect(typed(w)).toBe('build faster')
30
+ await vi.advanceTimersByTimeAsync(100 + 6 * 5)
31
+ expect(typed(w)).toBe('build ')
32
+ await vi.advanceTimersByTimeAsync(30 + 6 * 10)
33
+ expect(typed(w)).toBe('build better')
34
+ await vi.advanceTimersByTimeAsync(100 + 6 * 5 + 30 + 6 * 10)
35
+ expect(typed(w)).toBe('build faster')
36
+ })
37
+
38
+ it('stops on the last phrase without loop and emits done', async () => {
39
+ const w = mount(MTypewriter, { props: { text: ['a', 'b'], loop: false, ...opts } })
40
+ await vi.advanceTimersByTimeAsync(1000)
41
+ expect(typed(w)).toBe('b')
42
+ expect(w.emitted('done')).toHaveLength(1)
43
+ })
44
+
45
+ it('gives screen readers every phrase once', async () => {
46
+ const w = mount(MTypewriter, { props: { text: ['one', 'two'], ...opts } })
47
+ await nextTick()
48
+ expect(w.find('.sr-only').text()).toBe('one, two')
49
+ })
50
+ })
@@ -56,4 +56,108 @@ describe('useCalendarMonth (the date pickers\' shared month grid)', () => {
56
56
  expect(document.body.textContent).toContain('April 2026')
57
57
  w.unmount()
58
58
  })
59
+
60
+ it('lists every year of the range, disabling the ones min/max leave no day in (as Compose)', () => {
61
+ const view = ref(new Date('2026-03-10T00:00:00'))
62
+ const all = useCalendarMonth(view, { locale: () => 'en-US', min: () => undefined, max: () => undefined })
63
+ expect(all.years.value[0]).toEqual({ year: 1900, disabled: false })
64
+ expect(all.years.value.at(-1)).toEqual({ year: 2100, disabled: false })
65
+ const narrow = useCalendarMonth(view, { locale: () => 'en-US', min: () => '2020-06-15', max: () => '2030-02-01', yearRange: () => [2018, 2032] })
66
+ expect(narrow.years.value.filter((y) => !y.disabled).map((y) => y.year)).toEqual([2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030])
67
+ expect(narrow.years.value.filter((y) => y.disabled).map((y) => y.year)).toEqual([2018, 2019, 2031, 2032])
68
+ })
69
+
70
+ it('showYear keeps the month on view, brought inside min/max', () => {
71
+ const view = ref(new Date('2026-03-10T00:00:00'))
72
+ const { showYear, monthLabel } = useCalendarMonth(view, { locale: () => 'en-US', min: () => '2020-06-15', max: () => '2030-02-01' })
73
+ showYear(2023)
74
+ expect(monthLabel.value).toBe('March 2023')
75
+ showYear(2020)
76
+ expect(monthLabel.value).toBe('June 2020')
77
+ showYear(2030)
78
+ expect(monthLabel.value).toBe('February 2030')
79
+ })
80
+
81
+ it('the modal date picker jumps to a year from the grid its month title opens', async () => {
82
+ const w = mount(MDatePickerModal, { props: { modelValue: '2026-03-12', show: false, locale: 'en-US', max: '2026-12-31' }, attachTo: document.body })
83
+ await w.setProps({ show: true })
84
+ await nextTick()
85
+ const toggle = document.querySelector<HTMLElement>('[aria-expanded]')!
86
+ expect(toggle.getAttribute('aria-expanded')).toBe('false')
87
+ toggle.click()
88
+ await nextTick()
89
+ await nextTick()
90
+ const grid = document.querySelector<HTMLElement>('[role="radiogroup"]')!
91
+ expect(grid).toBeTruthy()
92
+ // The arrows hide while the grid is open
93
+ expect(document.querySelector('[aria-label="Next month"]')).toBeNull()
94
+ const checked = grid.querySelector<HTMLElement>('[aria-checked="true"]')!
95
+ // The whole range, the years after max disabled
96
+ const yearBtn = (y: string) => Array.from(grid.querySelectorAll<HTMLButtonElement>('button')).find((b) => b.textContent!.trim() === y)!
97
+ expect(yearBtn('2100').disabled).toBe(true)
98
+ expect(yearBtn('2026').disabled).toBe(false)
99
+ expect(checked.textContent!.trim()).toBe('2026')
100
+ expect(document.activeElement).toBe(checked)
101
+ // Arrow up: three years back (one row)
102
+ checked.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowUp', bubbles: true }))
103
+ expect(document.activeElement!.textContent!.trim()).toBe('2023')
104
+ const y1995 = Array.from(grid.querySelectorAll<HTMLElement>('button')).find((b) => b.textContent!.trim() === '1995')!
105
+ y1995.click()
106
+ await nextTick()
107
+ expect(document.querySelector('[role="radiogroup"]')).toBeNull()
108
+ expect(document.body.textContent).toContain('March 1995')
109
+ expect(document.querySelector('[aria-label="Next month"]')).toBeTruthy()
110
+ // Picking a day there and confirming
111
+ const day = Array.from(document.querySelectorAll<HTMLElement>('button')).find((b) => b.textContent!.trim() === '20')!
112
+ day.click()
113
+ await nextTick()
114
+ Array.from(document.querySelectorAll<HTMLElement>('button')).find((b) => b.textContent!.trim() === 'OK')!.click()
115
+ expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['1995-03-20'])
116
+ w.unmount()
117
+ })
118
+
119
+ // The other three pickers share the grid (_MYearGrid) and the menu button (_MMonthYearButton)
120
+ const openYearsAndPick = async (year: string) => {
121
+ const toggle = document.querySelector<HTMLElement>('[aria-expanded]')!
122
+ toggle.click()
123
+ await nextTick()
124
+ await nextTick()
125
+ const grid = document.querySelector<HTMLElement>('[role="radiogroup"]')!
126
+ expect(grid).toBeTruthy()
127
+ expect(document.querySelector('[aria-label="Next month"]')).toBeNull()
128
+ const btn = Array.from(grid.querySelectorAll<HTMLButtonElement>('button')).find((b) => b.textContent!.trim() === year)!
129
+ btn.click()
130
+ await nextTick()
131
+ expect(document.querySelector('[role="radiogroup"]')).toBeNull()
132
+ return grid
133
+ }
134
+
135
+ it.each([
136
+ ['MDatePicker', () => import('../components/MDatePicker.vue'), { modelValue: '2026-03-12' }],
137
+ ['MDateRangePicker', () => import('../components/MDateRangePicker.vue'), { modelValue: { start: '2026-03-12', end: null } }],
138
+ ])('%s (docked) jumps to a year from its month title', async (_name, load, extra) => {
139
+ const C = (await load()).default
140
+ const w = mount(C as never, { props: { locale: 'en-US', ...extra }, attachTo: document.body })
141
+ await w.find('button').trigger('click')
142
+ await nextTick()
143
+ await openYearsAndPick('1995')
144
+ expect(document.body.textContent).toContain('March 1995')
145
+ w.unmount()
146
+ })
147
+
148
+ it('MDateRangePickerModal jumps to a year from its month title, disabling the years past max', async () => {
149
+ const C = (await import('../components/MDateRangePickerModal.vue')).default
150
+ const w = mount(C, { props: { modelValue: { start: '2026-03-12', end: null }, show: false, locale: 'en-US', max: '2026-12-31' }, attachTo: document.body })
151
+ await w.setProps({ show: true })
152
+ await nextTick()
153
+ document.querySelector<HTMLElement>('[aria-expanded]')!.click()
154
+ await nextTick()
155
+ const later = Array.from(document.querySelectorAll<HTMLButtonElement>('[role="radio"]')).find((b) => b.textContent!.trim() === '2027')!
156
+ expect(later.disabled).toBe(true)
157
+ document.querySelector<HTMLElement>('[aria-expanded]')!.click()
158
+ await nextTick()
159
+ await openYearsAndPick('2001')
160
+ expect(document.body.textContent).toContain('March 2001')
161
+ w.unmount()
162
+ })
59
163
  })
@@ -0,0 +1,30 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import MSelect from '../components/MSelect.vue'
4
+ import MAutocomplete from '../components/MAutocomplete.vue'
5
+
6
+ const options = [
7
+ { value: 1, label: 'One' },
8
+ { value: 2, label: 'Two' },
9
+ ]
10
+
11
+ // The clear (X) button must leave the v-model at null, not undefined: undefined drops the key
12
+ // from JSON.stringify, so a form sent to an API never told the backend the field was emptied.
13
+ describe.each([
14
+ ['MSelect', MSelect],
15
+ ['MAutocomplete', MAutocomplete],
16
+ ])('%s clear button', (_name, Comp) => {
17
+ it('emits null', async () => {
18
+ const wrapper = mount(Comp as any, {
19
+ props: { modelValue: 1, options, clearable: true, label: 'Field' },
20
+ attachTo: document.body,
21
+ })
22
+ const clear = wrapper.find('button[aria-label="Clear"]')
23
+ expect(clear.exists()).toBe(true)
24
+ await clear.trigger('click')
25
+ const emitted = wrapper.emitted('update:modelValue')!
26
+ expect(emitted.at(-1)).toEqual([null])
27
+ expect(emitted.at(-1)![0]).not.toBeUndefined()
28
+ wrapper.unmount()
29
+ })
30
+ })
@@ -36,6 +36,10 @@ const props: Record<string, Record<string, unknown>> = {
36
36
  MOrderBook: { bids: [[1, 1]], asks: [[2, 1]] },
37
37
  MMortgageCalculator: { modelValue: { price: 100, down: 10, rate: 5, years: 10 } },
38
38
  MVitalsChart: { series: [{ key: 'hr', label: 'HR', data: [{ time: 0, value: 70 }] }] },
39
+ MCalendarHeatmap: { data: { '2026-11-20': 3 }, end: '2026-11-21' },
40
+ MMeterGroup: { items: [{ label: 'A', value: 1 }], max: 4 },
41
+ MTypewriter: { text: ['a', 'b'] },
42
+ MPhoneInput: { label: 'Phone', modelValue: '+541123456789' },
39
43
  MQuiz: { questions: [{ id: 1, prompt: 'Q', options: ['a', 'b'], answer: 0 }] },
40
44
  MCertificate: { recipient: 'Ana' },
41
45
  MPasswordMeter: { value: 'abc' },
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * Like MSelect but with a text input for filtering. Type to search, arrow keys to navigate, Enter to select.
4
4
  *
5
- * @event update:modelValue Emitted on selection — powers v-model
5
+ * @event update:modelValue Emitted on selection — powers v-model (`null` when the clear button empties it)
6
6
  * @event debounced Emitted debounce ms after the user stops typing the search query (only when debounce > 0)
7
7
  */
8
8
  import { computed, ref, useId, onMounted, onUnmounted, watch, nextTick } from 'vue'
@@ -393,7 +393,7 @@ const labelClasses = computed(() => {
393
393
  v-if="clearable && hasValue && !disabled"
394
394
  type="button"
395
395
  class="absolute right-9 top-1/2 -translate-y-1/2 flex h-6 w-6 cursor-pointer items-center justify-center rounded-full text-on-surface-variant transition-colors hover:bg-on-surface/8 hover:text-on-surface"
396
- @click.stop="emit('update:modelValue', undefined as any); closeDropdown()"
396
+ @click.stop="emit('update:modelValue', null); closeDropdown()"
397
397
  >
398
398
  <MIcon name="close" :size="18" />
399
399
  </button>