Skip to content

Commit 4712a9d

Browse files
authored
Highlight the anchor target (#441)
1 parent 65103ee commit 4712a9d

File tree

6 files changed

+32
-10
lines changed

6 files changed

+32
-10
lines changed

css/elements.css

+18
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,24 @@ table.lightweight-table th {
769769
vertical-align: baseline;
770770
}
771771

772+
/* for non-clause-like link targets, apply a fading highlight
773+
and a persistent focus-associated highlight */
774+
@keyframes highlight-target-bg {
775+
0% {
776+
background-color: rgba(249, 241, 172, 1);
777+
}
778+
100% {
779+
background-color: rgba(249, 241, 172, 0)
780+
}
781+
}
782+
#spec-container :target:not(emu-annex, emu-clause, emu-intro, emu-note, body) {
783+
animation: highlight-target-bg 2.5s ease-out;
784+
}
785+
#spec-container :target:focus-within:not(:has(:not(a))) {
786+
animation: none;
787+
background-color: rgba(249, 241, 172, 1);
788+
}
789+
772790
/* diff styles */
773791
ins {
774792
background-color: #e0f8e0;

src/Dfn.ts

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import Builder from './Builder';
77
/*@internal*/
88
export default class Dfn extends Builder {
99
static async enter({ spec, node, clauseStack }: Context) {
10+
if (!node.hasAttribute('tabindex')) {
11+
node.setAttribute('tabindex', '-1');
12+
}
13+
1014
const parentClause = clauseStack[clauseStack.length - 1];
1115
if (!parentClause) return;
1216

test/baselines/generated-reference/autolinking.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ <h1><span class="secnum">1</span> Autolinking</h1>
1111
<p>Type, type, <emu-xref aoid="Type"><a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(), type()</p>
1212
<p><emu-xref href="#sec-array-constructor"><a href="https://tc39.es/ecma262/#sec-array-constructor">%Array%</a></emu-xref> and %ArrayPrototype% from ES6 should link (but not %Arrayprototype%).</p>
1313

14-
<p><dfn>Lowercase</dfn></p>
15-
<p><dfn>strict mode</dfn></p>
16-
<p><dfn>%Percent%</dfn></p>
17-
<p><dfn>extra spaces</dfn></p>
18-
<p><dfn>Await</dfn></p>
19-
<p><dfn id="variants" variants="vOne, vTwo">Variants</dfn></p>
14+
<p><dfn tabindex="-1">Lowercase</dfn></p>
15+
<p><dfn tabindex="-1">strict mode</dfn></p>
16+
<p><dfn tabindex="-1">%Percent%</dfn></p>
17+
<p><dfn tabindex="-1">extra spaces</dfn></p>
18+
<p><dfn tabindex="-1">Await</dfn></p>
19+
<p><dfn id="variants" variants="vOne, vTwo" tabindex="-1">Variants</dfn></p>
2020
<p><emu-eqn id="𝔽" aoid="𝔽" class="inline">𝔽(<var>x</var>)</emu-eqn></p>
2121
</emu-clause>
2222
<emu-clause id="sec-bar">

test/baselines/generated-reference/dfn.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ <h1>Intro</h1>
1414
<emu-clause id="sec-dfn">
1515
<h1><span class="secnum">1</span> dfn</h1>
1616

17-
<p>The term <dfn>dfn</dfn> means the dfn tag. Other mentions of dfn in this clause should not be auto-linked.</p>
17+
<p>The term <dfn tabindex="-1">dfn</dfn> means the dfn tag. Other mentions of dfn in this clause should not be auto-linked.</p>
1818

19-
<p>Terms with ids are called <dfn id="identifiers">id dfns</dfn>. Since this dfn has an id, other occurences
19+
<p>Terms with ids are called <dfn id="identifiers" tabindex="-1">id dfns</dfn>. Since this dfn has an id, other occurences
2020
of <emu-xref href="#identifiers" id="_ref_1"><a href="#identifiers">id dfns</a></emu-xref> may autolink.</p>
2121

2222
<emu-clause id="sec-dfn-subclause">

test/baselines/generated-reference/oldids.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</ul></div><div id="spec-container">
99
<emu-clause id="c1" oldids="old1,old2"><span id="old2"></span><span id="old1"></span>
1010
<h1><span class="secnum">1</span> c1</h1>
11-
<p>This is some <dfn id="content" oldids="olddfn"><span id="olddfn"></span>content</dfn> and such.</p>
11+
<p>This is some <dfn id="content" oldids="olddfn" tabindex="-1"><span id="olddfn"></span>content</dfn> and such.</p>
1212
<emu-clause id="c2" oldids="old3,old4"><span id="old4"></span><span id="old3"></span>
1313
<h1><span class="secnum">1.1</span> c1.1</h1>
1414
</emu-clause>

test/baselines/generated-reference/optional-parts.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<emu-clause id="conformance">
1212
<h1><span class="secnum">1</span> Definitions of Normative Optional etc</h1>
13-
<p><dfn id="normative-optional">Normative Optional</dfn> is a defined term, as is <dfn id="legacy">Legacy</dfn>. For comparison, "Deprecated" is not.</p>
13+
<p><dfn id="normative-optional" tabindex="-1">Normative Optional</dfn> is a defined term, as is <dfn id="legacy" tabindex="-1">Legacy</dfn>. For comparison, "Deprecated" is not.</p>
1414
</emu-clause>
1515

1616
<emu-clause id="example-normative-optional" normative-optional=""><div class="attributes-tag"><emu-xref href="#normative-optional" id="_ref_0"><a href="#normative-optional">Normative Optional</a></emu-xref></div>

0 commit comments

Comments
 (0)