Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit 9090fa5

Browse files
josephlicciniCaerusKaru
authored andcommitted
fix(EventRecorder): maintain focus for nodes besides input and t… (#106)
In this change, the activeNode in Preboot is set for any focus event, not just those in `<input>` or `<textarea>`. This helps those who use screenreaders maintain focus during the swap between server and client views. Closes #105
1 parent edcb528 commit 9090fa5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/lib/api/event.recorder.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,16 @@ export function createListenHandler(
253253
// get the node key for a given node
254254
const nodeKey = getNodeKeyForPreboot({ root: root, node: node });
255255

256-
// if event on input or text area, record active node
257-
if (CARET_EVENTS.indexOf(eventName) >= 0 &&
258-
CARET_NODES.indexOf(node.tagName ? node.tagName : '') >= 0) {
256+
// record active node
257+
if (CARET_EVENTS.indexOf(eventName) >= 0) {
258+
// if it's an caret node, get the selection for the active node
259+
const isCaretNode = CARET_NODES.indexOf(node.tagName ? node.tagName : '') >= 0;
260+
259261
prebootData.activeNode = {
260262
root: root,
261263
node: node,
262264
nodeKey: nodeKey,
263-
selection: getSelection(node as HTMLInputElement)
265+
selection: isCaretNode ? getSelection(node as HTMLInputElement) : undefined
264266
};
265267
} else if (eventName !== 'change' && eventName !== 'focusout') {
266268
prebootData.activeNode = undefined;

0 commit comments

Comments
 (0)