@@ -7,7 +7,6 @@ import type { Equals } from "tsafe";
77import { createComponentI18nApi } from "../i18n" ;
88import type { FrIconClassName , RiIconClassName } from "../fr/generatedFromCss/classNames" ;
99import Button , { ButtonProps } from "../Button" ;
10- import { typeGuard } from "tsafe/typeGuard" ;
1110import { overwriteReadonlyProp } from "tsafe/lab/overwriteReadonlyProp" ;
1211
1312export type ModalProps = {
@@ -224,7 +223,9 @@ export function createModal(params: { isOpenedByDefault: boolean; id: string }):
224223 nativeButtonProps = { {
225224 ...buttonProps ,
226225 "id" : hiddenControlButtonId ,
227- "type" : "button"
226+ "type" : "button" ,
227+ "tabIndex" : - 1 ,
228+ "aria-hidden" : true
228229 } }
229230 className = { fr . cx ( "fr-hidden" ) }
230231 >
@@ -240,28 +241,17 @@ export function createModal(params: { isOpenedByDefault: boolean; id: string }):
240241 overwriteReadonlyProp ( Component as any , "name" , Component . displayName ) ;
241242
242243 function open ( ) {
243- const hiddenControlButton = document . getElementById ( hiddenControlButtonId ) ;
244-
245- assert ( hiddenControlButton !== null , "Modal isn't mounted" ) ;
244+ const modalElement = document . getElementById ( id ) ;
246245
247- hiddenControlButton . click ( ) ;
246+ // @ts -expect-error: Property 'dsfr' does not exist on type 'Window & typeof globalThis'.ts(2339)
247+ window . dsfr ( modalElement ) . modal . disclose ( ) ;
248248 }
249249
250250 function close ( ) {
251251 const modalElement = document . getElementById ( id ) ;
252252
253- assert ( modalElement !== null , "Modal isn't mounted" ) ;
254-
255- const closeButtonElement = modalElement . querySelector ( `.${ fr . cx ( "fr-btn--close" ) } ` ) ;
256-
257- assert ( closeButtonElement !== null ) ;
258-
259- assert (
260- typeGuard < HTMLButtonElement > ( closeButtonElement , "click" in closeButtonElement ) ,
261- "Close button isn't a button"
262- ) ;
263-
264- closeButtonElement . click ( ) ;
253+ // @ts -expect-error: Property 'dsfr' does not exist on type 'Window & typeof globalThis'.ts(2339)
254+ window . dsfr ( modalElement ) . modal . conceal ( ) ;
265255 }
266256
267257 return {
0 commit comments