@m3ui-vue/m3ui-vue 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist/API.md +75 -11
  2. package/dist/MMenuItem-BOkcVtEe.js +809 -0
  3. package/dist/MMenuItem-BOkcVtEe.js.map +1 -0
  4. package/dist/{MSlider-CdNIH7jc.js → MSlider-BXsBv0ox.js} +208 -182
  5. package/dist/MSlider-BXsBv0ox.js.map +1 -0
  6. package/dist/{MTextField-B4X92vH_.js → MTextField-rML9jnXs.js} +2 -2
  7. package/dist/{MTextField-B4X92vH_.js.map → MTextField-rML9jnXs.js.map} +1 -1
  8. package/dist/api.json +1 -1
  9. package/dist/code-editor.js +1 -1
  10. package/dist/components/MBottomSheet.vue.d.ts +20 -1
  11. package/dist/components/MDialog.vue.d.ts +17 -8
  12. package/dist/components/MDragDropList.vue.d.ts +1 -1
  13. package/dist/components/MMap.vue.d.ts +4 -4
  14. package/dist/components/MMapControl.vue.d.ts +20 -3
  15. package/dist/components/MMapMarker.vue.d.ts +5 -2
  16. package/dist/components/MMapPopup.vue.d.ts +5 -3
  17. package/dist/components/MMenuItem.vue.d.ts +2 -2
  18. package/dist/components/MSeekBar.vue.d.ts +122 -0
  19. package/dist/components/MSplitButton.vue.d.ts +2 -2
  20. package/dist/components/_MMapAttribution.vue.d.ts +7 -0
  21. package/dist/composables/_mapPin.d.ts +5 -0
  22. package/dist/composables/_popupPosition.d.ts +12 -0
  23. package/dist/composables/_useCalendarMonth.d.ts +24 -0
  24. package/dist/composables/_useEscapeStack.d.ts +3 -0
  25. package/dist/composables/_useScrollLock.d.ts +8 -0
  26. package/dist/composables/_useSheetMotion.d.ts +16 -1
  27. package/dist/composables/useLocale.d.ts +8 -0
  28. package/dist/index.d.ts +2 -0
  29. package/dist/locales/index.js +56 -0
  30. package/dist/locales/index.js.map +1 -1
  31. package/dist/m3ui-vue.css +1 -1
  32. package/dist/m3ui.js +5269 -4714
  33. package/dist/m3ui.js.map +1 -1
  34. package/dist/map.js +777 -641
  35. package/dist/map.js.map +1 -1
  36. package/dist/rich-text-editor.js +8 -8
  37. package/dist/styles.css +1 -1
  38. package/dist/{useLocale-b5-hzsL3.js → useLocale-CqQrhWFl.js} +9 -1
  39. package/dist/useLocale-CqQrhWFl.js.map +1 -0
  40. package/package.json +1 -1
  41. package/src/__tests__/MDialog.test.ts +30 -0
  42. package/src/__tests__/MMap.test.ts +132 -2
  43. package/src/__tests__/MSeekBar.test.ts +170 -0
  44. package/src/__tests__/MTooltip.test.ts +110 -0
  45. package/src/__tests__/_fakeMaplibre.ts +3 -0
  46. package/src/__tests__/calendarMonth.test.ts +59 -0
  47. package/src/__tests__/pickerModals.test.ts +128 -0
  48. package/src/__tests__/popupPosition.test.ts +224 -0
  49. package/src/__tests__/scrollLock.test.ts +110 -0
  50. package/src/__tests__/sheets.test.ts +158 -0
  51. package/src/components/MAutocomplete.vue +2 -4
  52. package/src/components/MBottomSheet.vue +211 -13
  53. package/src/components/MCommandPalette.vue +4 -6
  54. package/src/components/MContextMenu.vue +19 -5
  55. package/src/components/MDatePicker.vue +29 -70
  56. package/src/components/MDatePickerModal.vue +116 -172
  57. package/src/components/MDateRangePicker.vue +29 -51
  58. package/src/components/MDateRangePickerModal.vue +84 -162
  59. package/src/components/MDialog.vue +87 -63
  60. package/src/components/MLightbox.vue +6 -3
  61. package/src/components/MMap.vue +74 -28
  62. package/src/components/MMapControl.vue +121 -7
  63. package/src/components/MMapIdentify.vue +2 -1
  64. package/src/components/MMapMarker.vue +14 -7
  65. package/src/components/MMapPopup.vue +8 -4
  66. package/src/components/MMenu.vue +31 -12
  67. package/src/components/MMenuItem.vue +21 -4
  68. package/src/components/MMultiAutocomplete.vue +2 -4
  69. package/src/components/MMultiSelect.vue +2 -4
  70. package/src/components/MNavigationDrawer.vue +2 -8
  71. package/src/components/MNavigationRail.vue +2 -3
  72. package/src/components/MSearchBar.vue +2 -5
  73. package/src/components/MSeekBar.vue +593 -0
  74. package/src/components/MSelect.vue +2 -8
  75. package/src/components/MSplitButton.vue +23 -7
  76. package/src/components/MSpotlightSearch.vue +4 -6
  77. package/src/components/MTimePicker.vue +23 -6
  78. package/src/components/MTimePickerModal.vue +213 -226
  79. package/src/components/MTooltip.vue +99 -3
  80. package/src/components/_MMapAttribution.vue +81 -0
  81. package/src/composables/_mapPin.ts +25 -0
  82. package/src/composables/_popupPosition.ts +39 -0
  83. package/src/composables/_useCalendarMonth.ts +74 -0
  84. package/src/composables/_useEscapeStack.ts +33 -0
  85. package/src/composables/_useScrollLock.ts +41 -0
  86. package/src/composables/_useSheetMotion.ts +82 -20
  87. package/src/composables/useLocale.ts +16 -0
  88. package/src/index.ts +2 -0
  89. package/src/locales/de.ts +8 -0
  90. package/src/locales/es.ts +8 -0
  91. package/src/locales/fr.ts +8 -0
  92. package/src/locales/ja.ts +8 -0
  93. package/src/locales/ko.ts +8 -0
  94. package/src/locales/pt.ts +8 -0
  95. package/src/locales/zh.ts +8 -0
  96. package/dist/MMenuItem-DFyXflk9.js +0 -707
  97. package/dist/MMenuItem-DFyXflk9.js.map +0 -1
  98. package/dist/MSlider-CdNIH7jc.js.map +0 -1
  99. package/dist/useLocale-b5-hzsL3.js.map +0 -1
