Skip to content

Commit 3b8660e

Browse files
author
Jihye Hong
committed
[css-nav-1] Modify the explanation about focusableAreas
* Modify the method steps of the API * Add an example of the API
1 parent 14ac5bf commit 3b8660e

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

css-nav-1/Overview.bs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,44 @@ The {{Element/getSpatialNavigationContainer()}} method must follow these steps:
483483

484484
<div algorithm="focusableAreas steps">
485485
The {{Element/focusableAreas()}} method must follow these steps:
486-
1. Let <var>v</var> be <code>false</code>
487-
if the argument's {{FocusableAreasOptions/mode}} attribute if present and equal to <code>"all"</code>,
486+
1. Let <var>visibleOnly</var> be <code>false</code>
487+
if the argument's {{FocusableAreasOptions/mode}} attribute is present and equal to <code>'all'</code>,
488488
or <code>true</code> otherwise.
489-
4. Let <var>areas</var> be the result of <a>finding focusable areas</a> within the element with the visibleOnly argument set to <var>v</var>
489+
2. Let <var>areas</var> be the result of <a>finding focusable areas</a> within the element with the <var>visibleOnly</var> argument.
490+
3. Loop: If there is a <a>spatial navigation container</a> <var>container</var> among <var>areas</var>,
491+
then add the result of <a>finding focusable areas</a> to <var>areas</var> within the <var>container</var>.
490492
5. Let <var>anchors</var> be a <a for=list>clone</a> of <var>areas</var>,
491493
with every <a>focusable area</a> which is not itself a <a>Node</a> replaced with its <a>DOM anchor</a>.
492494
6. Return <var>anchors</var>
495+
</div>
496+
497+
<div class=example id=focusAreas-visible>
498+
The following code shows how to get all the visible focusable elements in the current page using {{Element/focusableAreas()}}.
499+
If the method finds a <a>spatial navigation container</a>, it recursively finds focusable areas inside it.
500+
However, <code>'visible'</code> is given to the {{FocusableAreasOptions/mode}} attribute of this method,
501+
the focusable element which isn’t inside the <a>scrollport</a> is excluded from the result.
493502

503+
<pre><code highlight=markup>
504+
&lt;body>
505+
&lt;button class="box" style="top:100px; left:20px;">&lt;/button>
506+
&lt;div class="container" style="left:110px; width:300px; height:200px; overflow-x: scroll;">
507+
&lt;button class="box" style="top:78px; left:25px;">&lt;/button>
508+
&lt;button class="box" style="top: 80px; left:150px;">&lt;/button>
509+
&lt;button class="box" style="top: 80px; left:350px;">&lt;/button>
510+
&lt;/div>
511+
&lt;/body>
512+
</code></pre>
513+
<pre><code highlight=javascript>
514+
const focusableAreas = document.body.focusableAreas({'mode': 'visible'});
515+
focusableAreas && focusableAreas.forEach(focusable => {
516+
focusable.style.outline = '5px solid red';
517+
});
518+
</code></pre>
519+
The figure below is the result of this code.
520+
<figure>
521+
<img alt="An image about focusableAreas()" src="images/focusableareas-visible-example.png" style="width: 450px;"/>
522+
<figcaption>Find all visible focusable areas inside the document.</figcaption>
523+
</figure>
494524
</div>
495525

496526
<div algorithm="spatialNavigationSearch steps">
@@ -863,11 +893,11 @@ and it cannot be scrolled at the same time.
863893
For the sake of keeping the description simple,
864894
this example assumes a UA where spatial navigation is triggered using arrow keys.
865895

866-
<figure>
867-
<img alt="An image about navnotarget" src="images/navnotarget-example-1.png" style="width: 200px;"/>
868-
<figcaption>Moving focus when there isn't any candidate in the
869-
<a>scroll container</a>.</figcaption>
870-
</figure>
896+
<figure>
897+
<img alt="An image about navnotarget" src="images/navnotarget-example-1.png" style="width: 200px;"/>
898+
<figcaption>Moving focus when there isn't any candidate in the
899+
<a>scroll container</a>.</figcaption>
900+
</figure>
871901

872902
<table class="complex data">
873903
<thead>
5.55 KB
Loading

0 commit comments

Comments
 (0)