Skip to content

Commit e69f234

Browse files
author
Jihye Hong
authored
Merge pull request w3c#4377 from jihyerish/modify-spatnavsearch
[css-nav-1] Modify spatialNavigationSearch API with `inside` attribute
2 parents 1f8d5b0 + ee70dd8 commit e69f234

File tree

1 file changed

+49
-24
lines changed

1 file changed

+49
-24
lines changed

css-nav-1/Overview.bs

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -535,19 +535,20 @@ the User Agent must run the steps described below:
535535
</div>
536536

537537
<div algorithm="spatialNavigationSearch steps">
538-
: <dfn method for=Element lt="spatialNavigationSearch(options)">spatialNavigationSearch(<var>options</var>)</dfn>
538+
: <dfn method for=Element lt="spatialNavigationSearch(options)">spatialNavigationSearch(<var>dir</var>, <var>options</var>)</dfn>
539539
::
540-
1. Let <var>direction</var> be the value of {{SpatialNavigationSearchOptions/dir}} attribute of <var>options</var>.
541-
2.
542-
* If the value of {{SpatialNavigationSearchOptions/candidates}} attribute of <var>options</var> is not <code>null</code>,
543-
then let <var>areas</var> be the that value
544-
* else,
545-
1.
546-
* If the value of {{SpatialNavigationSearchOptions/container}} attribute of <var>options</var> is not <code>null</code>,
547-
let <var>container</var> be that value
548-
* else, let <var>container</var> be the element's nearest <a>spatial navigation container</a> ancestor.
549-
2. Let <var>areas</var> be the result of <a>finding focusable areas</a> within <var>container</var>.
550-
3. Return the result of <a>selecting the best candidate</a> within <var>areas</var> in direction <var>direction</var> from the element.
540+
1. Let <var>direction</var> be the value of <var>dir</var>.
541+
2. Let <var>container</var> be the the value of {{SpatialNavigationSearchOptions/container}} attribute of <var>options</var>
542+
if it is not <code>null</code>, the element's nearest <a>spatial navigation container</a> ancestor otherwise.
543+
3. Let <var>areas</var> be the value of {{SpatialNavigationSearchOptions/candidates}} attribute of <var>options</var>
544+
if it is not <code>null</code>, result of <a>finding focusable areas</a> within <var>container</var> otherwise.
545+
4. Let <var>insideFirst</var> be the value of {{SpatialNavigationSearchOptions/inside}} attribute of <var>options</var>
546+
if it is not <code>null</code>, <code>false</code> otherwise.
547+
5. If <var>insideFirst</var> is <code>true</code>,
548+
then let <var>bestCandidate</var> be the result of <a>selecting the best candidate</a> within element with <var>direction</var>.
549+
* If <var>bestCandidate</var> is not <code>null</code>, return <var>bestCandidate</var>.
550+
* Else, fall back to the next step.
551+
6. Return the result of <a>selecting the best candidate</a> within <var>areas</var> in <var>direction</var> from the element.
551552

552553
Note: When neither a container nor a list of candidates is provided,
553554
this only searches through the visible focusable areas of the nearest
@@ -564,7 +565,7 @@ and the result will be <code>null</code>.</em>
564565
recursively.
565566

566567
<pre><code highlight=javascript>
567-
document.addEventListener('navbeforefocus', function(e) {
568+
document.addEventListener('navbeforefocus', e => {
568569
e.preventDefault();
569570

570571
let target = e.relatedTarget;
@@ -573,10 +574,7 @@ and the result will be <code>null</code>.</em>
573574

574575
if (areas.length === 0) { break; }
575576

576-
target = target.spatialNavigationSearch({
577-
dir: e.dir,
578-
candidates: areas
579-
});
577+
target = target.spatialNavigationSearch(e.dir, { candidates: areas });
580578
}
581579
target.focus();
582580
});
@@ -596,7 +594,7 @@ and the result will be <code>null</code>.</em>
596594
or programmatic calls to {{focus()}}
597595

598596
<pre><code highlight=javascript>
599-
document.addEventListener('navnotarget', function(e) {
597+
document.addEventListener('navnotarget', e => {
600598
e.preventDefault();
601599

602600
const container = e.relatedTarget;
@@ -618,17 +616,44 @@ and the result will be <code>null</code>.</em>
618616
break;
619617
}
620618
} else {
621-
const target = container.spatialNavigationSearch({
622-
dir: e.dir,
623-
candidates: areas
624-
});
619+
const target = container.spatialNavigationSearch(e.dir, { candidates: areas });
625620
target.focus();
626621
}
627622
});
628623
</code></pre>
629624
</div>
630625
</div>
631626

627+
<div class=example id=searchInside>
628+
This example shows different results of {{Element/spatialNavigationSearch()}}
629+
depending on the value of {{SpatialNavigationSearchOptions/inside}} attribute.
630+
631+
When the page has the code snippet as below,
632+
633+
<pre><code highlight=markup>
634+
&lt;body>
635+
&lt;div id="container" style="width:300px; height:200px; overflow-y: scroll;">
636+
&lt;button id="button1" style = "width:50px; height:50px;">&lt;/button>
637+
&lt;/div>
638+
&lt;button id="button2" style = "width:50px; height:50px;">&lt;/button>
639+
&lt;/body>
640+
</code></pre>
641+
642+
<pre><code highlight=javascript>
643+
const container = document.getElementById('container');
644+
645+
const innerBtn = container.spatialNavigationSearch('down', {inside: true});
646+
const outerBtn = container.spatialNavigationSearch('down');
647+
</code></pre>
648+
649+
<code>innerBtn</code> is assigned to the element whose {{Element/id}} matches with <code>'button1'</code>
650+
because the {{SpatialNavigationSearchOptions/inside}} attribute is <code>true</code>.
651+
But if the authors don't specify {{SpatialNavigationSearchOptions/inside}} attribute,
652+
<code>false</code> is given to it by default.
653+
Therefore <code>outerBtn</code> is assigned to the element with {{Element/id}} <code>'button2'</code>
654+
which is outside of <code>container</code>.
655+
</div>
656+
632657
<div class=api>
633658
<h2 id="events-navigationevent">
634659
Navigation Events</h2>
@@ -998,8 +1023,8 @@ To run the <dfn>spatial navigation steps</dfn> in <var>direction</var>, do the f
9981023
<span class=cssapi>* Else if the computed value of the 'spatial-navigation-action' property on <var>eventTarget</var> is not ''spatial-navigation-action/focus''
9991024
and <var>eventTarget</var> <a>can be manually scrolled</a>,
10001025
then <a>directionally scroll the element</a> <var>eventTarget</var> in <var>direction</var> and return.</span>
1001-
* Else, fallback to the next step.
1002-
* Else, fallback to the next step.
1026+
* Else, fall back to the next step.
1027+
* Else, fall back to the next step.
10031028
5. Let <var>container</var> be the nearest ancestor of <var>eventTarget</var> that is a <a>spatial navigation container</a>.
10041029
6. <i>Loop</i>: Let <var>candidates</var> be the result of <a>finding focusable areas</a>
10051030
within <var>container</var>

0 commit comments

Comments
 (0)