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

Function getRadiosInGroup

packages/react-aria/src/focus/FocusScope.tsx:302–325  ·  view source on GitHub ↗
(element: HTMLInputElement)

Source from the content-addressed store, hash-verified

300}
301
302function getRadiosInGroup(element: HTMLInputElement): HTMLInputElement[] {
303 if (!element.form) {
304 // Radio buttons outside a form - query the document
305 return Array.from(
306 getOwnerDocument(element).querySelectorAll<HTMLInputElement>(
307 `input[type="radio"][name="${CSS.escape(element.name)}"]`
308 )
309 ).filter(radio => !radio.form);
310 }
311
312 // namedItem returns RadioNodeList (iterable) for 2+ elements, but a single Element for exactly 1.
313 // https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormControlsCollection/namedItem
314 const radioList = element.form.elements.namedItem(element.name);
315 let ownerWindow = getOwnerWindow(element);
316 if (radioList instanceof ownerWindow.RadioNodeList) {
317 return Array.from(radioList).filter(
318 (el): el is HTMLInputElement => el instanceof ownerWindow.HTMLInputElement
319 );
320 }
321 if (radioList instanceof ownerWindow.HTMLInputElement) {
322 return [radioList];
323 }
324 return [];
325}
326
327function isTabbableRadio(element: HTMLInputElement): boolean {
328 if (element.checked) {

Callers 1

isTabbableRadioFunction · 0.85

Calls 3

getOwnerDocumentFunction · 0.90
getOwnerWindowFunction · 0.90
filterMethod · 0.65

Tested by

no test coverage detected