@@ -28,6 +28,7 @@ import FocusTrap from 'focus-trap-react';
2828/**
2929 * WordPress dependencies
3030 */
31+ import { withInstanceId } from '@wordpress/compose' ;
3132import { Component , createRef } from '@wordpress/element' ;
3233import { __ } from '@wordpress/i18n' ;
3334
@@ -61,16 +62,21 @@ class Dialog extends Component {
6162 subtitle,
6263 confirmButton,
6364 dependentModules,
65+ instanceId,
6466 } = this . props ;
6567
68+ const labelledByID = `googlesitekit-dialog-label-${ instanceId } ` ;
69+ const describedByID = `googlesitekit-dialog-description-${ instanceId } ` ;
70+ const hasProvides = ! ! ( provides && provides . length ) ;
71+
6672 return (
6773 < div
6874 ref = { this . dialogRef }
6975 className = { `mdc-dialog ${ dialogActive ? 'mdc-dialog--open' : '' } ` }
7076 role = "alertdialog"
7177 aria-modal = "true"
72- aria-labelledby = "remove-module-dialog"
73- aria-describedby = "remove-module-dialog-description"
78+ aria-labelledby = { title ? labelledByID : undefined }
79+ aria-describedby = { hasProvides ? describedByID : undefined }
7480 aria-hidden = { dialogActive ? 'false' : 'true' }
7581 tabIndex = "-1"
7682 >
@@ -80,7 +86,7 @@ class Dialog extends Component {
8086 < div className = "mdc-dialog__container" >
8187 < div className = "mdc-dialog__surface" >
8288 { title &&
83- < h2 id = "remove-module-dialog" className = "mdc-dialog__title" >
89+ < h2 id = { labelledByID } className = "mdc-dialog__title" >
8490 { title }
8591 </ h2 >
8692 }
@@ -89,15 +95,17 @@ class Dialog extends Component {
8995 { subtitle }
9096 </ p >
9197 }
92- < section id = "remove-module-dialog-description" className = "mdc-dialog__content" >
93- < ul className = "mdc-list mdc-list--underlined mdc-list--non-interactive" >
94- { provides && provides . map ( ( attribute ) => (
95- < li className = "mdc-list-item" key = { attribute } >
96- < span className = "mdc-list-item__text" > { attribute } </ span >
97- </ li >
98- ) ) }
99- </ ul >
100- </ section >
98+ { hasProvides &&
99+ < section id = { describedByID } className = "mdc-dialog__content" >
100+ < ul className = "mdc-list mdc-list--underlined mdc-list--non-interactive" >
101+ { provides . map ( ( attribute ) => (
102+ < li className = "mdc-list-item" key = { attribute } >
103+ < span className = "mdc-list-item__text" > { attribute } </ span >
104+ </ li >
105+ ) ) }
106+ </ ul >
107+ </ section >
108+ }
101109 { dependentModules &&
102110 < p className = "mdc-dialog__dependecies" >
103111 < strong > { __ ( 'Note: ' , 'google-site-kit' ) } </ strong > { dependentModules }
@@ -140,4 +148,4 @@ Dialog.defaultProps = {
140148 confirmButton : null ,
141149} ;
142150
143- export default Dialog ;
151+ export default withInstanceId ( Dialog ) ;
0 commit comments