Skip to content

Commit 01a93c6

Browse files
fix: test
1 parent 041ff8c commit 01a93c6

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

tests/focus.test.tsx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,72 @@ describe('Trigger focus management', () => {
224224
)!;
225225
expect(inner).not.toHaveFocus();
226226
});
227+
228+
it('does not run tab trap when focusPopup is false (handler early return)', async () => {
229+
render(
230+
<Trigger
231+
action="click"
232+
focusPopup={false}
233+
builtinPlacements={placementAlignMap}
234+
popupPlacement="bottom"
235+
popup={
236+
<div>
237+
<button type="button">a</button>
238+
<button type="button">b</button>
239+
</div>
240+
}
241+
>
242+
<button type="button">trigger</button>
243+
</Trigger>,
244+
);
245+
246+
const trigger = document.querySelector('button')!;
247+
act(() => {
248+
fireEvent.click(trigger);
249+
});
250+
await flush();
251+
252+
const popup = document.querySelector('.rc-trigger-popup')!;
253+
expect(popup).toBeTruthy();
254+
255+
const btnA = Array.from(document.querySelectorAll('button')).find(
256+
(b) => b.textContent === 'a',
257+
)!;
258+
const btnB = Array.from(document.querySelectorAll('button')).find(
259+
(b) => b.textContent === 'b',
260+
)!;
261+
act(() => {
262+
btnB.focus();
263+
});
264+
265+
fireEvent.keyDown(popup, { key: 'Tab', shiftKey: false, bubbles: true });
266+
267+
expect(document.activeElement).toBe(btnB);
268+
});
269+
270+
it('enables focus management by default for focus-only trigger', async () => {
271+
render(
272+
<Trigger
273+
action="focus"
274+
builtinPlacements={placementAlignMap}
275+
popupPlacement="bottom"
276+
popup={<button type="button">inner</button>}
277+
>
278+
<button type="button">trigger</button>
279+
</Trigger>,
280+
);
281+
282+
const trigger = document.querySelector('button')!;
283+
284+
act(() => {
285+
fireEvent.focus(trigger);
286+
});
287+
288+
await flush();
289+
290+
const inner = Array.from(document.querySelectorAll('button')).find(
291+
(b) => b.textContent === 'inner',
292+
)!;
293+
expect(document.activeElement).toBe(inner);
294+
});
227295
});

0 commit comments

Comments
 (0)