MCPcopy Create free account
hub / github.com/adobe/react-spectrum / getNextElement

Function getNextElement

packages/react-aria/src/radio/useRadioGroup.ts:93–120  ·  view source on GitHub ↗
(nextDir: 'next' | 'prev', e)

Source from the content-addressed store, hash-verified

91 });
92
93 function getNextElement(nextDir: 'next' | 'prev', e) {
94 let walker = getFocusableTreeWalker(e.currentTarget, {
95 from: getEventTarget(e) as Element,
96 accept: node => node instanceof getOwnerWindow(node).HTMLInputElement && node.type === 'radio'
97 });
98 let nextElem;
99 if (nextDir === 'next') {
100 nextElem = walker.nextNode();
101 if (!nextElem) {
102 walker.currentNode = e.currentTarget;
103 nextElem = walker.firstChild();
104 }
105 } else {
106 nextElem = walker.previousNode();
107 if (!nextElem) {
108 walker.currentNode = e.currentTarget;
109 nextElem = walker.lastChild();
110 }
111 }
112
113 if (nextElem) {
114 // Call focus on nextElem so that keyboard navigation scrolls the radio into view
115 nextElem.focus();
116 state.setSelectedValue(nextElem.value);
117 return true;
118 }
119 return false;
120 }
121
122 let {keyboardProps} = useKeyboard({
123 shortcuts: {

Callers 1

useRadioGroupFunction · 0.85

Calls 9

getFocusableTreeWalkerFunction · 0.90
getEventTargetFunction · 0.90
getOwnerWindowFunction · 0.90
nextNodeMethod · 0.80
previousNodeMethod · 0.80
focusMethod · 0.80
setSelectedValueMethod · 0.80
firstChildMethod · 0.45
lastChildMethod · 0.45

Tested by

no test coverage detected