@@ -8,8 +8,10 @@
8
8
  */
9
9
  import { computed, ref, watch } from 'vue'
10
10
  import MButton from './MButton.vue'
11
+ import MDialog from './MDialog.vue'
11
12
  import MIconButton from './MIconButton.vue'
12
13
  import { useLocale } from '../composables/useLocale'
14
+ import { isoDate as fmt, useCalendarMonth } from '../composables/_useCalendarMonth'
13
15
 
14
16
  export interface DateRange {
15
17
  start: string | null
@@ -62,74 +64,19 @@ watch(() => props.show, (open) => {
62
64
  viewDate.value = props.modelValue?.start
63
65
  ? new Date(props.modelValue.start + 'T00:00:00')
64
66
  : new Date()
65
- document.addEventListener('keydown', onKeydown)
66
- document.body.style.overflow = 'hidden'
67
- } else {
68
- document.removeEventListener('keydown', onKeydown)
69
- document.body.style.overflow = ''
70
67
  }
71
68
  })
72
69
 
73
70
  // ── Calendar logic ─────────────────────────────────────────────────
74
- const WEEKDAYS = computed(() => {
75
- const f = new Intl.DateTimeFormat(resolvedLocale.value, { weekday: 'narrow' })
76
- return Array.from({ length: 7 }, (_, i) => f.format(new Date(2024, 0, i + 1)))
77
- })
78
-
79
- const monthLabel = computed(() =>
80
- new Intl.DateTimeFormat(resolvedLocale.value, { month: 'long', year: 'numeric' }).format(viewDate.value),
81
- )
82
-
83
- const calendarDays = computed(() => {
84
- const y = viewDate.value.getFullYear()
85
- const m = viewDate.value.getMonth()
86
- const first = new Date(y, m, 1)
87
- const startDay = (first.getDay() + 6) % 7
88
- const daysInMonth = new Date(y, m + 1, 0).getDate()
89
- const days: { date: number; current: boolean; iso: string; disabled: boolean }[] = []
90
-
91
- const prevDays = new Date(y, m, 0).getDate()
92
- for (let i = startDay - 1; i >= 0; i--) {
93
- const d = prevDays - i
94
- const iso = fmt(y, m - 1, d)
95
- days.push({ date: d, current: false, iso, disabled: isOOR(iso) })
96
- }
97
- for (let d = 1; d <= daysInMonth; d++) {
98
- const iso = fmt(y, m, d)
99
- days.push({ date: d, current: true, iso, disabled: isOOR(iso) })
100
- }
101
- const remaining = 42 - days.length
102
- for (let d = 1; d <= remaining; d++) {
103
- const iso = fmt(y, m + 1, d)
104
- days.push({ date: d, current: false, iso, disabled: isOOR(iso) })
105
- }
106
- return days
71
+ // Weekday names, the month's title and its six-week grid, shared with the other date pickers
72
+ const { weekdays: WEEKDAYS, monthLabel, days: calendarDays, isOutOfRange: isOOR, prevMonth, nextMonth } = useCalendarMonth(viewDate, {
73
+ locale: () => resolvedLocale.value,
74
+ min: () => props.min,
75
+ max: () => props.max,
107
76
  })
108
77
 
109
- function fmt(y: number, m: number, d: number) {
110
- const dt = new Date(y, m, d)
111
- return `${dt.getFullYear()}-${String(dt.getMonth() + 1).padStart(2, '0')}-${String(dt.getDate()).padStart(2, '0')}`
112
- }
113
-
114
- function isOOR(iso: string) {
115
- if (props.min && iso < props.min) return true
116
- if (props.max && iso > props.max) return true
117
- return false
118
- }
119
-
120
78
  const todayIso = fmt(new Date().getFullYear(), new Date().getMonth(), new Date().getDate())
121
79
 
122
- function prevMonth() {
123
- const d = new Date(viewDate.value)
124
- d.setMonth(d.getMonth() - 1)
125
- viewDate.value = d
126
- }
127
- function nextMonth() {
128
- const d = new Date(viewDate.value)
129
- d.setMonth(d.getMonth() + 1)
130
- viewDate.value = d
131
- }
132
-
133
80
  function selectDay(day: typeof calendarDays.value[0]) {
134
81
  if (day.disabled) return
135
82
  if (picking.value === 'start') {
@@ -172,114 +119,89 @@ function confirm() {
172
119
  }
173
120
  }
174
121
 
175
- function onKeydown(e: KeyboardEvent) { if (e.key === 'Escape') cancel() }
122
+ // Escape or the scrim (MDialog) cancel, like the Cancel button
123
+ function onDialog(open: boolean) {
124
+ if (!open) cancel()
125
+ }
176
126
  </script>
177
127
 
178
128
  <template>
179
- <Teleport to="body">
180
- <Transition name="m3-drp-modal" appear>
181
- <div
182
- v-if="show"
183
- class="fixed inset-0 z-50 flex items-center justify-center bg-scrim/32 p-4"
184
- @click.self="cancel"
185
- >
186
- <div class="drp-box w-[360px] rounded-[28px] bg-surface-container-high shadow-elevation-3">
187
- <!-- Header -->
188
- <div class="px-6 pt-6 pb-4">
189
- <p class="mb-3 text-label-large text-on-surface-variant">
190
- {{ title || locale.selectRange }}
191
- </p>
192
- <div class="flex items-center gap-3">
193
- <div
194
- class="flex-1 rounded-lg px-3 py-2 text-center transition-colors"
195
- :class="picking === 'start' ? 'bg-primary-container text-on-primary-container' : 'bg-surface-container-highest text-on-surface'"
196
- @click="picking = 'start'"
197
- >
198
- <p class="text-label-small text-on-surface-variant">{{ locale.pickStart }}</p>
199
- <p class="text-title-medium font-medium capitalize">{{ fmtDisplay(start) }}</p>
200
- </div>
201
- <span class="text-on-surface-variant">→</span>
202
- <div
203
- class="flex-1 rounded-lg px-3 py-2 text-center transition-colors"
204
- :class="picking === 'end' ? 'bg-primary-container text-on-primary-container' : 'bg-surface-container-highest text-on-surface'"
205
- @click="start && (picking = 'end')"
206
- >
207
- <p class="text-label-small text-on-surface-variant">{{ locale.pickEnd }}</p>
208
- <p class="text-title-medium font-medium capitalize">{{ fmtDisplay(end) }}</p>
209
- </div>
210
- </div>
211
- </div>
212
-
213
- <div class="h-px bg-outline-variant" />
129
+ <!-- MDialog's bare box: scrim, Escape, scroll lock, the open/close animation and dialog semantics -->
130
+ <MDialog :model-value="show" bare max-width="360px" :title="title || locale.selectRange" @update:model-value="onDialog">
131
+ <!-- Header -->
132
+ <div class="px-6 pt-6 pb-4">
133
+ <p class="mb-3 text-label-large text-on-surface-variant">
134
+ {{ title || locale.selectRange }}
135
+ </p>
136
+ <div class="flex items-center gap-3">
137
+ <div
138
+ class="flex-1 rounded-lg px-3 py-2 text-center transition-colors"
139
+ :class="picking === 'start' ? 'bg-primary-container text-on-primary-container' : 'bg-surface-container-highest text-on-surface'"
140
+ @click="picking = 'start'"
141
+ >
142
+ <p class="text-label-small text-on-surface-variant">{{ locale.pickStart }}</p>
143
+ <p class="text-title-medium font-medium capitalize">{{ fmtDisplay(start) }}</p>
144
+ </div>
145
+ <span class="text-on-surface-variant">→</span>
146
+ <div
147
+ class="flex-1 rounded-lg px-3 py-2 text-center transition-colors"
148
+ :class="picking === 'end' ? 'bg-primary-container text-on-primary-container' : 'bg-surface-container-highest text-on-surface'"
149
+ @click="start && (picking = 'end')"
150
+ >
151
+ <p class="text-label-small text-on-surface-variant">{{ locale.pickEnd }}</p>
152
+ <p class="text-title-medium font-medium capitalize">{{ fmtDisplay(end) }}</p>
153
+ </div>
154
+ </div>
155
+ </div>
214
156
 
215
- <!-- Calendar -->
216
- <div class="px-4 pt-3 pb-2">
217
- <div class="mb-2 flex items-center justify-between">
218
- <MIconButton icon="chevron_left" :label="locale.previousMonth" :size="36" @click="prevMonth" />
219
- <span class="text-title-small font-medium capitalize text-on-surface">{{ monthLabel }}</span>
220
- <MIconButton icon="chevron_right" :label="locale.nextMonth" :size="36" @click="nextMonth" />
221
- </div>
157
+ <div class="h-px bg-outline-variant" />
222
158
 
223
- <div class="mb-1 grid grid-cols-7 gap-0.5 text-center">
224
- <span v-for="wd in WEEKDAYS" :key="wd" class="py-1 text-body-large font-medium text-on-surface">
225
- {{ wd }}
226
- </span>
227
- </div>
159
+ <!-- Calendar -->
160
+ <div class="px-4 pt-3 pb-2">
161
+ <div class="mb-2 flex items-center justify-between">
162
+ <MIconButton icon="chevron_left" :label="locale.previousMonth" :size="36" @click="prevMonth" />
163
+ <span class="text-title-small font-medium capitalize text-on-surface">{{ monthLabel }}</span>
164
+ <MIconButton icon="chevron_right" :label="locale.nextMonth" :size="36" @click="nextMonth" />
165
+ </div>
228
166
 
229
- <div class="grid grid-cols-7 gap-0.5">
230
- <button
231
- v-for="(day, i) in calendarDays"
232
- :key="i"
233
- type="button"
234
- class="flex h-10 w-full items-center justify-center text-body-medium transition-colors duration-100"
235
- :class="[
236
- day.disabled
237
- ? 'cursor-not-allowed text-on-surface/25 rounded-full'
238
- : day.iso === start || day.iso === end
239
- ? 'bg-primary text-on-primary rounded-full'
240
- : isInRange(day.iso)
241
- ? 'bg-primary/12 text-on-surface cursor-pointer'
242
- : day.iso === todayIso
243
- ? 'border border-primary text-primary rounded-full cursor-pointer hover:bg-primary/8'
244
- : day.current
245
- ? 'cursor-pointer text-on-surface rounded-full hover:bg-on-surface/8'
246
- : 'cursor-pointer text-on-surface-variant/50 rounded-full hover:bg-on-surface/4',
247
- ]"
248
- :disabled="day.disabled"
249
- @mouseenter="picking === 'end' && (hovered = day.iso)"
250
- @click="selectDay(day)"
251
- >
252
- {{ day.date }}
253
- </button>
254
- </div>
255
- </div>
167
+ <div class="mb-1 grid grid-cols-7 gap-0.5 text-center">
168
+ <span v-for="wd in WEEKDAYS" :key="wd" class="py-1 text-body-large font-medium text-on-surface">
169
+ {{ wd }}
170
+ </span>
171
+ </div>
256
172
 
257
- <!-- Footer -->
258
- <div class="flex justify-end gap-2 px-6 py-4">
259
- <MButton variant="text" @click="cancel">{{ locale.cancel }}</MButton>
260
- <MButton variant="text" :disabled="!start || !end" @click="confirm">OK</MButton>
261
- </div>
262
- </div>
173
+ <div class="grid grid-cols-7 gap-0.5">
174
+ <button
175
+ v-for="(day, i) in calendarDays"
176
+ :key="i"
177
+ type="button"
178
+ class="flex h-10 w-full items-center justify-center text-body-medium transition-colors duration-100"
179
+ :class="[
180
+ day.disabled
181
+ ? 'cursor-not-allowed text-on-surface/25 rounded-full'
182
+ : day.iso === start || day.iso === end
183
+ ? 'bg-primary text-on-primary rounded-full'
184
+ : isInRange(day.iso)
185
+ ? 'bg-primary/12 text-on-surface cursor-pointer'
186
+ : day.iso === todayIso
187
+ ? 'border border-primary text-primary rounded-full cursor-pointer hover:bg-primary/8'
188
+ : day.current
189
+ ? 'cursor-pointer text-on-surface rounded-full hover:bg-on-surface/8'
190
+ : 'cursor-pointer text-on-surface-variant/50 rounded-full hover:bg-on-surface/4',
191
+ ]"
192
+ :disabled="day.disabled"
193
+ @mouseenter="picking === 'end' && (hovered = day.iso)"
194
+ @click="selectDay(day)"
195
+ >
196
+ {{ day.date }}
197
+ </button>
263
198
  </div>
264
- </Transition>
265
- </Teleport>
199
+ </div>
200
+
201
+ <!-- Footer -->
202
+ <div class="flex justify-end gap-2 px-6 py-4">
203
+ <MButton variant="text" @click="cancel">{{ locale.cancel }}</MButton>
204
+ <MButton variant="text" :disabled="!start || !end" @click="confirm">{{ locale.ok }}</MButton>
205
+ </div>
206
+ </MDialog>
266
207
  </template>
267
-
268
- <style scoped>
269
- .m3-drp-modal-enter-active,
270
- .m3-drp-modal-leave-active {
271
- transition: opacity 0.15s ease;
272
- }
273
- .m3-drp-modal-enter-from,
274
- .m3-drp-modal-leave-to {
275
- opacity: 0;
276
- }
277
- .m3-drp-modal-enter-active .drp-box,
278
- .m3-drp-modal-leave-active .drp-box {
279
- transition: transform 0.15s ease;
280
- }
281
- .m3-drp-modal-enter-from .drp-box,
282
- .m3-drp-modal-leave-to .drp-box {
283
- transform: scale(0.95);
284
- }
285
- </style>
@@ -6,13 +6,16 @@
6
6
  * @slot icon M3 AlertDialog's optional icon (Secondary color, 24dp expected). Its presence also centers the
7
7
  * title, per spec.
8
8
  * @slot title Overrides the title prop with custom markup
9
- * @slot default Dialog body content — scrolls independently when taller than maxHeight
9
+ * @slot default Dialog body content — scrolls independently when taller than maxHeight. With `bare`, the whole
10
+ * dialog: it fills the box (no title, padding, close button or actions row)
10
11
  * @slot actions Row of action buttons — wraps to a new line instead of overflowing when labels are long
11
12
  * @event update:modelValue Emitted when the dialog should open/close — powers v-model
12
13
  */
13
- import { computed, nextTick, onUnmounted, ref, watch } from 'vue'
14
+ import { computed, nextTick, onUnmounted, ref, useId, watch } from 'vue'
14
15
  import MIconButton from './MIconButton.vue'
15
16
  import { useLocale } from '../composables/useLocale'
17
+ import { useScrollLock } from '../composables/_useScrollLock'
18
+ import { useEscapeStack } from '../composables/_useEscapeStack'
16
19
 
17
20
  const props = withDefaults(
18
21
  defineProps<{
@@ -45,6 +48,12 @@ const props = withDefaults(
45
48
  // deliberate library extension on top of the spec, kept opt-out (default `true`, matching
46
49
  // this component's existing behavior) rather than added unconditionally.
47
50
  closable?: boolean
51
+ /**
52
+ * Just the dialog's box (surface, shape, elevation), scrim, Escape, scroll lock and animation, with the default
53
+ * slot filling it: no title row, padding, close button or actions. For dialogs that draw everything themselves
54
+ * (the date and time pickers). `title` then only names it for assistive technology
55
+ */
56
+ bare?: boolean
48
57
  }>(),
49
58
  {
50
59
  // AlertDialogDefaults.DialogMaxWidth = 560dp
@@ -53,6 +62,7 @@ const props = withDefaults(
53
62
  persistent: false,
54
63
  fullscreen: false,
55
64
  closable: true,
65
+ bare: false,
56
66
  },
57
67
  )
58
68
 
@@ -74,9 +84,6 @@ function close() {
74
84
  emit('update:modelValue', false)
75
85
  }
76
86
 
77
- function onKeydown(event: KeyboardEvent) {
78
- if (event.key === 'Escape') close()
79
- }
80
87
 
81
88
  // M3's dialog anatomy lists an optional divider between the (scrollable) content and the
82
89
  // actions row — Compose's own AlertDialog.kt has no built-in implementation of it at all, so
@@ -92,12 +99,16 @@ function updateDividerVisibility() {
92
99
  showDivider.value = el.scrollHeight - el.scrollTop - el.clientHeight > 1
93
100
  }
94
101
 
102
+ useScrollLock(() => props.modelValue)
103
+ // Escape closes the dialog on top only, when several are stacked
104
+ useEscapeStack(() => props.modelValue, close)
105
+
106
+ const titleId = `m3-dialog-${useId()}`
107
+
95
108
  watch(
96
109
  () => props.modelValue,
97
110
  async (open) => {
98
111
  if (open) {
99
- document.addEventListener('keydown', onKeydown)
100
- document.body.style.overflow = 'hidden'
101
112
  await nextTick()
102
113
  updateDividerVisibility()
103
114
  // Observing contentEl alone only catches viewport-driven resizes (e.g. window resize
@@ -109,16 +120,14 @@ watch(
109
120
  if (contentEl.value) resizeObserver.observe(contentEl.value)
110
121
  if (contentInnerEl.value) resizeObserver.observe(contentInnerEl.value)
111
122
  } else {
112
- document.removeEventListener('keydown', onKeydown)
113
- document.body.style.overflow = ''
114
123
  resizeObserver?.disconnect()
115
124
  resizeObserver = undefined
116
125
  }
117
126
  },
127
+ { immediate: true },
118
128
  )
119
129
 
120
130
  onUnmounted(() => {
121
- document.removeEventListener('keydown', onKeydown)
122
131
  resizeObserver?.disconnect()
123
132
  })
124
133
  </script>
@@ -137,64 +146,76 @@ onUnmounted(() => {
137
146
  class="dialog-box flex min-w-[280px] w-full flex-col rounded-xl bg-surface-container-high shadow-elevation-3"
138
147
  :class="sizeClasses"
139
148
  :style="sizeStyle"
149
+ role="dialog"
150
+ aria-modal="true"
151
+ :aria-labelledby="!bare && ($slots.title || title) ? titleId : undefined"
152
+ :aria-label="bare ? title : undefined"
140
153
  >
141
- <!--
142
- AlertDialogDefaults.dialogPadding is 24dp on all four sides of the whole content
143
- column, with per-element bottom paddings (IconPadding/TitlePadding/textPadding)
144
- providing the gaps BETWEEN elements — not a single wrapping padding, since this
145
- template uses separate divs per section instead of one padded Column. Each
146
- section's own top/bottom classes are chosen so the combined gaps still land on
147
- the right dp value: title-to-body is 16dp (8px here + 8px there), body-to-actions
148
- is 24dp (8px here + 16px there), and the outermost edges (top of title, bottom of
149
- whichever section is last) are the full 24dp on their own.
150
- -->
151
- <div class="relative px-6 pt-6 pb-2">
152
- <!--
153
- Wrapped in a plain div rather than passing `absolute right-4 top-4` straight to
154
- MIconButton: its root already carries its own `relative` (for the ripple span),
155
- and Tailwind resolves conflicting position utilities by source order in the
156
- compiled CSS, not by order in the class attribute — so an external `absolute`
157
- can silently lose to that internal `relative` instead of overriding it.
158
- -->
159
- <div v-if="closable && !persistent" class="absolute right-4 top-4">
160
- <MIconButton icon="close" :label="closeLabel ?? locale.close" @click="close" />
161
- </div>
154
+ <!-- Bare: the content is the whole dialog (scrolling if taller than maxHeight), clipped to the box's
155
+ corners (rounded-[inherit]) so content reaching its edges, like a full-bleed image, keeps them -->
156
+ <div v-if="bare" class="min-h-0 overflow-y-auto rounded-[inherit]">
157
+ <slot />
158
+ </div>
159
+ <template v-else>
162
160
  <!--
163
- Icon slot: M3 AlertDialog's optional `icon` param (IconColor=Secondary,
164
- IconSize=24dp expected from the slot content, IconPadding bottom=16dp below it),
165
- which per spec also centers the title ("Align the title to the center when an
166
- icon is present") — reserving `pr-10` on the title only when the close button is
167
- also showing, so a centered title doesn't collide with it.
161
+ AlertDialogDefaults.dialogPadding is 24dp on all four sides of the whole content
162
+ column, with per-element bottom paddings (IconPadding/TitlePadding/textPadding)
163
+ providing the gaps BETWEEN elements — not a single wrapping padding, since this
164
+ template uses separate divs per section instead of one padded Column. Each
165
+ section's own top/bottom classes are chosen so the combined gaps still land on
166
+ the right dp value: title-to-body is 16dp (8px here + 8px there), body-to-actions
167
+ is 24dp (8px here + 16px there), and the outermost edges (top of title, bottom of
168
+ whichever section is last) are the full 24dp on their own.
168
169
  -->
169
- <div v-if="$slots.icon" class="mb-4 flex justify-center text-secondary">
170
- <slot name="icon" />
170
+ <div class="relative px-6 pt-6 pb-2">
171
+ <!--
172
+ Wrapped in a plain div rather than passing `absolute right-4 top-4` straight to
173
+ MIconButton: its root already carries its own `relative` (for the ripple span),
174
+ and Tailwind resolves conflicting position utilities by source order in the
175
+ compiled CSS, not by order in the class attribute — so an external `absolute`
176
+ can silently lose to that internal `relative` instead of overriding it.
177
+ -->
178
+ <div v-if="closable && !persistent" class="absolute right-4 top-4">
179
+ <MIconButton icon="close" :label="closeLabel ?? locale.close" @click="close" />
180
+ </div>
181
+ <!--
182
+ Icon slot: M3 AlertDialog's optional `icon` param (IconColor=Secondary,
183
+ IconSize=24dp expected from the slot content, IconPadding bottom=16dp below it),
184
+ which per spec also centers the title ("Align the title to the center when an
185
+ icon is present") — reserving `pr-10` on the title only when the close button is
186
+ also showing, so a centered title doesn't collide with it.
187
+ -->
188
+ <div v-if="$slots.icon" class="mb-4 flex justify-center text-secondary">
189
+ <slot name="icon" />
190
+ </div>
191
+ <h2
192
+ :id="titleId"
193
+ class="text-headline-small text-on-surface"
194
+ :class="[
195
+ $slots.icon ? 'text-center' : 'text-left',
196
+ closable && !persistent ? ($slots.icon ? 'px-10' : 'pr-10') : '',
197
+ ]"
198
+ >
199
+ <slot name="title">{{ title }}</slot>
200
+ </h2>
171
201
  </div>
172
- <h2
173
- class="text-headline-small text-on-surface"
174
- :class="[
175
- $slots.icon ? 'text-center' : 'text-left',
176
- closable && !persistent ? ($slots.icon ? 'px-10' : 'pr-10') : '',
177
- ]"
202
+ <div
203
+ ref="contentEl"
204
+ class="overflow-y-auto px-6 pt-2 text-body-medium text-on-surface-variant"
205
+ :class="$slots.actions ? 'pb-2' : 'pb-6'"
206
+ @scroll="updateDividerVisibility"
178
207
  >
179
- <slot name="title">{{ title }}</slot>
180
- </h2>
181
- </div>
182
- <div
183
- ref="contentEl"
184
- class="overflow-y-auto px-6 pt-2 text-body-medium text-on-surface-variant"
185
- :class="$slots.actions ? 'pb-2' : 'pb-6'"
186
- @scroll="updateDividerVisibility"
187
- >
188
- <div ref="contentInnerEl">
189
- <slot />
208
+ <div ref="contentInnerEl">
209
+ <slot />
210
+ </div>
190
211
  </div>
191
- </div>
192
- <!-- Divider: M3 dialog anatomy's optional divider, shown only while the content has more to scroll to -->
193
- <div v-if="showDivider && $slots.actions" class="shrink-0 border-t border-outline-variant" />
194
- <!-- flex-wrap approximates AlertDialogFlowRow: buttons wrap to a new line instead of overflowing when labels are too long to fit on one -->
195
- <div v-if="$slots.actions" class="flex flex-wrap justify-end gap-2 px-6 pt-4 pb-6">
196
- <slot name="actions" />
197
- </div>
212
+ <!-- Divider: M3 dialog anatomy's optional divider, shown only while the content has more to scroll to -->
213
+ <div v-if="showDivider && $slots.actions" class="shrink-0 border-t border-outline-variant" />
214
+ <!-- flex-wrap approximates AlertDialogFlowRow: buttons wrap to a new line instead of overflowing when labels are too long to fit on one -->
215
+ <div v-if="$slots.actions" class="flex flex-wrap justify-end gap-2 px-6 pt-4 pb-6">
216
+ <slot name="actions" />
217
+ </div>
218
+ </template>
198
219
  </div>
199
220
  </div>
200
221
  </Transition>
@@ -204,10 +225,13 @@ onUnmounted(() => {
204
225
  <div
205
226
  v-if="modelValue"
206
227
  class="dialog-fs fixed inset-0 z-50 flex flex-col bg-surface"
228
+ role="dialog"
229
+ aria-modal="true"
230
+ :aria-labelledby="$slots.title || title ? titleId : undefined"
207
231
  >
208
232
  <div class="flex h-14 shrink-0 items-center gap-2 px-2">
209
233
  <MIconButton v-if="!persistent" icon="close" :label="closeLabel ?? locale.close" @click="close" />
210
- <h2 class="flex-1 text-title-large font-medium text-on-surface">
234
+ <h2 :id="titleId" class="flex-1 text-title-large font-medium text-on-surface">
211
235
  <slot name="title">{{ title }}</slot>
212
236
  </h2>
213
237
  <div v-if="$slots.actions" class="flex items-center gap-2">
@@ -31,6 +31,7 @@ import { isHydrating } from '../composables/_hydration'
31
31
  import MIconButton from './MIconButton.vue'
32
32
  import MSpinner from './MSpinner.vue'
33
33
  import { useLocale } from '../composables/useLocale'
34
+ import { useScrollLock } from '../composables/_useScrollLock'
34
35
 
35
36
  export interface LightboxItem {
36
37
  src: string
@@ -285,6 +286,9 @@ function originTransform(): Origin | null {
285
286
  }
286
287
  }
287
288
 
289
+ // The page doesn't scroll from when it opens until its close animation ends
290
+ const scrollLock = useScrollLock()
291
+
288
292
  async function show() {
289
293
  restoreFocus = document.activeElement as HTMLElement | null
290
294
  rendered.value = true
@@ -296,7 +300,7 @@ async function show() {
296
300
  setNow(backdrop, 0)
297
301
  backdrop.k = 300
298
302
  document.addEventListener('keydown', onKeydown)
299
- document.body.style.overflow = 'hidden'
303
+ scrollLock.set(true)
300
304
  await nextTick()
301
305
  measure()
302
306
  backdrop.target = 1
@@ -330,7 +334,7 @@ function hide() {
330
334
  }
331
335
  onSettled = () => {
332
336
  rendered.value = false
333
- document.body.style.overflow = ''
337
+ scrollLock.set(false)
334
338
  restoreFocus?.focus?.()
335
339
  restoreFocus = null
336
340
  }
@@ -788,7 +792,6 @@ onBeforeUnmount(() => {
788
792
  if (raf) cancelAnimationFrame(raf)
789
793
  if (tapTimer) clearTimeout(tapTimer)
790
794
  document.removeEventListener('keydown', onKeydown)
791
- if (rendered.value) document.body.style.overflow = ''
792
795
  })
793
796
 
794
797
  defineExpose({ open, close, next, prev })