diff --git a/src/internal/single-tab-stop/__tests__/context.test.tsx b/src/internal/single-tab-stop/__tests__/context.test.tsx
index abacf2b..0ba4eb6 100644
--- a/src/internal/single-tab-stop/__tests__/context.test.tsx
+++ b/src/internal/single-tab-stop/__tests__/context.test.tsx
@@ -64,15 +64,6 @@ test('does not override tab index when keyboard navigation is not active', () =>
expect(document.querySelector('#button')).not.toHaveAttribute('tabIndex');
});
-test('(legacy coverage) does not override tab index when keyboard navigation is not active', () => {
- render(
-
-
-
- );
- expect(document.querySelector('#button')).not.toHaveAttribute('tabIndex');
-});
-
test('does not override tab index for suppressed elements', () => {
render(
@@ -107,18 +98,6 @@ test('overrides tab index when keyboard navigation is active', () => {
expect(document.querySelector('#button2')).toHaveAttribute('tabIndex', '-1');
});
-test('(legacy coverage) overrides tab index when keyboard navigation is active', () => {
- render(
-
-
-
-
- );
- setTestSingleTabStopNavigationTarget(document.querySelector('#button1'));
- expect(document.querySelector('#button1')).toHaveAttribute('tabIndex', '0');
- expect(document.querySelector('#button2')).toHaveAttribute('tabIndex', '-1');
-});
-
test('does not override explicit tab index with 0', () => {
render(
diff --git a/src/internal/single-tab-stop/test-helpers/index.tsx b/src/internal/single-tab-stop/test-helpers/index.tsx
index 1b8cd00..046be03 100644
--- a/src/internal/single-tab-stop/test-helpers/index.tsx
+++ b/src/internal/single-tab-stop/test-helpers/index.tsx
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
-import React, { forwardRef, useCallback, useEffect, useRef } from 'react';
+import React, { useCallback, useEffect, useRef } from 'react';
import { FocusableChangeHandler, SingleTabStopNavigationContext } from '../';
import { useUniqueId } from '../../use-unique-id';
@@ -14,44 +14,55 @@ interface TestProviderAPI {
const providerRegistry = new Map();
-export const TestSingleTabStopNavigationProvider = forwardRef(
- ({ children, navigationActive }: { children: React.ReactNode; navigationActive: boolean }) => {
- const focusablesRef = useRef(new Set());
- const focusHandlersRef = useRef(new Map());
- const registerFocusable = useCallback((focusable: HTMLElement, changeHandler: FocusableChangeHandler) => {
- focusablesRef.current.add(focusable);
- focusHandlersRef.current.set(focusable, changeHandler);
- return () => {
- focusablesRef.current.delete(focusable);
- focusHandlersRef.current.delete(focusable);
- };
- }, []);
-
- const providerId = useUniqueId();
- providerRegistry.set(providerId, {
- setCurrentTarget: (focusTarget, suppressed = []) => {
- focusablesRef.current.forEach(focusable => {
- const handler = focusHandlersRef.current.get(focusable)!;
- handler(focusTarget === focusable || suppressed.includes(focusable));
- });
- },
- });
- useEffect(
- () => () => {
- providerRegistry.delete(providerId);
- },
- [providerId]
- );
-
- return (
- {} }}
- >
- {children}
-
- );
- }
-);
+export const TestSingleTabStopNavigationProvider = ({
+ children,
+ navigationActive,
+}: {
+ children: React.ReactNode;
+ navigationActive: boolean;
+}) => {
+ const focusablesRef = useRef(new Set());
+ const focusHandlersRef = useRef(new Map());
+ const registerFocusable = useCallback((focusable: HTMLElement, changeHandler: FocusableChangeHandler) => {
+ focusablesRef.current.add(focusable);
+ focusHandlersRef.current.set(focusable, changeHandler);
+ return () => {
+ focusablesRef.current.delete(focusable);
+ focusHandlersRef.current.delete(focusable);
+ };
+ }, []);
+
+ const providerId = useUniqueId();
+ providerRegistry.set(providerId, {
+ setCurrentTarget: (focusTarget, suppressed = []) => {
+ focusablesRef.current.forEach(focusable => {
+ const handler = focusHandlersRef.current.get(focusable)!;
+ handler(focusTarget === focusable || suppressed.includes(focusable));
+ });
+ },
+ });
+ useEffect(
+ () => () => {
+ providerRegistry.delete(providerId);
+ },
+ [providerId]
+ );
+
+ return (
+ {},
+ }}
+ >
+ {children}
+
+ );
+};
export const setTestSingleTabStopNavigationTarget: SetTarget = (focusTarget, suppressed) => {
Array.from(providerRegistry).forEach(([, provider]) => provider.setCurrentTarget(focusTarget, suppressed));