Skip to content

Commit 035c839

Browse files
adminadmin
authored andcommitted
fix: 1223 vocalisation toasts
1 parent d8fb59f commit 035c839

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

packages/shared-ui/src/components/Toaster.vue

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,30 @@ import { DsfrAlert } from "@gouvminint/vue-dsfr";
44
55
const { toasts } = useToaster();
66
7+
const liveMessage = ref<string>("");
8+
9+
watch(
10+
() => toasts.length,
11+
(newLength, oldLength) => {
12+
if (newLength > oldLength) {
13+
const lastToast = toasts[toasts.length - 1];
14+
15+
liveMessage.value = "";
16+
17+
nextTick(() => {
18+
setTimeout(() => {
19+
const message = `${lastToast.title ? lastToast.title + ". " : ""}${lastToast.description || ""}`;
20+
liveMessage.value = message;
21+
22+
setTimeout(() => {
23+
liveMessage.value = "";
24+
}, 1000);
25+
}, 100);
26+
});
27+
}
28+
},
29+
);
30+
731
function isValidToast(toast: any): boolean {
832
return toast && toast.id && toast.type;
933
}
@@ -16,6 +40,15 @@ function resolvedClosed(id: string) {
1640

1741
<template>
1842
<div class="toast-container toast-container--top">
43+
<div
44+
v-if="liveMessage"
45+
role="status"
46+
aria-live="polite"
47+
aria-atomic="true"
48+
class="fr-sr-only"
49+
>
50+
{{ liveMessage }}
51+
</div>
1952
<template v-for="toast in toasts" :key="toast.id">
2053
<DsfrAlert
2154
v-if="isValidToast(toast)"
@@ -28,7 +61,7 @@ function resolvedClosed(id: string) {
2861
:closeable="true"
2962
:close-button-label="toast.closeButtonLabel || 'Fermer'"
3063
:role="toast.role || 'status'"
31-
:aria-live="toast.role === 'alert' ? 'assertive' : 'polite'"
64+
aria-live="off"
3265
:duration="toast.duration || undefined"
3366
@close="() => resolvedClosed(toast.id)"
3467
/>

0 commit comments

Comments
 (0)