-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
109 lines (103 loc) · 3.52 KB
/
Copy pathindex.html
File metadata and controls
109 lines (103 loc) · 3.52 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0">
<title>Autocomplete-Light: Extremely Lightweight Autocomplete Web Component</title>
<style>
body {
margin: 0 auto;
max-width: 50em;
font-family: "Helvetica", "Arial", sans-serif;
line-height: 1.5;
padding: 4em 1em;
color: #555;
}
h2 {
margin-top: 1em;
padding-top: 1em;
color: #333;
}
</style>
</head>
<body>
<form>
<h2>autocomplete-light input</h2>
<p>
A simple input which emits an event when the user selects an item
and nothing more, check teh HTML source for usage.
</p>
<p>
This is the core autocompletion component, it's all about displaying a
box with HTML fetched from the server, this is useful as-is to make
a global navigation input like in the top bar of facebook for example,
or to build other more complex components such as autocomplete-select.
</p>
<autocomplete-light id="input-simple" url="/">
<input slot="input" type="text" />
</autocomplete-light>
<script>
document.querySelector('#input-simple').addEventListener(
'autocompleteChoiceSelected',
function(ev) {
console.log('SELECTED VALUE: ', ev.detail.choice.getAttribute('data-value'))
this.querySelector('input').value = ev.detail.choice.innerHTML
}
)
</script>
<h2>autocomplete-select non-multiple</h2>
<p>
An autocomplete-select is composed of a hidden select field maintained by the
Web Component, a deck of visible choices that the user can remove, and an
autocomplete input of course.
</p>
<autocomplete-select id="select-simple">
<select slot="select" name="simple"></select>
<div slot="deck">
<div data-value="1" selected>aab</div>
</div>
<autocomplete-select-input slot="input" url="/">
<input slot="input" type="text" />
</autocomplete-select-input>
</autocomplete-select>
<h2>autocomplete-select multiple</h2>
<p>Same as above, with multiple choices</p>
<autocomplete-select multiple id="select-multiple">
<select slot="select" name="multiple" multiple></select>
<div slot="deck">
<div data-value="0" selected>aaa</div>
<div data-value="3" selected>bbb</div>
</div>
<autocomplete-select-input slot="input" url="/">
<input slot="input" type="text" />
</autocomplete-select-input>
</autocomplete-select>
<h2>autocomplete-select from options</h2>
<p>Local: it gets its options from introspecting the select tag without a url.</p>
<p>Change event on vanilla select also works</p>
<autocomplete-select multiple id="select-multiple-local">
<select slot="select" name="multiple-options" multiple>
<option value="0" selected>aaa</option>
<option value="1">aab</option>
<option value="2">abb</option>
<option value="3" selected>bbb</option>
</select>
<div slot="deck"></div>
<autocomplete-select-input slot="input">
<input slot="input" type="text" />
</autocomplete-select-input>
</autocomplete-select>
<script>
var options = document.querySelector('[name=multiple-options]')
options.addEventListener('change', function(e) {
console.log('change multiple-options select')
})
</script>
<h2>form submission</h2>
<p>Click this button to display form data in GET</p>
<input type="submit" />
</form>
<link rel="stylesheet" type="text/css" href="./autocomplete-light.css" />
<script src="./autocomplete-light.js"></script>
</body>
</html>