-
Notifications
You must be signed in to change notification settings - Fork 0
/
delegates-focus-focus-method.html
76 lines (71 loc) · 2.1 KB
/
delegates-focus-focus-method.html
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html>
<head>
<title>Custom Elements: delegatesFocus focus method</title>
<meta name="author" title="Eugene Kashida" href="mailto:[email protected]">
</head>
<body>
<script>
class DelegatesFalse extends HTMLElement {
constructor() {
super();
this._shadowRoot = this.attachShadow({
delegatesFocus: false,
mode: 'open',
});
this._shadowRoot.innerHTML = `
<div>
<input placeholder="delegatesFocus=false">
</div>
`;
}
}
class DelegatesTrue extends HTMLElement {
constructor() {
super();
this._shadowRoot = this.attachShadow({
delegatesFocus: true,
mode: 'open',
});
this._shadowRoot.innerHTML = `
<div>
<span tabindex="-1">focusable span -1</span>
<span tabindex="0">focusable span 0</span>
<input placeholder="delegatesFocus=true">
</div>
`;
}
}
customElements.define('delegates-true', DelegatesTrue);
customElements.define('delegates-false', DelegatesFalse);
var div = document.createElement('div');
div.innerHTML = `
<div>
<button class="delegates-false-button">Invoke focus() on delegates-false</button>
<delegates-false></delegates-false>
</div>
<div>
<button class="delegates-true-button">Invoke focus() on delegates-true</button>
<delegates-true></delegates-true>
</div>
<div>
<button class="foo">Invoke focus() on foo input</button>
<input placeholder="foo">
</div>
`;
document.body.appendChild(div);
var falseButton = div.querySelector('.delegates-false-button');
falseButton.addEventListener('click', function() {
div.querySelector('delegates-false').focus();
});
var trueButton = div.querySelector('.delegates-true-button');
trueButton.addEventListener('click', function() {
div.querySelector('delegates-true').focus();
});
var fooButton = div.querySelector('.foo');
fooButton.addEventListener('click', function() {
div.querySelector('input').focus();
});
</script>
</body>
</html>