Skip to content

Commit 58812c3

Browse files
committed
fix(DsfrModal): ♿ La modale est visible si styles désactivés
1 parent d6ca0f9 commit 58812c3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/components/DsfrModal/DsfrModal.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ import { FocusTrap } from 'focus-trap-vue'
55
66
import DsfrButtonGroup from '../DsfrButton/DsfrButtonGroup.vue'
77
import { onMounted, onBeforeUnmount, computed, ref, nextTick, watch, Ref } from 'vue'
8+
import { getRandomId } from '@/utils/random-utils'
89
910
const props = withDefaults(defineProps<{
11+
modalId?: string
1012
opened?: boolean
1113
actions?: Record<string, any>[]
1214
isAlert?: boolean
1315
origin?: {focus:() => void}
1416
title: string
1517
icon?: string
1618
}>(), {
19+
modalId: () => getRandomId('modal', 'dialog'),
1720
actions: () => [],
1821
origin: () => ({ focus () {} }), // eslint-disable-line @typescript-eslint/no-empty-function
1922
icon: undefined,
@@ -35,14 +38,18 @@ const closeBtn: Ref<HTMLButtonElement | null> = ref(null)
3538
watch(() => props.opened, (newValue) => {
3639
if (newValue) {
3740
document.body.classList.add('modal-open')
41+
modal.value?.showModal()
3842
setTimeout(() => {
3943
closeBtn.value?.focus()
4044
}, 100)
4145
} else {
4246
document.body.classList.remove('modal-open')
47+
modal.value?.close()
4348
}
4449
})
4550
51+
const modal = ref()
52+
4653
onMounted(() => {
4754
startListeningToEscape()
4855
})
@@ -72,10 +79,12 @@ async function close () {
7279
>
7380
<dialog
7481
id="fr-modal-1"
75-
aria-labelledby="fr-modal-title-modal-1"
82+
ref="modal"
83+
:aria-labelledby="modalId"
7684
:role="role"
7785
class="fr-modal"
7886
:class="{'fr-modal--opened': opened}"
87+
:open="opened"
7988
>
8089
<div class="fr-container fr-container--fluid fr-container-md">
8190
<div class="fr-grid-row fr-grid-row--center">
@@ -97,7 +106,7 @@ async function close () {
97106
</div>
98107
<div class="fr-modal__content">
99108
<h1
100-
id="fr-modal-title-modal-1"
109+
:id="modalId"
101110
class="fr-modal__title"
102111
>
103112
<span

0 commit comments

Comments
 (0)