File tree Expand file tree Collapse file tree 2 files changed +39
-9
lines changed
Expand file tree Collapse file tree 2 files changed +39
-9
lines changed Original file line number Diff line number Diff line change @@ -30,8 +30,7 @@ describe('DsfrAlert', () => {
3030 // Then
3131 expect ( titleEl . tagName ) . toBe ( 'H3' )
3232 expect ( titleEl ) . toHaveClass ( 'fr-alert__title' )
33- expect ( descritptionEl . tagName ) . toBe ( 'DIV' )
34- expect ( descritptionEl ) . toHaveClass ( 'fr-alert' )
33+ expect ( descritptionEl . tagName ) . toBe ( 'P' )
3534 } )
3635
3736 it ( 'should mount DsfrAlert with right content with description in slot' , ( ) => {
@@ -87,7 +86,7 @@ describe('DsfrAlert', () => {
8786 } ,
8887 } )
8988
90- const closeBtn = getByTitle ( 'Fermer' )
89+ const closeBtn = getByTitle ( 'Fermer le message ' )
9190 await fireEvent . click ( closeBtn )
9291
9392 // Then
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ const props = withDefaults(defineProps<DsfrAlertProps>(), {
1212 title: ' ' ,
1313 titleTag: ' h3' ,
1414 type: ' info' ,
15- closeButtonLabel: ' Fermer' ,
15+ closeButtonLabel: ' Fermer le message ' ,
1616})
1717
1818const emit = defineEmits <{ (e : ' close' ): void }>()
@@ -26,6 +26,19 @@ const classes = computed(
2626 },
2727 ]),
2828)
29+
30+ const idTitle = computed (() => useRandomId (' alert' , ' title' ))
31+ const idDescription = computed (() => useRandomId (' alert' , ' description' ))
32+
33+ const idListDescribedby = computed (() => {
34+ if (props .description && ! props .title ) {
35+ return idDescription .value
36+ }
37+ if (! props .description && props .title ) {
38+ return idTitle .value
39+ }
40+ return ` ${idTitle .value } ${idDescription .value } `
41+ })
2942 </script >
3043
3144<template >
@@ -39,19 +52,37 @@ const classes = computed(
3952 <component
4053 :is =" titleTag"
4154 v-if =" !small"
55+ :id =" idTitle"
4256 class =" fr-alert__title"
4357 >
4458 {{ title }}
4559 </component >
46- <slot >
60+ <p
61+ v-if =" description"
62+ :id =" idDescription"
63+ >
4764 {{ description }}
48- </slot >
65+ </p >
66+ <slot v-else />
4967 <button
5068 v-if =" closeable"
51- class = " fr-btn fr-btn--close "
69+ :aria-describedby = " idListDescribedby "
5270 :title =" closeButtonLabel"
53- :aria-label = " closeButtonLabel "
71+ class = " fr-btn fr-btn--close "
5472 @click =" onClick"
55- />
73+ >
74+ <span class =" fr-sr-only" >{{ closeButtonLabel }}</span >
75+ </button >
5676 </div >
5777</template >
78+
79+ <style scoped>
80+ p {
81+ padding : 0 ;
82+ margin : 0 ;
83+ }
84+
85+ .fr-alert--sm {
86+ padding : .5rem 2.25rem .5rem 3rem ;
87+ }
88+ </style >
You can’t perform that action at this time.
0 commit comments