@m3ui-vue/m3ui-vue 1.4.1 → 1.4.3

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 (91) hide show
  1. package/dist/API.md +251 -9
  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/MDatePicker.vue.d.ts +5 -0
  25. package/dist/components/MDatePickerModal.vue.d.ts +5 -0
  26. package/dist/components/MDateRangePicker.vue.d.ts +5 -0
  27. package/dist/components/MDateRangePickerModal.vue.d.ts +5 -0
  28. package/dist/components/MLightbox.vue.d.ts +1 -1
  29. package/dist/components/MListItem.vue.d.ts +10 -6
  30. package/dist/components/MMeterGroup.vue.d.ts +98 -0
  31. package/dist/components/MPhoneInput.vue.d.ts +72 -0
  32. package/dist/components/MSeekBar.vue.d.ts +1 -1
  33. package/dist/components/MTreeTable.vue.d.ts +1 -1
  34. package/dist/components/MTypewriter.vue.d.ts +57 -0
  35. package/dist/components/MVideoPlayer.vue.d.ts +1 -1
  36. package/dist/components/_MMonthYearButton.vue.d.ts +16 -0
  37. package/dist/components/_MYearGrid.vue.d.ts +19 -0
  38. package/dist/composables/_useCalendarMonth.d.ts +7 -0
  39. package/dist/composables/phoneNumber.d.ts +39 -0
  40. package/dist/composables/useLocale.d.ts +18 -0
  41. package/dist/data/phone-countries.d.ts +2 -0
  42. package/dist/draw.js +2 -2
  43. package/dist/flow.js +1 -1
  44. package/dist/gantt.js +1 -1
  45. package/dist/index.d.ts +8 -0
  46. package/dist/locales/index.js +63 -0
  47. package/dist/locales/index.js.map +1 -1
  48. package/dist/m3ui-vue.css +1 -1
  49. package/dist/m3ui.js +3662 -2028
  50. package/dist/m3ui.js.map +1 -1
  51. package/dist/map.js +5 -5
  52. package/dist/media.js +4 -4
  53. package/dist/pdf.js +4 -4
  54. package/dist/rich-text-editor.js +4 -4
  55. package/dist/styles.css +1 -1
  56. package/dist/{useLocale-DLKJIRFi.js → useLocale-B8YKWg-H.js} +10 -1
  57. package/dist/useLocale-B8YKWg-H.js.map +1 -0
  58. package/package.json +1 -1
  59. package/src/__tests__/MCalendarHeatmap.test.ts +79 -0
  60. package/src/__tests__/MListItemNestedControl.test.ts +88 -0
  61. package/src/__tests__/MMeterGroup.test.ts +43 -0
  62. package/src/__tests__/MPhoneInput.test.ts +97 -0
  63. package/src/__tests__/MTabs.test.ts +100 -2
  64. package/src/__tests__/MTypewriter.test.ts +50 -0
  65. package/src/__tests__/calendarMonth.test.ts +104 -0
  66. package/src/__tests__/ssr.test.ts +4 -0
  67. package/src/components/MCalendarHeatmap.vue +349 -0
  68. package/src/components/MDatePicker.vue +74 -34
  69. package/src/components/MDatePickerModal.vue +79 -36
  70. package/src/components/MDateRangePicker.vue +73 -33
  71. package/src/components/MDateRangePickerModal.vue +75 -35
  72. package/src/components/MListItem.vue +54 -8
  73. package/src/components/MMeterGroup.vue +196 -0
  74. package/src/components/MPhoneInput.vue +480 -0
  75. package/src/components/MTabs.vue +33 -6
  76. package/src/components/MTypewriter.vue +195 -0
  77. package/src/components/_MMonthYearButton.vue +36 -0
  78. package/src/components/_MYearGrid.vue +106 -0
  79. package/src/composables/_useCalendarMonth.ts +32 -2
  80. package/src/composables/phoneNumber.ts +137 -0
  81. package/src/composables/useLocale.ts +27 -0
  82. package/src/data/phone-countries.ts +62 -0
  83. package/src/index.ts +8 -0
  84. package/src/locales/de.ts +9 -0
  85. package/src/locales/es.ts +9 -0
  86. package/src/locales/fr.ts +9 -0
  87. package/src/locales/ja.ts +9 -0
  88. package/src/locales/ko.ts +9 -0
  89. package/src/locales/pt.ts +9 -0
  90. package/src/locales/zh.ts +9 -0
  91. 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,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
+ })
@@ -1,5 +1,5 @@
1
- import { describe, it, expect } from 'vitest'
2
- import { mount } from '@vue/test-utils'
1
+ import { describe, it, expect, vi, afterEach } from 'vitest'
2
+ import { mount, flushPromises } from '@vue/test-utils'
3
3
  import MTabs from '../components/MTabs.vue'
4
4
 
