@@ -52,6 +52,10 @@ code.key {
5252 border-radius: 0.5ch;
5353 padding: 1px 5px;
5454}
55+ .output {
56+ background: white;
57+ padding: 1em;
58+ }
5559</style>
5660
5761
@@ -1211,7 +1215,95 @@ Note: In addition, as per [[#grouping]], the viewport of a <a for="/">browsing c
12111215 (not limited to the <a>top-level browsing context</a> )
12121216 also establishes a <a>spatial navigation focus container</a> .
12131217
1214- Issue(16): Add an example
1218+ <div class=example>
1219+ The following example shows a simplified TV program schedule or calendar.
1220+ It has a grid of elements representing TV shows or calendar entries,
1221+ and some UI buttons around it.
1222+
1223+ In this case, the grid is quite sparse,
1224+ so if the user tries to move down from "Foo",
1225+ focus would be moved to "Next Week",
1226+ as it is objectively closer in the down direction.
1227+ The same is true for going down from "Bar":
1228+ the focus would be moved to "Previous Week".
1229+
1230+ <div class=output>
1231+ <div id=example-cal>
1232+ <button> Previous Week</button>
1233+ <table>
1234+ <tr><td><th> M<th> T<th> W<th> T<th> F<th> S<th> S
1235+ <tr><td> 0-6<td><td><td><td><td><td><td> <a href="#">Foo</a>
1236+ <tr><td> 6-9<td> <a href="#">Bar</a> <td><td><td><td><td><td>
1237+ <tr><td> 9-12<td><td><td><td><td><td><td>
1238+ <tr><td> 12-18<td><td><td><td><td><td><td>
1239+ <tr><td> 18-21<td><td><td><td><td><td><td>
1240+ <tr><td> 21-24<td><td><td><td><td><td> <a href="#">Baz</a> <td>
1241+ </table>
1242+ <button> Next Week</button>
1243+ </div>
1244+ <style>
1245+ #example-cal table, #example-cal td, #example-cal th {
1246+ border-collapse: collapse;
1247+ border: solid 1px;
1248+ }
1249+ #example-cal th { text-align: center; }
1250+ #example-cal td { width: 12.5%; }
1251+ #example-cal {
1252+ display: grid;
1253+ grid-template-columns: auto 1fr auto;
1254+ }
1255+ #example-cal button { align-self: center; }
1256+
1257+ /* For browsers that don't support grid */
1258+ #example-cal table {
1259+ display:inline-table
1260+ vertical-align: middle;
1261+ }
1262+ </style>
1263+ </div>
1264+ <pre><code highlight=markup>
1265+ <div>
1266+ <button>Previous Week</button>
1267+ <table>
1268+ <tr><td><th>M<th>T<th>W<th>T<th>F<th>S<th>S
1269+ <tr><td>0-6<td><td><td><td><td><td><td><a href="#">Foo</a>
1270+ <tr><td>6-9<td><a href="#">Bar</a><td><td><td><td><td><td>
1271+ <tr><td>9-12<td><td><td><td><td><td><td>
1272+ <tr><td>12-18<td><td><td><td><td><td><td>
1273+ <tr><td>18-21<td><td><td><td><td><td><td>
1274+ <tr><td>21-24<td><td><td><td><td><td><a href="#">Baz</a><td>
1275+ </table>
1276+ <button>Next Week</button>
1277+ </div>
1278+ </code></pre>
1279+ <pre><code highlight=css>
1280+ table, td, th {
1281+ border-collapse: collapse;
1282+ border: solid 1px;
1283+ }
1284+ td { width: 12.5%; }
1285+ div {
1286+ display: grid;
1287+ grid-template-columns: auto 1fr auto;
1288+ }
1289+ button { align-self: center; }
1290+ </code></pre>
1291+
1292+ Because the elements in the table are semantically related to eachother,
1293+ the author may want to provide a different navigation experience
1294+ giving priority to movements inside the grid once you have focused one of its items.
1295+
1296+ Adding <code highlight=css> table { spatial-navigation-contain: contain; }</code> to the stylesheet
1297+ would result it this behavior.
1298+ It would still be possible to move the focus out of the table,
1299+ for example by going right from "Foo".
1300+ Since there is nothing in the grid that is to the right,
1301+ the focus would move to "Next week".
1302+
1303+ However, if the user navigates down from "Foo",
1304+ there is something inside the grid,
1305+ so focus will move there without considering things that are outside.
1306+ </div>
12151307
12161308Note: the 'spatial-navigation-contain' property is <a>at-risk</a> .
12171309
0 commit comments