@@ -110,6 +110,89 @@ describe('EuiFlyout', () => {
110110 ) ;
111111 } ) ;
112112
113+ describe ( 'aria-labelledby and flyout menu integration' , ( ) => {
114+ it ( 'sets aria-labelledby when flyout has a menu with title' , ( ) => {
115+ const { getByTestSubject } = render (
116+ < EuiFlyout
117+ onClose = { ( ) => { } }
118+ flyoutMenuProps = { { title : 'Test Menu Title' } }
119+ data-test-subj = "flyout"
120+ />
121+ ) ;
122+
123+ const flyout = getByTestSubject ( 'flyout' ) ;
124+ const ariaLabelledBy = flyout . getAttribute ( 'aria-labelledby' ) ;
125+
126+ // Should have a generated ID for the menu title
127+ expect ( ariaLabelledBy ) . toBeTruthy ( ) ;
128+ expect ( ariaLabelledBy ) . toMatch ( / ^ g e n e r a t e d - i d / ) ;
129+ } ) ;
130+
131+ it ( 'uses custom titleId when provided in flyoutMenuProps' , ( ) => {
132+ const customTitleId = 'my-custom-title-id' ;
133+ const { getByTestSubject } = render (
134+ < EuiFlyout
135+ onClose = { ( ) => { } }
136+ flyoutMenuProps = { {
137+ title : 'Test Menu Title' ,
138+ titleId : customTitleId ,
139+ } }
140+ data-test-subj = "flyout"
141+ />
142+ ) ;
143+
144+ const flyout = getByTestSubject ( 'flyout' ) ;
145+ expect ( flyout ) . toHaveAttribute ( 'aria-labelledby' , customTitleId ) ;
146+ } ) ;
147+
148+ it ( 'combines flyout menu ID with existing aria-labelledby' , ( ) => {
149+ const customTitleId = 'my-custom-title-id' ;
150+ const existingAriaLabelledBy = 'existing-label-id' ;
151+
152+ const { getByTestSubject } = render (
153+ < EuiFlyout
154+ onClose = { ( ) => { } }
155+ flyoutMenuProps = { {
156+ title : 'Test Menu Title' ,
157+ titleId : customTitleId ,
158+ } }
159+ aria-labelledby = { existingAriaLabelledBy }
160+ data-test-subj = "flyout"
161+ />
162+ ) ;
163+
164+ const flyout = getByTestSubject ( 'flyout' ) ;
165+ expect ( flyout ) . toHaveAttribute (
166+ 'aria-labelledby' ,
167+ `${ customTitleId } ${ existingAriaLabelledBy } `
168+ ) ;
169+ } ) ;
170+
171+ it ( 'does not set aria-labelledby when flyout has no menu' , ( ) => {
172+ const { getByTestSubject } = render (
173+ < EuiFlyout onClose = { ( ) => { } } data-test-subj = "flyout" />
174+ ) ;
175+
176+ const flyout = getByTestSubject ( 'flyout' ) ;
177+ expect ( flyout ) . not . toHaveAttribute ( 'aria-labelledby' ) ;
178+ } ) ;
179+
180+ it ( 'only uses existing aria-labelledby when no menu is present' , ( ) => {
181+ const existingAriaLabelledBy = 'existing-label-id' ;
182+
183+ const { getByTestSubject } = render (
184+ < EuiFlyout
185+ onClose = { ( ) => { } }
186+ aria-labelledby = { existingAriaLabelledBy }
187+ data-test-subj = "flyout"
188+ />
189+ ) ;
190+
191+ const flyout = getByTestSubject ( 'flyout' ) ;
192+ expect ( flyout ) . toHaveAttribute ( 'aria-labelledby' , existingAriaLabelledBy ) ;
193+ } ) ;
194+ } ) ;
195+
113196 describe ( 'props' , ( ) => {
114197 test ( 'hideCloseButton' , ( ) => {
115198 const { baseElement } = render (
0 commit comments