@mozaic-ds/vue 2.17.0 → 2.19.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.
- package/dist/mozaic-vue.css +1 -1
- package/dist/mozaic-vue.d.ts +158 -72
- package/dist/mozaic-vue.js +1728 -4748
- package/dist/mozaic-vue.js.map +1 -1
- package/dist/mozaic-vue.umd.cjs +6 -25
- package/dist/mozaic-vue.umd.cjs.map +1 -1
- package/package.json +16 -10
- package/src/components/BrandPresets.mdx +20 -2
- package/src/components/Migration.mdx +651 -0
- package/src/components/accordionlistitem/MAccordionListItem.spec.ts +22 -3
- package/src/components/accordionlistitem/MAccordionListItem.vue +38 -28
- package/src/components/actionlistbox/MActionListbox.spec.ts +99 -0
- package/src/components/actionlistbox/MActionListbox.vue +54 -7
- package/src/components/breadcrumb/MBreadcrumb.vue +1 -1
- package/src/components/builtinmenu/MBuiltInMenu.spec.ts +30 -1
- package/src/components/builtinmenu/MBuiltInMenu.vue +26 -17
- package/src/components/builtinmenu/README.md +2 -0
- package/src/components/button/MButton.spec.ts +26 -0
- package/src/components/button/MButton.vue +2 -0
- package/src/components/callout/MCallout.spec.ts +35 -0
- package/src/components/callout/MCallout.stories.ts +0 -3
- package/src/components/callout/MCallout.vue +26 -7
- package/src/components/callout/README.md +4 -2
- package/src/components/carousel/MCarousel.spec.ts +26 -2
- package/src/components/carousel/MCarousel.vue +10 -4
- package/src/components/checklistmenu/MCheckListMenu.spec.ts +12 -1
- package/src/components/checklistmenu/MCheckListMenu.vue +6 -0
- package/src/components/checklistmenu/README.md +2 -0
- package/src/components/combobox/MCombobox.vue +7 -0
- package/src/components/datatable/datatable.mdx +3 -2
- package/src/components/drawer/MDrawer.spec.ts +102 -3
- package/src/components/drawer/MDrawer.vue +73 -14
- package/src/components/field/MField.vue +1 -0
- package/src/components/fileuploader/MFileUploader.vue +2 -2
- package/src/components/fileuploaderitem/MFileUploaderItem.vue +2 -7
- package/src/components/iconbutton/MIconButton.spec.ts +15 -0
- package/src/components/iconbutton/MIconButton.vue +1 -0
- package/src/components/kpiitem/MKpiItem.spec.ts +13 -0
- package/src/components/kpiitem/MKpiItem.vue +1 -1
- package/src/components/modal/MModal.spec.ts +115 -3
- package/src/components/modal/MModal.vue +91 -11
- package/src/components/modal/README.md +1 -1
- package/src/components/navigationindicator/MNavigationIndicator.spec.ts +75 -18
- package/src/components/navigationindicator/MNavigationIndicator.vue +10 -12
- package/src/components/optionListbox/MOptionListbox.vue +16 -1
- package/src/components/overlay/MOverlay.spec.ts +1 -1
- package/src/components/overlay/MOverlay.vue +1 -1
- package/src/components/phonenumber/MPhoneNumber.spec.ts +6 -2
- package/src/components/phonenumber/MPhoneNumber.vue +20 -16
- package/src/components/popover/MPopover.spec.ts +126 -0
- package/src/components/popover/MPopover.vue +36 -1
- package/src/components/segmentedcontrol/MSegmentedControl.spec.ts +92 -0
- package/src/components/segmentedcontrol/MSegmentedControl.vue +61 -2
- package/src/components/sidebarexpandableitem/MSidebarExpandableItem.spec.ts +12 -0
- package/src/components/sidebarexpandableitem/MSidebarExpandableItem.vue +1 -0
- package/src/components/starrating/MStarRating.spec.ts +19 -22
- package/src/components/starrating/MStarRating.vue +3 -2
- package/src/components/steppercompact/MStepperCompact.spec.ts +9 -0
- package/src/components/steppercompact/MStepperCompact.vue +1 -1
- package/src/components/stepperinline/MStepperInline.spec.ts +11 -0
- package/src/components/stepperinline/MStepperInline.vue +1 -1
- package/src/components/stepperstacked/MStepperStacked.spec.ts +13 -0
- package/src/components/stepperstacked/MStepperStacked.vue +1 -0
- package/src/components/tabs/MTabs.vue +90 -4
- package/src/components/tabs/Mtabs.spec.ts +162 -0
- package/src/components/textinput/MTextInput.vue +2 -2
- package/src/components/toggle/MToggle.vue +1 -1
- package/src/main.ts +1 -0
- package/src/components/ComponentsMapping.mdx +0 -98
|
@@ -82,15 +82,34 @@ describe('MAccordionListItem', () => {
|
|
|
82
82
|
expect(button.attributes('aria-expanded')).toBe('true');
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
it('sets
|
|
85
|
+
it('sets inert correctly for content', async () => {
|
|
86
86
|
const { wrapper, state } = mountItem({ id: 'item-1', title: 'Title' }, []);
|
|
87
87
|
|
|
88
88
|
const content = wrapper.find('.mc-accordion__content');
|
|
89
|
-
expect(content.attributes('
|
|
89
|
+
expect(content.attributes('inert')).not.toBeUndefined();
|
|
90
90
|
|
|
91
91
|
state.value.push('item-1');
|
|
92
92
|
await wrapper.vm.$nextTick();
|
|
93
|
-
expect(content.attributes('
|
|
93
|
+
expect(content.attributes('inert')).toBeUndefined();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('renders heading with default level h2', () => {
|
|
97
|
+
const { wrapper } = mountItem({ id: '1', title: 'Title' });
|
|
98
|
+
expect(wrapper.find('h2.mc-accordion__title').exists()).toBe(true);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('renders heading with custom headingLevel prop', () => {
|
|
102
|
+
const wrapper = mount(MAccordionListItem, {
|
|
103
|
+
props: { id: '1', title: 'Title', tag: 'h3' },
|
|
104
|
+
global: {
|
|
105
|
+
provide: {
|
|
106
|
+
[AccordionStateKey as symbol]: ref([]),
|
|
107
|
+
[AccordionToggleFnKey as symbol]: vi.fn(),
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
expect(wrapper.find('h3.mc-accordion__title').exists()).toBe(true);
|
|
112
|
+
expect(wrapper.find('h2').exists()).toBe(false);
|
|
94
113
|
});
|
|
95
114
|
|
|
96
115
|
it('calls toggleItem when button is clicked', async () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="mc-accordion__item">
|
|
3
3
|
<div class="mc-accordion__header">
|
|
4
|
-
<
|
|
4
|
+
<component :is="tag" class="mc-accordion__title">
|
|
5
5
|
<button
|
|
6
6
|
:id="`accordion-${id}`"
|
|
7
7
|
class="mc-accordion__trigger"
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
</span>
|
|
20
20
|
</div>
|
|
21
21
|
</button>
|
|
22
|
-
</
|
|
22
|
+
</component>
|
|
23
23
|
</div>
|
|
24
24
|
<div
|
|
25
25
|
:id="`content-${id}`"
|
|
26
26
|
class="mc-accordion__content"
|
|
27
|
-
:
|
|
27
|
+
:inert="!open || undefined"
|
|
28
28
|
:aria-labelledby="`accordion-${id}`"
|
|
29
29
|
role="region"
|
|
30
30
|
>
|
|
@@ -49,31 +49,41 @@ import {
|
|
|
49
49
|
AccordionToggleFnKey,
|
|
50
50
|
} from '../accordionlist/m-accordion-list.const';
|
|
51
51
|
|
|
52
|
-
const props =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
52
|
+
const props = withDefaults(
|
|
53
|
+
defineProps<{
|
|
54
|
+
/**
|
|
55
|
+
* A unique identifier for the accordion item.
|
|
56
|
+
* It links the trigger button (`aria-controls`) to its associated content (`aria-labelledby`),
|
|
57
|
+
* ensuring accessibility and tracking the open/closed state.
|
|
58
|
+
* If no ID is provided, a unique one is generated automatically.
|
|
59
|
+
*/
|
|
60
|
+
id: string;
|
|
61
|
+
/**
|
|
62
|
+
* The main heading of the accordion item. This is the primary text visible to users in the collapsed state and acts as the trigger for expanding or collapsing the content.
|
|
63
|
+
*/
|
|
64
|
+
title: string;
|
|
65
|
+
/**
|
|
66
|
+
* An optional secondary heading displayed below the title. It provides additional context or detail about the content of the accordion item.
|
|
67
|
+
*/
|
|
68
|
+
subtitle?: string;
|
|
69
|
+
/**
|
|
70
|
+
* The main content of the accordion item. This is the information revealed when the accordion is expanded, typically containing text, HTML, or other elements.
|
|
71
|
+
*/
|
|
72
|
+
content?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Icon component to display before the item title.
|
|
75
|
+
*/
|
|
76
|
+
icon?: Component;
|
|
77
|
+
/**
|
|
78
|
+
* Heading level for the accordion trigger (h2–h6). Adjust to match the
|
|
79
|
+
* heading hierarchy of the page where the accordion is used.
|
|
80
|
+
*/
|
|
81
|
+
tag?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
82
|
+
}>(),
|
|
83
|
+
{
|
|
84
|
+
tag: 'h2',
|
|
85
|
+
},
|
|
86
|
+
);
|
|
77
87
|
|
|
78
88
|
defineSlots<{
|
|
79
89
|
/**
|
|
@@ -135,4 +135,103 @@ describe('MActionListbox', () => {
|
|
|
135
135
|
await actions[1].trigger('click');
|
|
136
136
|
expect(wrapper.emitted('action')?.[1][0]).toBe('move');
|
|
137
137
|
});
|
|
138
|
+
|
|
139
|
+
it('has role="menu" on the list and role="menuitem" on each button', () => {
|
|
140
|
+
const wrapper = mountComponent();
|
|
141
|
+
expect(wrapper.find('ul.mc-action-list').attributes('role')).toBe('menu');
|
|
142
|
+
const menuItems = wrapper.findAll('button[role="menuitem"]');
|
|
143
|
+
expect(menuItems.length).toBe(items.length);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe('keyboard navigation', () => {
|
|
147
|
+
function mountAttached(props = {}) {
|
|
148
|
+
const div = document.createElement('div');
|
|
149
|
+
document.body.appendChild(div);
|
|
150
|
+
const wrapper = mount(MActionListbox, {
|
|
151
|
+
props: { items, ...props },
|
|
152
|
+
attachTo: div,
|
|
153
|
+
global: { components: { MDivider, MIconButton, Cross24 } },
|
|
154
|
+
});
|
|
155
|
+
return wrapper;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
it('ArrowDown moves focus to the next item', async () => {
|
|
159
|
+
const wrapper = mountAttached();
|
|
160
|
+
const buttons = wrapper.findAll('button[role="menuitem"]');
|
|
161
|
+
await buttons[0].element.focus();
|
|
162
|
+
await wrapper.find('ul[role="menu"]').trigger('keydown', { key: 'ArrowDown' });
|
|
163
|
+
expect(document.activeElement).toBe(buttons[1].element);
|
|
164
|
+
wrapper.unmount();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('ArrowDown wraps from last to first item', async () => {
|
|
168
|
+
const wrapper = mountAttached();
|
|
169
|
+
const buttons = wrapper.findAll('button[role="menuitem"]');
|
|
170
|
+
await buttons[buttons.length - 1].element.focus();
|
|
171
|
+
await wrapper.find('ul[role="menu"]').trigger('keydown', { key: 'ArrowDown' });
|
|
172
|
+
expect(document.activeElement).toBe(buttons[0].element);
|
|
173
|
+
wrapper.unmount();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('ArrowUp moves focus to the previous item', async () => {
|
|
177
|
+
const wrapper = mountAttached();
|
|
178
|
+
const buttons = wrapper.findAll('button[role="menuitem"]');
|
|
179
|
+
await buttons[1].element.focus();
|
|
180
|
+
await wrapper.find('ul[role="menu"]').trigger('keydown', { key: 'ArrowUp' });
|
|
181
|
+
expect(document.activeElement).toBe(buttons[0].element);
|
|
182
|
+
wrapper.unmount();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('ArrowUp wraps from first to last item', async () => {
|
|
186
|
+
const wrapper = mountAttached();
|
|
187
|
+
const buttons = wrapper.findAll('button[role="menuitem"]');
|
|
188
|
+
await buttons[0].element.focus();
|
|
189
|
+
await wrapper.find('ul[role="menu"]').trigger('keydown', { key: 'ArrowUp' });
|
|
190
|
+
expect(document.activeElement).toBe(buttons[buttons.length - 1].element);
|
|
191
|
+
wrapper.unmount();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('Home moves focus to the first item', async () => {
|
|
195
|
+
const wrapper = mountAttached();
|
|
196
|
+
const buttons = wrapper.findAll('button[role="menuitem"]');
|
|
197
|
+
await buttons[2].element.focus();
|
|
198
|
+
await wrapper.find('ul[role="menu"]').trigger('keydown', { key: 'Home' });
|
|
199
|
+
expect(document.activeElement).toBe(buttons[0].element);
|
|
200
|
+
wrapper.unmount();
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('End moves focus to the last item', async () => {
|
|
204
|
+
const wrapper = mountAttached();
|
|
205
|
+
const buttons = wrapper.findAll('button[role="menuitem"]');
|
|
206
|
+
await buttons[0].element.focus();
|
|
207
|
+
await wrapper.find('ul[role="menu"]').trigger('keydown', { key: 'End' });
|
|
208
|
+
expect(document.activeElement).toBe(buttons[buttons.length - 1].element);
|
|
209
|
+
wrapper.unmount();
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('Escape emits "close"', async () => {
|
|
213
|
+
const wrapper = mountAttached();
|
|
214
|
+
await wrapper.find('ul[role="menu"]').trigger('keydown', { key: 'Escape' });
|
|
215
|
+
expect(wrapper.emitted('close')).toBeTruthy();
|
|
216
|
+
wrapper.unmount();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('disabled items are skipped during ArrowDown navigation', async () => {
|
|
220
|
+
const itemsWithDisabled = [
|
|
221
|
+
{ label: 'First' },
|
|
222
|
+
{ label: 'Disabled', disabled: true },
|
|
223
|
+
{ label: 'Third' },
|
|
224
|
+
];
|
|
225
|
+
const wrapper = mount(MActionListbox, {
|
|
226
|
+
props: { items: itemsWithDisabled },
|
|
227
|
+
attachTo: document.body,
|
|
228
|
+
global: { components: { MDivider, MIconButton, Cross24 } },
|
|
229
|
+
});
|
|
230
|
+
const enabledButtons = wrapper.findAll('button[role="menuitem"]:not([disabled])');
|
|
231
|
+
await enabledButtons[0].element.focus();
|
|
232
|
+
await wrapper.find('ul[role="menu"]').trigger('keydown', { key: 'ArrowDown' });
|
|
233
|
+
expect(document.activeElement).toBe(enabledButtons[1].element);
|
|
234
|
+
wrapper.unmount();
|
|
235
|
+
});
|
|
236
|
+
});
|
|
138
237
|
});
|
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
ref="popover"
|
|
10
10
|
class="mc-listbox__content"
|
|
11
11
|
v-bind="$slots.activator ? { id, popover: '' } : {}"
|
|
12
|
+
@toggle="onPopoverToggle"
|
|
12
13
|
>
|
|
13
14
|
<div class="mc-listbox__header">
|
|
14
|
-
<h3 v-if="title" class="mc-listbox__title">{{ title }}</h3>
|
|
15
|
+
<h3 v-if="title" :id="`${id}-title`" class="mc-listbox__title">{{ title }}</h3>
|
|
15
16
|
<MIconButton
|
|
16
17
|
class="mc-listbox__close"
|
|
17
18
|
ghost
|
|
@@ -24,7 +25,15 @@
|
|
|
24
25
|
</MIconButton>
|
|
25
26
|
</div>
|
|
26
27
|
<div class="mc-listbox__body">
|
|
27
|
-
<ul
|
|
28
|
+
<ul
|
|
29
|
+
ref="menuEl"
|
|
30
|
+
class="mc-action-list"
|
|
31
|
+
role="menu"
|
|
32
|
+
tabindex="-1"
|
|
33
|
+
:aria-label="title || undefined"
|
|
34
|
+
:aria-labelledby="title ? `${id}-title` : undefined"
|
|
35
|
+
@keydown="onMenuKeydown"
|
|
36
|
+
>
|
|
28
37
|
<template v-for="(item, index) in items" :key="`item-${index}`">
|
|
29
38
|
<MDivider
|
|
30
39
|
v-if="item.divider"
|
|
@@ -35,22 +44,24 @@
|
|
|
35
44
|
:class="[
|
|
36
45
|
'mc-action-list__element',
|
|
37
46
|
{
|
|
38
|
-
'mc-action-list__element--danger':
|
|
39
|
-
item.appearance === 'danger',
|
|
47
|
+
'mc-action-list__element--danger': item.appearance === 'danger',
|
|
40
48
|
'mc-action-list__element--disabled': item.disabled,
|
|
41
49
|
},
|
|
42
50
|
]"
|
|
43
|
-
role="
|
|
51
|
+
role="presentation"
|
|
44
52
|
>
|
|
45
53
|
<button
|
|
46
54
|
type="button"
|
|
55
|
+
role="menuitem"
|
|
47
56
|
class="mc-action-list__button"
|
|
57
|
+
:disabled="item.disabled || undefined"
|
|
48
58
|
@click="emit('action', item?.id || index)"
|
|
49
59
|
>
|
|
50
60
|
<component
|
|
51
61
|
v-if="item.icon"
|
|
52
62
|
class="mc-action-list__icon"
|
|
53
63
|
:is="item.icon"
|
|
64
|
+
aria-hidden="true"
|
|
54
65
|
/>
|
|
55
66
|
<p class="mc-action-list__text">{{ item.label }}</p>
|
|
56
67
|
</button>
|
|
@@ -65,7 +76,7 @@
|
|
|
65
76
|
</template>
|
|
66
77
|
|
|
67
78
|
<script setup lang="ts">
|
|
68
|
-
import { useId, useTemplateRef, type Component, type VNode } from 'vue';
|
|
79
|
+
import { nextTick, useId, useTemplateRef, type Component, type VNode } from 'vue';
|
|
69
80
|
import MIconButton from '../iconbutton/MIconButton.vue';
|
|
70
81
|
import MDivider from '../divider/MDivider.vue';
|
|
71
82
|
import { Cross24 } from '@mozaic-ds/icons-vue';
|
|
@@ -137,8 +148,44 @@ const slots = defineSlots<{
|
|
|
137
148
|
}>();
|
|
138
149
|
|
|
139
150
|
const id = useId();
|
|
140
|
-
|
|
141
151
|
const popover = useTemplateRef('popover');
|
|
152
|
+
const menuEl = useTemplateRef('menuEl');
|
|
153
|
+
|
|
154
|
+
function getMenuItems(): HTMLButtonElement[] {
|
|
155
|
+
return Array.from(
|
|
156
|
+
menuEl.value?.querySelectorAll<HTMLButtonElement>('button[role="menuitem"]:not(:disabled)') ?? [],
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function onMenuKeydown(e: KeyboardEvent) {
|
|
161
|
+
const items = getMenuItems();
|
|
162
|
+
if (!items.length) return;
|
|
163
|
+
const current = items.findIndex((el) => el === document.activeElement);
|
|
164
|
+
|
|
165
|
+
if (e.key === 'ArrowDown') {
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
items[(current + 1) % items.length].focus();
|
|
168
|
+
} else if (e.key === 'ArrowUp') {
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
items[(current - 1 + items.length) % items.length].focus();
|
|
171
|
+
} else if (e.key === 'Home') {
|
|
172
|
+
e.preventDefault();
|
|
173
|
+
items[0].focus();
|
|
174
|
+
} else if (e.key === 'End') {
|
|
175
|
+
e.preventDefault();
|
|
176
|
+
items[items.length - 1].focus();
|
|
177
|
+
} else if (e.key === 'Escape') {
|
|
178
|
+
close();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function onPopoverToggle(e: ToggleEvent) {
|
|
183
|
+
if (e.newState === 'open') {
|
|
184
|
+
nextTick(() => getMenuItems()[0]?.focus());
|
|
185
|
+
} else {
|
|
186
|
+
document.querySelector<HTMLElement>(`[popovertarget="${id}"]`)?.focus();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
142
189
|
|
|
143
190
|
function close() {
|
|
144
191
|
emit('close');
|
|
@@ -86,7 +86,9 @@ describe('MBuiltInMenu', () => {
|
|
|
86
86
|
});
|
|
87
87
|
const lis = wrapper.findAll('li');
|
|
88
88
|
const selectedItem = lis[2];
|
|
89
|
-
|
|
89
|
+
// aria-current is on the interactive element, not the <li> container
|
|
90
|
+
const interactiveEl = selectedItem.find('button, a');
|
|
91
|
+
expect(interactiveEl.attributes('aria-current')).toBe('true');
|
|
90
92
|
expect(selectedItem.classes()).toContain(
|
|
91
93
|
'mc-built-in-menu__item--selected',
|
|
92
94
|
);
|
|
@@ -108,4 +110,31 @@ describe('MBuiltInMenu', () => {
|
|
|
108
110
|
'mc-built-in-menu--outlined',
|
|
109
111
|
);
|
|
110
112
|
});
|
|
113
|
+
|
|
114
|
+
it('uses default aria-label "Menu" on nav when label prop is not provided', () => {
|
|
115
|
+
const wrapper = mount(MBuiltInMenu, { props: { items } });
|
|
116
|
+
expect(wrapper.find('nav').attributes('aria-label')).toBe('Menu');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('uses custom label prop as aria-label on nav', () => {
|
|
120
|
+
const wrapper = mount(MBuiltInMenu, {
|
|
121
|
+
props: { items, label: 'Settings navigation' },
|
|
122
|
+
});
|
|
123
|
+
expect(wrapper.find('nav').attributes('aria-label')).toBe('Settings navigation');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('sets aria-hidden on ChevronRight and item icons', () => {
|
|
127
|
+
const wrapper = mount(MBuiltInMenu, { props: { items } });
|
|
128
|
+
// All SVG icons inside items should be aria-hidden
|
|
129
|
+
const ariaHiddenIcons = wrapper.findAll('[aria-hidden="true"]');
|
|
130
|
+
expect(ariaHiddenIcons.length).toBeGreaterThan(0);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('does not put aria-current on the <li>, only on the interactive element', () => {
|
|
134
|
+
const wrapper = mount(MBuiltInMenu, { props: { items, modelValue: 0 } });
|
|
135
|
+
const li = wrapper.findAll('li')[0];
|
|
136
|
+
expect(li.attributes('aria-current')).toBeUndefined();
|
|
137
|
+
const interactive = li.find('button, a');
|
|
138
|
+
expect(interactive.attributes('aria-current')).toBe('true');
|
|
139
|
+
});
|
|
111
140
|
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
'mc-built-in-menu': true,
|
|
5
5
|
'mc-built-in-menu--outlined': props.outlined,
|
|
6
6
|
}"
|
|
7
|
-
aria-label="
|
|
7
|
+
:aria-label="props.label"
|
|
8
8
|
>
|
|
9
9
|
<ul class="mc-built-in-menu__list">
|
|
10
10
|
<li
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
'mc-built-in-menu__item': true,
|
|
15
15
|
'mc-built-in-menu__item--selected': currentMenuItem === index,
|
|
16
16
|
}"
|
|
17
|
-
v-bind="currentMenuItem === index ? { 'aria-current': true } : {}"
|
|
18
17
|
>
|
|
19
18
|
<component
|
|
20
19
|
:is="getItemTag(item)"
|
|
@@ -23,17 +22,19 @@
|
|
|
23
22
|
'mc-built-in-menu__link': isLink(item),
|
|
24
23
|
}"
|
|
25
24
|
v-bind="isLink(item) ? getLinkAttrs(item) : {}"
|
|
25
|
+
:aria-current="currentMenuItem === index ? true : undefined"
|
|
26
26
|
@click="currentMenuItem = index"
|
|
27
27
|
>
|
|
28
28
|
<component
|
|
29
29
|
v-if="item.icon"
|
|
30
30
|
:is="item.icon"
|
|
31
31
|
class="mc-built-in-menu__icon"
|
|
32
|
+
aria-hidden="true"
|
|
32
33
|
/>
|
|
33
34
|
|
|
34
35
|
<span class="mc-built-in-menu__label">{{ item.label }}</span>
|
|
35
36
|
|
|
36
|
-
<ChevronRight20 class="mc-built-in-menu__icon" />
|
|
37
|
+
<ChevronRight20 class="mc-built-in-menu__icon" aria-hidden="true" />
|
|
37
38
|
</component>
|
|
38
39
|
</li>
|
|
39
40
|
</ul>
|
|
@@ -56,20 +57,28 @@ export type MenuItem = {
|
|
|
56
57
|
target?: '_self' | '_blank' | '_parent' | '_top';
|
|
57
58
|
};
|
|
58
59
|
|
|
59
|
-
const props =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
60
|
+
const props = withDefaults(
|
|
61
|
+
defineProps<{
|
|
62
|
+
/**
|
|
63
|
+
* Specifies the key of the currently selected menu item. It allows the component to highlight or style the corresponding item to indicate it is selected or currently in use.
|
|
64
|
+
*/
|
|
65
|
+
modelValue?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Defines the menu items, each of which can include an icon and act as a button, link, or router-link.
|
|
68
|
+
*/
|
|
69
|
+
items: MenuItem[];
|
|
70
|
+
/**
|
|
71
|
+
* When enabled, adds a visible border around the wrapper to highlight or separate its content.
|
|
72
|
+
*/
|
|
73
|
+
outlined?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Accessible label for the navigation landmark. Should describe the purpose
|
|
76
|
+
* of this menu to distinguish it from other navigations on the page.
|
|
77
|
+
*/
|
|
78
|
+
label?: string;
|
|
79
|
+
}>(),
|
|
80
|
+
{ label: 'Menu' },
|
|
81
|
+
);
|
|
73
82
|
|
|
74
83
|
const emit = defineEmits<{
|
|
75
84
|
/**
|
|
@@ -10,6 +10,8 @@ A built-in menu is a structured list of navigational or interactive options, typ
|
|
|
10
10
|
| `modelValue` | Specifies the key of the currently selected menu item. It allows the component to highlight or style the corresponding item to indicate it is selected or currently in use. | `number` | - |
|
|
11
11
|
| `items*` | Defines the menu items, each of which can include an icon and act as a button, link, or router-link. | `MenuItem[]` | - |
|
|
12
12
|
| `outlined` | When enabled, adds a visible border around the wrapper to highlight or separate its content. | `boolean` | - |
|
|
13
|
+
| `label` | Accessible label for the navigation landmark. Should describe the purpose
|
|
14
|
+
of this menu to distinguish it from other navigations on the page. | `string` | `"Menu"` |
|
|
13
15
|
|
|
14
16
|
## Events
|
|
15
17
|
|
|
@@ -188,4 +188,30 @@ describe('MButton component', () => {
|
|
|
188
188
|
expect(label.exists()).toBe(true);
|
|
189
189
|
expect(label.text()).toBe('Normal Button');
|
|
190
190
|
});
|
|
191
|
+
|
|
192
|
+
it('sets aria-busy="true" when isLoading is true', () => {
|
|
193
|
+
const wrapper = mount(MButton, {
|
|
194
|
+
props: { isLoading: true },
|
|
195
|
+
slots: { default: 'Loading' },
|
|
196
|
+
});
|
|
197
|
+
expect(wrapper.find('button').attributes('aria-busy')).toBe('true');
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('does not set aria-busy when isLoading is false', () => {
|
|
201
|
+
const wrapper = mount(MButton, {
|
|
202
|
+
props: { isLoading: false },
|
|
203
|
+
slots: { default: 'Normal' },
|
|
204
|
+
});
|
|
205
|
+
expect(wrapper.find('button').attributes('aria-busy')).toBeUndefined();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('sets aria-hidden on the loader wrapper', () => {
|
|
209
|
+
const wrapper = mount(MButton, {
|
|
210
|
+
props: { isLoading: true },
|
|
211
|
+
slots: { default: 'Loading' },
|
|
212
|
+
});
|
|
213
|
+
const loaderWrapper = wrapper.find('.mc-button__icon[aria-hidden]');
|
|
214
|
+
expect(loaderWrapper.exists()).toBe(true);
|
|
215
|
+
expect(loaderWrapper.attributes('aria-hidden')).toBe('true');
|
|
216
|
+
});
|
|
191
217
|
});
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
:class="classObject"
|
|
5
5
|
:disabled="disabled"
|
|
6
6
|
:type="type"
|
|
7
|
+
:aria-busy="isLoading || undefined"
|
|
7
8
|
>
|
|
8
9
|
<span
|
|
9
10
|
v-if="$slots.icon && iconPosition == 'left' && !isLoading"
|
|
@@ -15,6 +16,7 @@
|
|
|
15
16
|
v-if="isLoading"
|
|
16
17
|
class="mc-button__icon"
|
|
17
18
|
:style="{ position: 'absolute' }"
|
|
19
|
+
aria-hidden="true"
|
|
18
20
|
>
|
|
19
21
|
<MLoader :style="{ color: 'currentColor' }" size="s" />
|
|
20
22
|
</span>
|
|
@@ -97,4 +97,39 @@ describe('MCallout.vue', () => {
|
|
|
97
97
|
|
|
98
98
|
expect(wrapper.find('.mc-callout__footer').exists()).toBe(false);
|
|
99
99
|
});
|
|
100
|
+
|
|
101
|
+
it('renders title with default tag prop (h2)', () => {
|
|
102
|
+
const wrapper = mount(MCallout, {
|
|
103
|
+
props: { title: 'Title', description: 'Desc' },
|
|
104
|
+
});
|
|
105
|
+
expect(wrapper.find('h2.mc-callout__title').exists()).toBe(true);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('renders title with custom tag prop', () => {
|
|
109
|
+
const wrapper = mount(MCallout, {
|
|
110
|
+
props: { title: 'Title', description: 'Desc', tag: 'h3' },
|
|
111
|
+
});
|
|
112
|
+
expect(wrapper.find('h3.mc-callout__title').exists()).toBe(true);
|
|
113
|
+
expect(wrapper.find('h2').exists()).toBe(false);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('has aria-labelledby pointing to the title', () => {
|
|
117
|
+
const wrapper = mount(MCallout, {
|
|
118
|
+
props: { title: 'Title', description: 'Desc' },
|
|
119
|
+
});
|
|
120
|
+
const section = wrapper.find('section');
|
|
121
|
+
const titleId = wrapper.find('.mc-callout__title').attributes('id');
|
|
122
|
+
expect(titleId).toBeDefined();
|
|
123
|
+
expect(section.attributes('aria-labelledby')).toBe(titleId);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('sets aria-hidden on the icon wrapper', () => {
|
|
127
|
+
const wrapper = mount(MCallout, {
|
|
128
|
+
props: { title: 'Title', description: 'Desc' },
|
|
129
|
+
slots: { icon: '<svg class="icon" />' },
|
|
130
|
+
});
|
|
131
|
+
expect(wrapper.find('.mc-callout__icon').attributes('aria-hidden')).toBe(
|
|
132
|
+
'true',
|
|
133
|
+
);
|
|
134
|
+
});
|
|
100
135
|
});
|
|
@@ -18,9 +18,6 @@ const meta: Meta<typeof MCallout> = {
|
|
|
18
18
|
},
|
|
19
19
|
args: {
|
|
20
20
|
icon: '<ImageAlt32 aria-hidden="true" />',
|
|
21
|
-
title:
|
|
22
|
-
'This is a title, be concise and use the description message to give details.',
|
|
23
|
-
description: 'Description message.',
|
|
24
21
|
},
|
|
25
22
|
render: (args) => ({
|
|
26
23
|
components: { MCallout, MButton, MLink, ArrowNext20, ImageAlt32 },
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<section
|
|
3
|
-
|
|
2
|
+
<section
|
|
3
|
+
class="mc-callout"
|
|
4
|
+
role="status"
|
|
5
|
+
:class="classObject"
|
|
6
|
+
:aria-labelledby="`callout-title-${id}`"
|
|
7
|
+
>
|
|
8
|
+
<div class="mc-callout__icon" aria-hidden="true">
|
|
4
9
|
<slot name="icon" />
|
|
5
10
|
</div>
|
|
6
11
|
<div class="mc-callout__content">
|
|
7
|
-
<
|
|
12
|
+
<component
|
|
13
|
+
v-if="title"
|
|
14
|
+
:is="props.tag"
|
|
15
|
+
:id="`callout-title-${id}`"
|
|
16
|
+
class="mc-callout__title"
|
|
17
|
+
>{{ title }}</component
|
|
18
|
+
>
|
|
8
19
|
|
|
9
|
-
<p class="mc-callout__message">
|
|
20
|
+
<p v-if="description" class="mc-callout__message">
|
|
10
21
|
{{ description }}
|
|
11
22
|
</p>
|
|
12
23
|
|
|
@@ -18,7 +29,7 @@
|
|
|
18
29
|
</template>
|
|
19
30
|
|
|
20
31
|
<script setup lang="ts">
|
|
21
|
-
import { computed, type VNode } from 'vue';
|
|
32
|
+
import { computed, useId, type VNode } from 'vue';
|
|
22
33
|
/**
|
|
23
34
|
* A callout is used to highlight additional information that can assist users with tips, extra details, or helpful guidance, without signaling a critical status or alert. Unlike notifications, callouts are not triggered by user actions and do not correspond to specific system states. They are designed to enhance the user experience by providing contextually relevant information that supports comprehension and usability.
|
|
24
35
|
*/
|
|
@@ -27,21 +38,29 @@ const props = withDefaults(
|
|
|
27
38
|
/**
|
|
28
39
|
* Title of the callout.
|
|
29
40
|
*/
|
|
30
|
-
title
|
|
41
|
+
title?: string;
|
|
31
42
|
/**
|
|
32
43
|
* Description of the callout.
|
|
33
44
|
*/
|
|
34
|
-
description
|
|
45
|
+
description?: string;
|
|
35
46
|
/**
|
|
36
47
|
* Allows to define the callout appearance.
|
|
37
48
|
*/
|
|
38
49
|
appearance?: 'standard' | 'accent' | 'tips' | 'inverse';
|
|
50
|
+
/**
|
|
51
|
+
* Heading level for the callout title (h2–h6). Adjust to match the
|
|
52
|
+
* heading hierarchy of the page where the callout is used.
|
|
53
|
+
*/
|
|
54
|
+
tag?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
39
55
|
}>(),
|
|
40
56
|
{
|
|
41
57
|
appearance: 'standard',
|
|
58
|
+
tag: 'h2',
|
|
42
59
|
},
|
|
43
60
|
);
|
|
44
61
|
|
|
62
|
+
const id = useId();
|
|
63
|
+
|
|
45
64
|
defineSlots<{
|
|
46
65
|
/**
|
|
47
66
|
* Use this slot to insert an icon.
|
|
@@ -7,9 +7,11 @@ A callout is used to highlight additional information that can assist users with
|
|
|
7
7
|
|
|
8
8
|
| Name | Description | Type | Default |
|
|
9
9
|
| --- | --- | --- | --- |
|
|
10
|
-
| `title
|
|
11
|
-
| `description
|
|
10
|
+
| `title` | Title of the callout. | `string` | - |
|
|
11
|
+
| `description` | Description of the callout. | `string` | - |
|
|
12
12
|
| `appearance` | Allows to define the callout appearance. | `"standard"` `"inverse"` `"accent"` `"tips"` | `"standard"` |
|
|
13
|
+
| `tag` | Heading level for the callout title (h2–h6). Adjust to match the
|
|
14
|
+
heading hierarchy of the page where the callout is used. | `"h2"` `"h1"` `"h3"` `"h4"` `"h5"` `"h6"` | `"h2"` |
|
|
13
15
|
|
|
14
16
|
## Slots
|
|
15
17
|
|