Skip to content

Commit ba610cf

Browse files
author
Jihye Hong
committed
Refine the spec
* Modify the code example * Modify for the clear description
1 parent 921ef44 commit ba610cf

1 file changed

Lines changed: 37 additions & 43 deletions

File tree

css-nav-1/Overview.bs

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ even if the author has not invoked any of the APIs.
327327
Regardless of the actual mechanism chosen to trigger spatial navigation,
328328
the following requirements apply:
329329
* If the mechanism the user must use to trigger spatial navigation
330-
would normally fire a {{UIEvent}},
331-
then that event must be fired prior to running the <a>spatial navigation steps</a>
330+
would normally fire a {{UIEvent}}.
331+
The event must be fired prior to running the <a>spatial navigation steps</a>
332332
and these steps must not be run if that event's <a>canceled flag</a>
333333
gets set.
334334

@@ -348,8 +348,8 @@ the following requirements apply:
348348
would follow the same sequence.
349349
</div>
350350
* If the mechanism the user must use to trigger spatial navigation
351-
would in some contexts trigger other actions,
352-
the User Agent should in these contexts
351+
would trigger other actions in some contexts.
352+
The User Agent should in these contexts
353353
give priority to these other actions
354354
and execute them instead of spatial navigation.
355355
It must not trigger both.
@@ -403,12 +403,12 @@ the same chain of events will be fired and
403403
the same element will be scrolled or focused.
404404

405405
Note: Authors can use this to trigger spatial navigation
406-
based on a different UI mechanism than the one assigned by the User Agent,
407-
such as mapping to different keys,
408-
or triggering spatial navigation from a clickable on-screen directional pad.
406+
based on a different UI mechanism than the one assigned by the User Agent.
407+
Such as mapping to different keys,
408+
or triggering spatial navigation from a clickable on-screen directional pad,
409409
or in reaction to other events than UI ones.
410410
It could also be used when an author wants to interrupt navigation to do some asynchronous operation
411-
(e.g. load more content in an infinite scroller) then resume where they cancelled.
411+
(e.g. load more content in an infinite scroller) then resume the navigation where they cancelled.
412412

413413
Note: This API is also useful for testing purposes,
414414
as there is no other way to trigger spatial navigation
@@ -486,11 +486,9 @@ The {{Element/focusableAreas()}} method must follow these steps:
486486
if the argument's {{FocusableAreasOptions/mode}} attribute is present and equal to <code>'all'</code>,
487487
or <code>true</code> otherwise.
488488
2. Let <var>areas</var> be the result of <a>finding focusable areas</a> within the element with the <var>visibleOnly</var> argument.
489-
3. Loop: If there is a <a>spatial navigation container</a> <var>container</var> among <var>areas</var>,
490-
then add the result of <a>finding focusable areas</a> to <var>areas</var> within the <var>container</var>.
491-
5. Let <var>anchors</var> be a <a for=list>clone</a> of <var>areas</var>,
489+
3. Let <var>anchors</var> be a <a for=list>clone</a> of <var>areas</var>,
492490
with every <a>focusable area</a> which is not itself a <a>Node</a> replaced with its <a>DOM anchor</a>.
493-
6. Return <var>anchors</var>
491+
4. Return <var>anchors</var>
494492
</div>
495493

496494
<div class=example id=focusAreas-visible>
@@ -530,12 +528,12 @@ The {{Element/spatialNavigationSearch()}} method must follow these steps:
530528
else, let <var>areas</var> be the result of <a>finding focusable areas</a>
531529
within the argument's {{SpatialNavigationSearchOptions/container}} attribute is not <code>null</code>,
532530
or the element's nearest <a>spatial navigation container</a> ancestor
533-
4. Return the result of <a>selecting the best candidate</a> within <var>areas</var> in direction <var>d</var> from the element
531+
3. Return the result of <a>selecting the best candidate</a> within <var>areas</var> in direction <var>d</var> from the element
534532

535533
Note: When neither a container nor a list of candidates is provided,
536534
this only searches through the visible focusable areas of the nearest
537535
<a>spatial navigation container</a> ancestor.
538-
<strong>If none are found, this does not climb further up the ancestry chain,
536+
<strong>If there isn't any eligible element to navigate, this does not climb further up the ancestry chain,
539537
and the result will be <code>null</code>.</strong>
540538
</div>
541539

