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

Function getRadiosInGroup

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

Source from the content-addressed store, hash-verified

317}
318
319function getRadiosInGroup(element: HTMLInputElement): HTMLInputElement[] {
320 if (!element.form) {
321 // Radio buttons outside a form - query the document
322 return Array.from(
323 getOwnerDocument(element).querySelectorAll<HTMLInputElement>(
324 `input[type="radio"][name="${CSS.escape(element.name)}"]`
325 )
326 ).filter(radio => !radio.form);
327 }
328
329 // namedItem returns RadioNodeList (iterable) for 2+ elements, but a single Element for exactly 1.
330 // https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormControlsCollection/namedItem
331 const radioList = element.form.elements.namedItem(element.name);
332 let ownerWindow = getOwnerWindow(element);
333 if (radioList instanceof ownerWindow.RadioNodeList) {
334 return Array.from(radioList).filter(
335 (el): el is HTMLInputElement => el instanceof ownerWindow.HTMLInputElement
336 );
337 }
338 if (radioList instanceof ownerWindow.HTMLInputElement) {
339 return [radioList];
340 }
341 return [];
342}
343
344function isTabbableRadio(element: HTMLInputElement): boolean {
345 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