Skip to content

Commit 2663c58

Browse files
author
Jihye Hong
committed
Add the spatial-navigation-action CSS Property
- Add the description of spatial-navigation-action CSS Property - Add an example of the property
1 parent 9753ac3 commit 2663c58

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

css-nav-1/Overview.bs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,84 @@ Note: the 'spatial-navigation-contain' property is <a>at-risk</a>.
12501250

12511251
</div>
12521252

1253+
<h3 id=container>
1254+
Defining the spatial navigation behavior : the 'spatial-navigation-action' property</h3>
1255+
1256+
<pre class='propdef'>
1257+
Name: spatial-navigation-action
1258+
Value: auto | focus | scroll
1259+
Initial: auto
1260+
Applies to: <a>spatial navigation focus container</a>
1261+
Inherited: true
1262+
</pre>
1263+
1264+
When the user triggers spatial navigation in a given direction, the 'spatial-navigation-action' decides
1265+
the proper spatial navigation behavior.
1266+
1267+
<dl dfn-for=spatial-navigation-action dfn-type=value>
1268+
<dt><dfn>auto</dfn>
1269+
<dd>If the element is a <a>scroll container</a>,
1270+
then directional input moves the focus to the candidates in the viewport.
1271+
When there isn't any visible candidate, then the container scrolls.
1272+
1273+
<dt><dfn>focus</dfn>
1274+
<dd>If the element is a <a>scroll container</a>,
1275+
then directional input moves the focus to the candidates(visible or not). The user cannot manually scroll the container.
1276+
1277+
NOTE: If the 'focus' value is given to 'spatial-navigation-action', 'navnotarget' event occurs
1278+
when there isn’t any visible candidate in the spatial navigation container no matter what it can be scrolled more or not.
1279+
1280+
<dt><dfn>scroll</dfn>
1281+
<dd>If the element is a <a>scroll container</a>,
1282+
then directional input only works for manually scrolling the container.
1283+
1284+
Note: The 'scroll' value is <a>at-risk</a>.
1285+
</dl>
1286+
1287+
<div class=example>
1288+
In this example, there is an element which is out of the view within the scrollable element.
1289+
Pressing the down arrow key moves the focus directly to it without scrolling mannually.
1290+
1291+
<pre><code highlight=markup>
1292+
&lt;div class = 'scroller'>
1293+
&lt;button class = 'item'>&lt;/button>
1294+
&lt;button class = 'item'>&lt;/button>
1295+
&lt;button class = 'item'>&lt;/button>
1296+
&lt;/div>
1297+
</code></pre>
1298+
<pre><code highlight=css>
1299+
.scroller {
1300+
display: grid;
1301+
grid-template-columns: repeat(1, 1fr);
1302+
height: 300px;
1303+
width: 200px;
1304+
overflow-y: scroll;
1305+
spatial-navigation-action: focus;
1306+
}
1307+
.item {
1308+
height: 100px;
1309+
width: 100px;
1310+
margin: 50px auto;
1311+
}
1312+
</code></pre>
1313+
<pre><code highlight=js>
1314+
let container = document.getElementById('feed');
1315+
let currentTarget = document.activeElement;
1316+
1317+
container.addEventListener('navnotarget', function(e) {
1318+
let nextFocus = currentTarget.spatialNavigationSearch({
1319+
dir: e.dir,
1320+
candidates: this.focusableAreas({'mode': 'all'}),
1321+
container: this
1322+
});
1323+
1324+
nextFocus.scrollIntoView();
1325+
nextFocus.focus({preventScroll:true});
1326+
});
1327+
</code></pre>
1328+
1329+
</div>
1330+
12531331
<h2 class=no-num id=scrolling>Appendix A. Scroll extensions</h2>
12541332

12551333
This section proposes a few extensions to CSS

0 commit comments

Comments
 (0)