@@ -546,20 +544,16 @@ and the result will be <code>null</code>.</strong>
546544
the focus is automatically transferred to it.
547545

548546
<pre><code highlight=javascript>
549-
document.addEventListener("navbeforefocus", function(e) {
547+
document.addEventListener('navbeforefocus', function(e) {
550548
e.preventDefault();
551549

552-
if (e.dir === "forward" || e.dir === "backward") {
553-
e.dir = "top";
554-
}
555-
556-
var t = e.relatedTarget;
557-
while (t.isSameNode(t.getSpatialNavigationContainer())) {
558-
var areas = t.focusableAreas();
550+
let target = e.relatedTarget;
551+
while (target.isSameNode(target.getSpatialNavigationContainer())) {
552+
const areas = target.focusableAreas();
559553

560554
if (areas.length === 0) { break; }
561555

562-
t = t.spatialNavigationSearch({
556+
target = target.spatialNavigationSearch({
563557
dir: e.dir,
564558
candidates: areas
565559
});
@@ -571,44 +565,45 @@ and the result will be <code>null</code>.</strong>
571565

572566
<div class=example id=loop>
573567
The following code changes the behavior of spatial navigation
574-
to trap the focus within a spatial navigation container:
568+
to trap the focus within a <a>spatial navigation container</a>:
575569
when no further focusable elements can be found in the requested direction
576-
and the spatial navigation container cannot be scrolled any futher,
577-
we loop back to the other side instead of searching outside of it,
570+
and the <a>spatial navigation container</a> cannot be scrolled any further,
571+
the focus loops back to the other side instead of moving outside of it,
578572
either by focusing or scrolling depending on what is available.
579573

580-
The focus can still be moved outside by sequential navigation,
574+
However, the focus can still be moved outside by sequential navigation,
581575
mouse interaction,
582-
programmatic calls to {{focus()}}
576+
and programmatic calls to {{focus()}}
583577

584578
<pre><code highlight=javascript>
585-
document.addEventListener("navnotarget", function(e) {
579+
document.addEventListener('navnotarget', function(e) {
586580
e.preventDefault();
587581

588-
var c = e.relatedTarget;
589-
var areas = c.focusableAreas({mode: "all"});
582+
const container = e.relatedTarget;
583+
const areas = container.focusableAreas({mode: 'all'});
590584

591585
if (areas.length === 0) {
592586
switch (e.dir) {
593-
case "down":
594-
c.scrollTop = 0;
587+
case 'down':
588+
container.scrollTop = 0;
595589
break;
596-
case "up":
597-
c.scrollTop = c.scrollHeight;
590+
case 'up':
591+
container.scrollTop = container.scrollHeight;
598592
break;
599-
case "right":
600-
c.scrollLeft = 0;
593+
case 'right':
594+
container.scrollLeft = 0;
601595
break;
602-
case "left":
603-
c.scrollLeft = c.scrollWidth;
596+
case 'left':
597+
container.scrollLeft = container.scrollWidth;
604598
break;
605599
}
606600
} else {
607-
var t = c.spatialNavigationSearch({
601+
const target = container.spatialNavigationSearch({
608602
dir: e.dir,
609603
candidates: areas
610604
});
611-
t.focus();
605+
target.focus();
606+
}
612607
});
613608
</code></pre>
614609
</div>
@@ -922,7 +917,7 @@ if a suitable one cannot be found inside it (see [[#nav]] for details).
922917

923918
Such groupings are called <dfn lt="spatial navigation focus container | spatial navigation focus containers | spatial navigation container | spatial navigation containers">spatial navigation focus containers</dfn>.
924919

925-
<span class=cssapi>By default, </span><a>spatial navigation containers</a> are established by:
920+
<span class=cssapi>By default, </span><a>spatial navigation containers</a>(same with spatial navigation focus container) are established by:
926921
* The viewport of a <a for="/">browsing context</a>
927922
(not limited to the <a>top-level browsing context</a>)
928923

@@ -1476,6 +1471,5 @@ The editors of this specification would like to thank the following individuals
14761471
* Hyojin Song
14771472
* Jeonghee Ahn
14781473
* Junho Seo
1479-
14801474
* Rob Dodson
14811475
* Seungcheon Baek

0 commit comments

Comments
 (0)