Skip to content

Commit d73787b

Browse files
zombieJclaude
andcommitted
test: add test for ignoreElement functionality
Add a simple test to verify that ignoreElement allows focus on ignored elements outside the locked area. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2155804 commit d73787b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/focus.test.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,39 @@ describe('focus', () => {
9696
expect(document.activeElement).toBe(input1);
9797
});
9898
});
99+
100+
it('ignoreElement should allow focus on ignored elements', () => {
101+
let capturedIgnoreElement: ((ele: HTMLElement) => void) | null = null;
102+
103+
const TestComponent: React.FC = () => {
104+
const elementRef = useRef<HTMLDivElement>(null);
105+
const [ignoreElement] = useLockFocus(true, () => elementRef.current);
106+
107+
if (ignoreElement && !capturedIgnoreElement) {
108+
capturedIgnoreElement = ignoreElement;
109+
}
110+
111+
return (
112+
<>
113+
<button data-testid="ignored-button">Ignored</button>
114+
<div ref={elementRef} data-testid="focus-container" tabIndex={0}>
115+
<input key="input1" data-testid="input1" />
116+
</div>
117+
</>
118+
);
119+
};
120+
121+
const { getByTestId } = render(<TestComponent />);
122+
123+
const ignoredButton = getByTestId('ignored-button');
124+
125+
// Mark the button as ignored
126+
if (capturedIgnoreElement) {
127+
capturedIgnoreElement(ignoredButton);
128+
}
129+
130+
// Focus should be allowed on the ignored button
131+
ignoredButton.focus();
132+
expect(document.activeElement).toBe(ignoredButton);
133+
});
99134
});

0 commit comments

Comments
 (0)