|
3 | 3 | import React, { useState } from 'react'; |
4 | 4 | import { render } from '@testing-library/react'; |
5 | 5 |
|
6 | | -import { renderWithSingleTabStopNavigation } from '@cloudscape-design/component-toolkit/internal/testing'; |
| 6 | +import { |
| 7 | + setTestSingleTabStopNavigationTarget, |
| 8 | + TestSingleTabStopNavigationProvider, |
| 9 | +} from '@cloudscape-design/component-toolkit/internal/testing'; |
7 | 10 |
|
8 | 11 | import Checkbox, { CheckboxProps } from '../../../lib/components/checkbox'; |
9 | 12 | import InternalCheckbox from '../../../lib/components/checkbox/internal'; |
@@ -243,30 +246,34 @@ describe('table grid navigation support', () => { |
243 | 246 | } |
244 | 247 |
|
245 | 248 | test('does not override tab index when keyboard navigation is not active', () => { |
246 | | - renderWithSingleTabStopNavigation(<Checkbox id="checkbox" checked={false} />, { navigationActive: false }); |
| 249 | + render( |
| 250 | + <TestSingleTabStopNavigationProvider navigationActive={false}> |
| 251 | + <Checkbox id="checkbox" checked={false} /> |
| 252 | + </TestSingleTabStopNavigationProvider> |
| 253 | + ); |
247 | 254 | expect(getCheckboxInput('#checkbox')).not.toHaveAttribute('tabIndex'); |
248 | 255 | }); |
249 | 256 |
|
250 | 257 | test('overrides tab index when keyboard navigation is active', () => { |
251 | | - const { setCurrentTarget } = renderWithSingleTabStopNavigation( |
252 | | - <div> |
| 258 | + render( |
| 259 | + <TestSingleTabStopNavigationProvider navigationActive={true}> |
253 | 260 | <Checkbox id="checkbox1" checked={false} /> |
254 | 261 | <Checkbox id="checkbox2" checked={false} /> |
255 | | - </div> |
| 262 | + </TestSingleTabStopNavigationProvider> |
256 | 263 | ); |
257 | | - setCurrentTarget(getCheckboxInput('#checkbox1')); |
| 264 | + setTestSingleTabStopNavigationTarget(getCheckboxInput('#checkbox1')); |
258 | 265 | expect(getCheckboxInput('#checkbox1')).toHaveAttribute('tabIndex', '0'); |
259 | 266 | expect(getCheckboxInput('#checkbox2')).toHaveAttribute('tabIndex', '-1'); |
260 | 267 | }); |
261 | 268 |
|
262 | 269 | test('does not override explicit tab index with 0', () => { |
263 | | - const { setCurrentTarget } = renderWithSingleTabStopNavigation( |
264 | | - <div> |
| 270 | + render( |
| 271 | + <TestSingleTabStopNavigationProvider navigationActive={true}> |
265 | 272 | <InternalCheckbox id="checkbox1" checked={false} tabIndex={-1} /> |
266 | 273 | <InternalCheckbox id="checkbox2" checked={false} tabIndex={-1} /> |
267 | | - </div> |
| 274 | + </TestSingleTabStopNavigationProvider> |
268 | 275 | ); |
269 | | - setCurrentTarget(getCheckboxInput('#checkbox1')); |
| 276 | + setTestSingleTabStopNavigationTarget(getCheckboxInput('#checkbox1')); |
270 | 277 | expect(getCheckboxInput('#checkbox1')).toHaveAttribute('tabIndex', '-1'); |
271 | 278 | expect(getCheckboxInput('#checkbox2')).toHaveAttribute('tabIndex', '-1'); |
272 | 279 | }); |
|
0 commit comments