@@ -557,72 +557,6 @@ this only searches through the visible focusable areas of the nearest
557557<em> If there isn't any, this does not climb further up the ancestry chain,
558558and the result will be <code> null</code> .</em>
559559</div>
560-
561- <div class=example id=delegation>
562- The following code changes the behavior of spatial navigation
563- so that when a scroll container would get focused,
564- if it has at least one visible focusable descendant,
565- the focus is automatically transferred to it,
566- recursively.
567-
568- <pre><code highlight=javascript>
569- document.addEventListener('navbeforefocus' , e => {
570- e.preventDefault();
571-
572- let target = e.relatedTarget;
573- while (target.isSameNode(target.getSpatialNavigationContainer())) {
574- const areas = target.focusableAreas();
575-
576- if (areas.length === 0) { break; }
577-
578- target = target.spatialNavigationSearch(e.dir, { candidates: areas });
579- }
580- target.focus();
581- });
582- </code></pre>
583- </div>
584-
585- <div class=example id=loop>
586- The following code changes the behavior of spatial navigation
587- to trap the focus within a <a>spatial navigation container</a> :
588- when no further focusable elements can be found in the requested direction
589- and the <a>spatial navigation container</a> cannot be scrolled any further,
590- the focus loops back to the other side instead of moving outside of it,
591- either by focusing or scrolling depending on what is available.
592-
593- However, the focus can still be moved outside by sequential navigation,
594- mouse interaction,
595- or programmatic calls to {{focus()}} …
596-
597- <pre><code highlight=javascript>
598- document.addEventListener('navnotarget' , e => {
599- e.preventDefault();
600-
601- const container = e.relatedTarget;
602- const areas = container.focusableAreas({mode: 'all' });
603-
604- if (areas.length === 0) {
605- switch (e.dir) {
606- case 'down' :
607- container.scrollTop = 0;
608- break;
609- case 'up' :
610- container.scrollTop = container.scrollHeight;
611- break;
612- case 'right' :
613- container.scrollLeft = 0;
614- break;
615- case 'left' :
616- container.scrollLeft = container.scrollWidth;
617- break;
618- }
619- } else {
620- const target = container.spatialNavigationSearch(e.dir, { candidates: areas });
621- target.focus();
622- }
623- });
624- </code></pre>
625- </div>
626560</div>
627561
628562<div class=example id=searchInside>
@@ -773,6 +707,30 @@ the <a spec=html for="/">origin</a> of the [=active document=] of the [=top-leve
773707 </table>
774708</div>
775709
710+ <div class=example id=delegation>
711+ The following code changes the behavior of spatial navigation
712+ so that when a scroll container would get focused,
713+ if it has at least one visible focusable descendant,
714+ the focus is automatically transferred to it,
715+ recursively.
716+
717+ <pre><code highlight=javascript>
718+ document.addEventListener('navbeforefocus' , e => {
719+ e.preventDefault();
720+
721+ let target = e.relatedTarget;
722+ if (target.isSameNode(target.getSpatialNavigationContainer())) {
723+ const areas = target.focusableAreas();
724+
725+ if (areas.length === 0) { break; }
726+
727+ target = target.spatialNavigationSearch(e.dir, { candidates: areas });
728+ }
729+ target.focus();
730+ });
731+ </code></pre>
732+ </div>
733+
776734<h4 id="event-type-navnotarget" class="non-normative">
777735<dfn event for=NavigationEvent>navnotarget</dfn></h4>
778736
@@ -921,6 +879,49 @@ the <a spec=html for="/">origin</a> of the [=active document=] of the [=top-leve
921879 </div>
922880 </pre>
923881</div>
882+
883+ <div class=example id=loop>
884+ The following code changes the behavior of spatial navigation
885+ to trap the focus within a <a>spatial navigation container</a> :
886+ when no further focusable elements can be found in the requested direction
887+ and the <a>spatial navigation container</a> cannot be scrolled any further,
888+ the focus loops back to the other side instead of moving outside of it,
889+ either by focusing or scrolling depending on what is available.
890+
891+ However, the focus can still be moved outside by sequential navigation,
892+ mouse interaction,
893+ or programmatic calls to {{focus()}} .
894+
895+ <pre><code highlight=javascript>
896+ document.addEventListener('navnotarget' , e => {
897+ e.preventDefault();
898+
899+ const container = e.relatedTarget;
900+ const areas = container.focusableAreas({ mode: 'all' });
901+
902+ if (areas.length === 0) {
903+ switch (e.dir) {
904+ case 'down' :
905+ container.scrollTop = 0;
906+ break;
907+ case 'up' :
908+ container.scrollTop = container.scrollHeight;
909+ break;
910+ case 'right' :
911+ container.scrollLeft = 0;
912+ break;
913+ case 'left' :
914+ container.scrollLeft = container.scrollWidth;
915+ break;
916+ }
917+ } else {
918+ const target = container.spatialNavigationSearch(e.dir, { candidates: areas });
919+ target.focus();
920+ }
921+ });
922+ </code></pre>
923+ </div>
924+
924925</div>
925926</div>
926927
@@ -970,7 +971,7 @@ to fully define the behavior.
970971Issue(w3c/csswg-drafts#3376): The following currently does not account
971972for <a href="https://github.com/WICG/overscroll-behavior">the proposed overscroll-behavior specification</a> .
972973
973- <h3 id=grouping >
974+ <h3 id=glossary >
974975Glossary</h3>
975976
976977The following term definitions have been specified to explain the processing model for spatial navigation.
0 commit comments