Skip to content

Commit acaa7d3

Browse files
author
Jihye Hong
authored
Merge pull request #3762 from jihyerish/master
[css-nav-1] Modify the explanation about focusableAreas
2 parents 75eb1a6 + 3b8660e commit acaa7d3

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

css-nav-1/Overview.bs

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ the specification remains the full document.
8888

8989
<input type=checkbox id=api-check> <label for=api-check>Hide JavaScript APIs, including events</label><br>
9090
<input type=checkbox id=cssapi-check> <label for=cssapi-check>Hide CSS properties that enable selecting behavior variants, and related information</label><br>
91-
<input type=checkbox id=verbose-check> <label for=verbose-check>Hide informative sections that explain and summarise normative sections without adding more information</label><br>
91+
<input type=checkbox id=verbose-check> <label for=verbose-check>Hide informative sections that explain and summarize normative sections without adding more information</label><br>
9292

9393
<h2 id="intro" class=non-normative>
9494
Introduction</h2>
@@ -209,7 +209,7 @@ until it has either moved focus,
209209
scrolled,
210210
or reached the root.
211211

212-
Note: As a consequnce of this processing model,
212+
Note: As a consequence of this processing model,
213213
the elements that are reachable by sequential navigation
214214
and by spatial navigation are almost the same:
215215
elements that are currently outside of the viewport of a scrollable element
@@ -394,7 +394,7 @@ JavaScript API</h2>
394394
<h3 id=high-level-api>
395395
Triggering Navigation Programmatically</h3>
396396

397-
The {{Window/navigate()}} method enables the author to trigger spatial navigation programatically,
397+
The {{Window/navigate()}} method enables the author to trigger spatial navigation programmatically,
398398
as if the user had done so manually
399399
(for instance, by pressing the arrow keys in a browser where that is the way to trigger spatial navigation).
400400

@@ -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">
@@ -537,7 +567,7 @@ and the result will be <code>null</code>.</strong>
537567
The following code changes the behavior of spatial navigation
538568
so that when a scroll container would get focused,
539569
if it has at least one visible focusable descendant,
540-
the focus is automatically transfered to it.
570+
the focus is automatically transferred to it.
541571

542572
<pre><code highlight=javascript>
543573
document.addEventListener("navbeforefocus", function(e) {
@@ -566,14 +596,14 @@ and the result will be <code>null</code>.</strong>
566596
<div class=example id=loop>
567597
The following code changes the behavior of spatial navigation
568598
to trap the focus within a spatial navigation container:
569-
when no further focusable elements can be found in the requested direcition
599+
when no further focusable elements can be found in the requested direction
570600
and the spatial navigation container cannot be scrolled any futher,
571601
we loop back to the other side instead of searching outside of it,
572602
either by focusing or scrolling depending on what is available.
573603

574604
The focus can still be moved outside by sequential navigation,
575605
mouse interaction,
576-
programatic calls to {{focus()}}
606+
programmatic calls to {{focus()}}
577607

578608
<pre><code highlight=javascript>
579609
document.addEventListener("navnotarget", function(e) {
@@ -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>
@@ -983,15 +1013,14 @@ The <a>navigation-override</a> [=policy-controlled feature=]</h2>
9831013
We recognize that there exists other mechanisms predating spatial navigation
9841014
that malicious authors could use
9851015
to interfere with the user's ability to control where the focus goes.
986-
Despite that, it seems worthwile to attempt not to increase this attack surface,
1016+
Despite that, it seems worthwhile to attempt not to increase this attack surface,
9871017
although it is possible that such attacks are already sufficiently easy to perform
9881018
that this is a lost cause.
9891019
Further feedback on this topic,
9901020
based on experience with implementation or with mitigating such attacks,
9911021
is very welcome.
9921022

9931023

994-
9951024
<h2 id=processing-model>
9961025
Processing Model</h2>
9971026

5.55 KB
Loading

0 commit comments

Comments
 (0)