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'); 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);