* Find the candidates within a spatial navigation container include delegable container. * This function does not search inside delegable container or focusable container. * In other words, this return candidates set is not included focusable elements inside delegable container or focusable co
(container, option = {mode: 'visible'})
| 301 | * @returns {sequence<Node>} candidate elements within the container |
| 302 | */ |
| 303 | function getSpatialNavigationCandidates (container, option = {mode: 'visible'}) { |
| 304 | let candidates = []; |
| 305 | |
| 306 | if (container.childElementCount > 0) { |
| 307 | if (!container.parentElement) { |
| 308 | container = container.getElementsByTagName('body')[0] || document.body; |
| 309 | } |
| 310 | const children = container.children; |
| 311 | for (const elem of children) { |
| 312 | if (isDelegableContainer(elem)) { |
| 313 | candidates.push(elem); |
| 314 | } else if (isFocusable(elem)) { |
| 315 | candidates.push(elem); |
| 316 | |
| 317 | if (!isContainer(elem) && elem.childElementCount) { |
| 318 | candidates = candidates.concat(getSpatialNavigationCandidates(elem, {mode: 'all'})); |
| 319 | } |
| 320 | } else if (elem.childElementCount) { |
| 321 | candidates = candidates.concat(getSpatialNavigationCandidates(elem, {mode: 'all'})); |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | return (option.mode === 'all') ? candidates : candidates.filter(isVisible); |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Find the candidates among focusable elements within a spatial navigation container from the search origin (currently focused element) |
no test coverage detected