Skip to content

Commit b4f8af0

Browse files
committed
Add tabbable option to Highlight object
Default tabbable to true Update snapshots
1 parent 66828d2 commit b4f8af0

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

src/Highlight.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface IHighlightData {
1414
export interface IOptions {
1515
skipIDsBy?: RegExp;
1616
formatMessage: (descriptor: { id: string }, values: { style: IHighlightData['style'] }) => string;
17+
tabbable?: boolean;
1718
}
1819

1920
export default class Highlight {

src/Highlighter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface IOptions {
2121
onSelect?: (highlights: Highlight[], newHighlight?: Highlight) => void;
2222
onFocusIn?: (highlight: Highlight) => void;
2323
onFocusOut?: (highlight: Highlight) => void;
24+
tabbable?: boolean;
2425
}
2526

2627
export default class Highlighter {
@@ -42,6 +43,7 @@ export default class Highlighter {
4243
onFocusOut: () => {
4344
this.clearFocusedStyles();
4445
},
46+
tabbable: true,
4547
...options,
4648
};
4749
this.debouncedSnapSelection = debounce(this.snapSelection, ON_SELECT_DELAY);
@@ -106,11 +108,12 @@ export default class Highlighter {
106108
}
107109

108110
public getHighlightOptions(): HighlightOptions {
109-
const { formatMessage, skipIDsBy } = this.options;
111+
const { formatMessage, skipIDsBy, tabbable } = this.options;
110112

111113
return {
112114
formatMessage,
113115
skipIDsBy,
116+
tabbable,
114117
};
115118
}
116119

src/__snapshots__/injectHighlightWrappers.spec.ts.snap

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ exports[`inject highlight wrappers for figure with caption for highlight ending
1010
aria-label="Start of highlight"
1111
data-for-screenreaders="true"
1212
data-highlight-id="some-highlight"
13-
tabindex="0"
1413
/>
1514
hardware store sells 16-ft ladders and 24-ft ladders. A window is located 12 feet above the ground. A ladder needs to be purchased that will reach the window from a point on the ground 5 feet from the building.
1615
</span>
@@ -46,7 +45,6 @@ exports[`inject highlight wrappers for figure with caption for highlight ending
4645
aria-label="Start of highlight"
4746
data-for-screenreaders="true"
4847
data-highlight-id="some-highlight"
49-
tabindex="0"
5048
/>
5149
hardware store sells 16-ft ladders and 24-ft ladders. A window is located 12 feet above the ground. A ladder needs to be purchased that will reach the window from a point on the ground 5 feet from the building.
5250
</span>
@@ -82,7 +80,6 @@ exports[`inject highlight wrappers for figure with caption for highlight startin
8280
aria-label="Start of highlight"
8381
data-for-screenreaders="true"
8482
data-highlight-id="some-highlight"
85-
tabindex="0"
8683
/>
8784
<img
8885
alt="A right triangle with a base of 5 feet, a height of 12 feet, and a hypotenuse labeled c"
@@ -108,7 +105,6 @@ exports[`inject highlight wrappers for figure with caption for highlight startin
108105
aria-label="Start of highlight"
109106
data-for-screenreaders="true"
110107
data-highlight-id="some-highlight"
111-
tabindex="0"
112108
/>
113109
<img
114110
alt="A right triangle with a base of 5 feet, a height of 12 feet, and a hypotenuse labeled c"
@@ -134,7 +130,6 @@ exports[`inject highlight wrappers for figure with caption for highlight startin
134130
aria-label="Start of highlight"
135131
data-for-screenreaders="true"
136132
data-highlight-id="some-highlight"
137-
tabindex="0"
138133
/>
139134
<img
140135
alt="A right triangle with a base of 5 feet, a height of 12 feet, and a hypotenuse labeled c"
@@ -170,7 +165,6 @@ exports[`inject highlight wrappers for figure with caption for highlight startin
170165
aria-label="Start of highlight"
171166
data-for-screenreaders="true"
172167
data-highlight-id="some-highlight"
173-
tabindex="0"
174168
/>
175169
<img
176170
alt="A right triangle with a base of 5 feet, a height of 12 feet, and a hypotenuse labeled c"
@@ -206,7 +200,6 @@ exports[`inject highlight wrappers for figure with caption for highlight startin
206200
aria-label="Start of highlight"
207201
data-for-screenreaders="true"
208202
data-highlight-id="some-highlight"
209-
tabindex="0"
210203
/>
211204
<img
212205
alt="A right triangle with a base of 5 feet, a height of 12 feet, and a hypotenuse labeled c"
@@ -232,7 +225,6 @@ exports[`inject highlight wrappers for figure with caption for highlight startin
232225
aria-label="Start of highlight"
233226
data-for-screenreaders="true"
234227
data-highlight-id="some-highlight"
235-
tabindex="0"
236228
/>
237229
<img
238230
alt="A right triangle with a base of 5 feet, a height of 12 feet, and a hypotenuse labeled c"
@@ -258,7 +250,6 @@ exports[`inject highlight wrappers for figure with caption for highlight startin
258250
aria-label="Start of highlight"
259251
data-for-screenreaders="true"
260252
data-highlight-id="some-highlight"
261-
tabindex="0"
262253
/>
263254
<img
264255
alt="A right triangle with a base of 5 feet, a height of 12 feet, and a hypotenuse labeled c"
@@ -284,7 +275,6 @@ exports[`inject highlight wrappers for img between paragraphs in chrome and safa
284275
aria-label="Start of highlight"
285276
data-for-screenreaders="true"
286277
data-highlight-id="some-highlight"
287-
tabindex="0"
288278
/>
289279
the first terms, the outer terms, the inner terms, and then the last terms of each binomial.
290280
</span>
@@ -320,7 +310,6 @@ exports[`inject highlight wrappers for img between paragraphs in firefox 1`] = `
320310
aria-label="Start of highlight"
321311
data-for-screenreaders="true"
322312
data-highlight-id="some-highlight"
323-
tabindex="0"
324313
/>
325314
the first terms, the outer terms, the inner terms, and then the last terms of each binomial.
326315
</span>
@@ -356,7 +345,6 @@ exports[`inject highlight wrappers for text followed by section in chrome and sa
356345
aria-label="Start of highlight"
357346
data-for-screenreaders="true"
358347
data-highlight-id="some-highlight"
359-
tabindex="0"
360348
/>
361349
How To
362350
<span
@@ -377,7 +365,6 @@ exports[`inject highlight wrappers for text followed by section in firefox 1`] =
377365
aria-label="Start of highlight"
378366
data-for-screenreaders="true"
379367
data-highlight-id="some-highlight"
380-
tabindex="0"
381368
/>
382369
How To
383370
<span

src/injectHighlightWrappers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ function createAndInsertNodeForScreenReaders(highlight: Highlight, element: HTML
7676
node.setAttribute('aria-label', ariaLabel);
7777

7878
if (position === 'start') {
79-
node.setAttribute('tabindex', '0');
79+
if (highlight.options.tabbable) {
80+
node.setAttribute('tabindex', '0');
81+
}
8082
element.prepend(node);
8183
} else {
8284
element.append(node);

0 commit comments

Comments
 (0)