Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Dom/focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
19 changes: 19 additions & 0 deletions tests/focus.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<a href="">current page</a><a>placeholder</a>';
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<HTMLDivElement>(null);
Expand Down