5
5
  const tabs = [
@@ -36,4 +36,102 @@ describe('MTabs', () => {
36
36
  await w.findAll('button')[1]!.trigger('click')
37
37
  expect(w.emitted('update:modelValue')).toEqual([['hotels']])
38
38
  })
39
+
40
+ describe('scrollable: keeps the active tab in view (ScrollableTabRow)', () => {
41
+ // A 390px row holding eight 120px tabs (960px of content): happy-dom has
42
+ // no layout, so the geometry is mocked on the prototype.
43
+ const many = Array.from({ length: 8 }, (_, i) => ({ value: i, label: `Tab ${i}` }))
44
+ const proto = HTMLElement.prototype
45
+ const saved = ['offsetLeft', 'offsetWidth', 'clientWidth', 'scrollWidth'].map(
46
+ (k) => [k, Object.getOwnPropertyDescriptor(proto, k)] as const,
47
+ )
48
+ const isTab = (el: HTMLElement) => el.tagName === 'BUTTON'
49
+ function mockLayout() {
50
+ Object.defineProperty(proto, 'offsetLeft', {
51
+ configurable: true,
52
+ get(this: HTMLElement) { return isTab(this) ? [...this.parentElement!.children].indexOf(this) * 120 : 0 },
53
+ })
54
+ Object.defineProperty(proto, 'offsetWidth', { configurable: true, get(this: HTMLElement) { return isTab(this) ? 120 : 390 } })
55
+ Object.defineProperty(proto, 'clientWidth', { configurable: true, get() { return 390 } })
56
+ Object.defineProperty(proto, 'scrollWidth', {
57
+ configurable: true,
58
+ get(this: HTMLElement) { return this.querySelector(':scope > button') ? this.querySelectorAll(':scope > button').length * 120 : 390 },
59
+ })
60
+ }
61
+ function spyScroll() {
62
+ const calls: ScrollToOptions[] = []
63
+ vi.spyOn(proto, 'scrollTo').mockImplementation(function (this: HTMLElement, opts?: ScrollToOptions | number) {
64
+ if (typeof opts === 'object') { calls.push(opts); this.scrollLeft = opts.left ?? 0 }
65
+ } as typeof proto.scrollTo)
66
+ return calls
67
+ }
68
+ function mockReducedMotion(reduce: boolean) {
69
+ vi.stubGlobal('matchMedia', (q: string) => ({ matches: reduce && q.includes('reduce'), media: q, addEventListener() {}, removeEventListener() {} }))
70
+ }
71
+
72
+ afterEach(() => {
73
+ for (const [k, d] of saved) {
74
+ if (d) Object.defineProperty(proto, k, d)
75
+ else delete (proto as unknown as Record<string, unknown>)[k]
76
+ }
77
+ vi.restoreAllMocks()
78
+ vi.unstubAllGlobals()
79
+ })
80
+
81
+ it('scrolls the row (not the page) to the active tab on mount, without animation', async () => {
82
+ mockLayout(); mockReducedMotion(false)
83
+ const calls = spyScroll()
84
+ const intoView = vi.fn()
85
+ vi.spyOn(proto, 'scrollIntoView').mockImplementation(intoView)
86
+ mount(MTabs, { props: { modelValue: 4, tabs: many, scrollable: true } })
87
+ await flushPromises()
88
+ // tab 4 spans 480–600: centered → 540 - 195 = 345
89
+ expect(calls).toEqual([{ left: 345, behavior: 'auto' }])
90
+ expect(intoView).not.toHaveBeenCalled()
91
+ })
92
+
93
+ it('smooth-scrolls to the new tab when modelValue changes, clamped to the row ends', async () => {
94
+ mockLayout(); mockReducedMotion(false)
95
+ const calls = spyScroll()
96
+ const w = mount(MTabs, { props: { modelValue: 0, tabs: many, scrollable: true } })
97
+ await flushPromises()
98
+ expect(calls).toEqual([]) // first tab already in view
99
+ await w.setProps({ modelValue: 7 })
100
+ await flushPromises()
101
+ expect(calls).toEqual([{ left: 960 - 390, behavior: 'smooth' }])
102
+ await w.setProps({ modelValue: 1 })
103
+ await flushPromises()
104
+ expect(calls[1]).toEqual({ left: 0, behavior: 'smooth' })
105
+ })
106
+
107
+ it('jumps instead of animating with prefers-reduced-motion', async () => {
108
+ mockLayout(); mockReducedMotion(true)
109
+ const calls = spyScroll()
110
+ const w = mount(MTabs, { props: { modelValue: 0, tabs: many, scrollable: true } })
111
+ await flushPromises()
112
+ await w.setProps({ modelValue: 5 })
113
+ await flushPromises()
114
+ expect(calls).toEqual([{ left: 465, behavior: 'auto' }])
115
+ })
116
+
117
+ it('does not pull the row back when an unchanged tabs array is passed again', async () => {
118
+ mockLayout(); mockReducedMotion(false)
119
+ const calls = spyScroll()
120
+ const w = mount(MTabs, { props: { modelValue: 4, tabs: many, scrollable: true } })
121
+ await flushPromises()
122
+ await w.setProps({ tabs: many.map((t) => ({ ...t })) })
123
+ await flushPromises()
124
+ expect(calls).toHaveLength(1)
125
+ })
126
+
127
+ it('never scrolls a fixed (non-scrollable) row', async () => {
128
+ mockLayout(); mockReducedMotion(false)
129
+ const calls = spyScroll()
130
+ const w = mount(MTabs, { props: { modelValue: 4, tabs: many } })
131
+ await flushPromises()
132
+ await w.setProps({ modelValue: 7 })
133
+ await flushPromises()
134
+ expect(calls).toEqual([])
135
+ })
136
+ })
39
137
  })
@@ -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
  })
@@ -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' },