-
Notifications
You must be signed in to change notification settings - Fork 82
/
focusable.js
55 lines (47 loc) · 1.88 KB
/
focusable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// NOTE: this selector MUST *never* be used directly,
// always go through query/focusable or is/focusable.js
// there are too many edge cases that they could be covered in
// a simple CSS selector…
import selectInShadows from '../util/select-in-shadows';
import _supports from '../supports/supports';
let supports;
let selector;
export default function() {
if (!supports) {
supports = _supports();
}
if (typeof selector === 'string') {
return selector;
}
// https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute
selector = ''
// IE11 supports.can focus <table> and <td>
+ (supports.focusTable ? 'table, td,' : '')
// IE11 supports.can focus <fieldset>
+ (supports.focusFieldset ? 'fieldset,' : '')
// Namespace problems of [xlink:href] explained in https://stackoverflow.com/a/23047888/515124
// svg a[*|href] does not match in IE9, but since we're filtering
// through is/focusable we can include all <a> from SVG
+ 'svg a,'
// may behave as 'svg, svg *,' in chrome as *every* svg element with a focus event listener is focusable
// navigational elements
+ 'a[href],'
// validity determined by is/valid-area.js
+ 'area[href],'
// validity determined by is/disabled.js
+ 'input, select, textarea, button,'
// browsing context containers
+ 'iframe, object, embed,'
// interactive content
+ 'keygen,'
+ (supports.focusAudioWithoutControls ? 'audio,' : 'audio[controls],')
+ (supports.focusVideoWithoutControls ? 'video,' : 'video[controls],')
+ (supports.focusSummary ? 'summary,' : '')
// validity determined by is/valid-tabindex.js
+ '[tabindex],'
// editing hosts
+ '[contenteditable]';
// where ShadowDOM is supported, we also want the shadowed focusable elements (via ">>>" or "/deep/")
selector = selectInShadows(selector);
return selector;
}