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

Function getRadiosInGroup

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

Source from the content-addressed store, hash-verified

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