@@ -181,6 +181,34 @@ describe('Tabs', () => {
181
181
expect ( tabs [ 0 ] ) . toHaveClass ( 'selected' ) ;
182
182
} ) ;
183
183
184
+ it ( 'should update TabPanel ID when current tab is changed' , ( ) => {
185
+ let onSelectionChange = jest . fn ( ) ;
186
+ let { getByRole, getAllByRole} = render (
187
+ < Tabs onSelectionChange = { onSelectionChange } >
188
+ < TabList >
189
+ < Tab id = "first-element" > First</ Tab >
190
+ < Tab id = "second-element" > Second</ Tab >
191
+ < Tab id = "third-element" > Third</ Tab >
192
+ </ TabList >
193
+ < TabPanel id = "first-element" > First</ TabPanel >
194
+ < TabPanel id = "second-element" > Second</ TabPanel >
195
+ < TabPanel id = "third-element" > Third</ TabPanel >
196
+ </ Tabs >
197
+ ) ;
198
+
199
+ expect ( getByRole ( 'tabpanel' ) . getAttribute ( 'id' ) ) . toContain ( 'first-element' ) ;
200
+ let tabs = getAllByRole ( 'tab' ) ;
201
+
202
+ userEvent . click ( tabs [ 1 ] ) ;
203
+ expect ( onSelectionChange ) . toHaveBeenCalled ( ) ;
204
+ expect ( getByRole ( 'tabpanel' ) . getAttribute ( 'id' ) ) . toContain ( 'second-element' ) ;
205
+
206
+ userEvent . click ( tabs [ 2 ] ) ;
207
+ expect ( onSelectionChange ) . toHaveBeenCalled ( ) ;
208
+ expect ( getByRole ( 'tabpanel' ) . getAttribute ( 'id' ) ) . toContain ( 'third-element' ) ;
209
+
210
+ } ) ;
211
+
184
212
it ( 'should support orientation' , ( ) => {
185
213
let className = ( { orientation} ) => orientation ;
186
214
let { getByRole} = renderTabs ( { orientation : 'vertical' , className} , { className} ) ;
0 commit comments