File tree 3 files changed +43
-6
lines changed
examples/bpk-component-modal
packages/bpk-component-modal/src
3 files changed +43
-6
lines changed Original file line number Diff line number Diff line change @@ -106,13 +106,13 @@ const content = [
106
106
pulvinar erat dignissim vitae.
107
107
</ Paragraph > ,
108
108
] ;
109
- type ContainerProps = {
109
+ type ContainerProps = {
110
110
title ?: string ;
111
111
buttonLabel ?: string ;
112
112
id ?: string ;
113
113
wrapperProps ?: Object ;
114
114
isOpen ?: boolean ;
115
- } & Omit < BpkModalProps , 'getApplicationElement' | 'id' | 'isOpen' > ;
115
+ } & Omit < BpkModalProps , 'getApplicationElement' | 'id' | 'isOpen' > ;
116
116
117
117
const ModalContainer = ( props : ContainerProps ) => {
118
118
const [ isOpen , setIsOpen ] = useState ( props . isOpen || false ) ;
@@ -230,8 +230,7 @@ const NestedExample = (isOpen: boolean) => (
230
230
231
231
const NoHeaderExample = ( isOpen : boolean ) => (
232
232
< ModalContainer
233
- title = "Modal title"
234
- closeLabel = "Close modal"
233
+ ariaLabel = "Modal title"
235
234
showHeader = { false }
236
235
isOpen = { isOpen }
237
236
>
@@ -252,7 +251,7 @@ const WithAccessoryViewExample = (isOpen: boolean) => (
252
251
accessoryView = {
253
252
< BpkNavigationBarButtonLink
254
253
label = "Close"
255
- onClick = { ( ) => { } }
254
+ onClick = { ( ) => { } }
256
255
className = { getClassName ( 'bpk-modal__leading-button' ) }
257
256
>
258
257
< div >
Original file line number Diff line number Diff line change 16
16
* limitations under the License.
17
17
*/
18
18
19
- import { render } from '@testing-library/react' ;
19
+ import { render , screen } from '@testing-library/react' ;
20
20
21
21
import { BpkNavigationBarButtonLink } from '../../bpk-component-navigation-bar' ;
22
22
@@ -198,4 +198,39 @@ describe('BpkModalInner', () => {
198
198
) ;
199
199
expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
200
200
} ) ;
201
+
202
+ it ( 'should render correctly with showHeader false' , ( ) => {
203
+ render (
204
+ < BpkModalInner
205
+ id = "my-modal"
206
+ ariaLabel = "Modal title"
207
+ showHeader = { false }
208
+ dialogRef = { jest . fn ( ) }
209
+ isIphone = { false }
210
+ >
211
+ Modal content
212
+ </ BpkModalInner > ,
213
+ ) ;
214
+
215
+ expect ( screen . queryAllByRole ( 'heading' ) ) . toHaveLength ( 0 ) ;
216
+ expect ( screen . getByRole ( 'dialog' ) ) . toHaveAttribute ( 'aria-label' , 'Modal title' ) ;
217
+ } ) ;
218
+
219
+ it ( 'should render with a11y labelled-by when showHeader true' , ( ) => {
220
+ render (
221
+ < BpkModalInner
222
+ id = "my-modal"
223
+ title = "Actual title"
224
+ ariaLabel = "Ignored title"
225
+ showHeader
226
+ dialogRef = { jest . fn ( ) }
227
+ isIphone = { false }
228
+ >
229
+ Modal content
230
+ </ BpkModalInner > ,
231
+ ) ;
232
+
233
+ expect ( screen . getByRole ( 'heading' ) ) . toHaveTextContent ( 'Actual title' ) ;
234
+ expect ( screen . getByRole ( 'dialog' ) ) . toHaveAccessibleName ( 'Actual title' ) ;
235
+ } ) ;
201
236
} ) ;
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ export type Props = {
52
52
* The accessory view allows for icons and actions to be placed in front of the main title inside the modal header. To be used with `BpkNavigationBarButtonLink`
53
53
*/
54
54
accessoryView ?: ReactNode ;
55
+ ariaLabel ?: string // optional aria label for scenario when header is disabled
55
56
} ;
56
57
57
58
export const MODAL_STYLING = {
@@ -62,6 +63,7 @@ export type ModalStyle = (typeof MODAL_STYLING)[keyof typeof MODAL_STYLING];
62
63
63
64
const BpkModalInner = ( {
64
65
accessoryView = null ,
66
+ ariaLabel,
65
67
children,
66
68
className = null ,
67
69
closeLabel = '' ,
@@ -125,6 +127,7 @@ const BpkModalInner = ({
125
127
tabIndex = { - 1 }
126
128
role = "dialog"
127
129
aria-labelledby = { showHeader ? headingId : undefined }
130
+ aria-label = { ! showHeader ? ariaLabel : undefined }
128
131
className = { classNames . join ( ' ' ) }
129
132
ref = { dialogRef }
130
133
>
You can’t perform that action at this time.
0 commit comments