From 749319c383ec7fd7f1f7f44ba2eea6416c5042c3 Mon Sep 17 00:00:00 2001 From: AMin Date: Sun, 25 Oct 2026 13:46:24 +0800 Subject: [PATCH 1/2] fix: include links with an empty href in focus list --- src/Dom/focus.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dom/focus.ts b/src/Dom/focus.ts index 556d79ef..ce6fe66b 100644 --- a/src/Dom/focus.ts +++ b/src/Dom/focus.ts @@ -22,7 +22,7 @@ function focusable(node: HTMLElement, includePositive = false): boolean { // Editable element node.isContentEditable || // Anchor with href element - (nodeName === 'a' && !!node.getAttribute('href')); + (nodeName === 'a' && node.hasAttribute('href')); // Get tabIndex const tabIndexAttr = node.getAttribute('tabindex'); From 61b00904d4e0c90411e6758b8fc6ea5ec4a16f94 Mon Sep 17 00:00:00 2001 From: AMin Date: Sun, 25 Oct 2026 13:47:32 +0800 Subject: [PATCH 2/2] test: cover empty href and negative tabindex --- tests/focus.test.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/focus.test.tsx b/tests/focus.test.tsx index 80142537..1dae0e78 100644 --- a/tests/focus.test.tsx +++ b/tests/focus.test.tsx @@ -59,6 +59,25 @@ describe('focus', () => { setSelectionRangeSpy.mockRestore(); }); + it('includes links with an empty href in the focus list', () => { + const container = document.createElement('div'); + container.innerHTML = 'current pageplaceholder'; + document.body.appendChild(container); + const link = container.querySelector('a'); + + try { + link.focus(); + expect(document.activeElement).toBe(link); + expect(getFocusNodeList(container)).toEqual([link]); + + link.tabIndex = -1; + expect(getFocusNodeList(container)).toEqual([]); + expect(getFocusNodeList(container, true)).toEqual([link]); + } finally { + container.remove(); + } + }); + describe('useLockFocus', () => { const TestComponent: React.FC<{ lock: boolean }> = ({ lock }) => { const elementRef = useRef(null);