-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathautocomplete.html
76 lines (76 loc) · 4.13 KB
/
autocomplete.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 lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Accessible Autocomplete</title>
<link rel="stylesheet" href="css/normalization.css" />
<link rel="stylesheet" href="css/base.css" />
<link rel="stylesheet" href="css/autocomplete.css">
</head>
<body>
<div class="container">
<a href="#main" class="skip-link">Skip to main content</a>
<div class="page-wrapper" id="main" role="main" tabindex="-1">
<h1>Accessible Autocomplete</h1>
<p><a href="http://haltersweb.github.io/Accessibility/">View the full library of accessibility solutions.</a></p>
<p>This is an accessible autocomplete which works with keyboard, screen readers, switch devices, and touch screens.</p>
<h2>Example</h2>
<p>This solution is written in jQuery using fake data. Future TODOs: 1) write in vanilla JS 2) instantiation.</p>
<p>NOTE: type any letter to get 6 results. Any 2 letters gives you 3 results; 3 letters gives you 1 result.</p>
<div id="a11yAutocomplete">
<form action="">
<div data-widget="accessible-autocomplete">
<label for="search">Search for:</label>
<input type="text" id="search" autocomplete="off" class="autocomplete-search-field" aria-describedby="initInstr" aria-owns="results" aria-expanded="false" aria-autocomplete="both" aria-activedescendant="" />
<button type="button" id="clearText">clear text</button>
<button type="submit" id="submit">Search</button>
<ul id="results" class="autocomplete-list" role="listbox" tabindex=0 style="display: none;"></ul>
<span id="initInstr" style="display: none;">When autocomplete results are available use up and down arrows to review and enter to select. Touch device users, explore by touch or with swipe gestures.</span>
<div aria-live="assertive" class="screen-reader-text"></div>
</div>
</form>
</div>
<p>It's up to you to set mobile style handling but here's an example <button type="button" id="addMobiClass">toggle .mobi class</button>.</p>
<h2>Keyboard Interaction</h2>
<ul class="bullet singletons">
<li><strong>UP and DOWN:</strong> Cycles through auto-suggestions and input field.</li>
<li><strong>ESC:</strong> Close the menu</li>
<li><strong>ENTER:</strong> Select the currently focused auto-suggestion and close the menu.</li>
<li><strong>TAB:</strong> Select the currently focused auto-suggestion, close the menu, and move focus to the next focusable element.</li>
</ul>
<h2>Screen-reader Interaction</h2>
<ul class="bullet singletons">
<li>when the search field gains focus an initial instruction is announced.</li>
<li>when search results are returned the count and instructions are announced.</li>
<li>when suggestions are arrowed through they are spoken aloud.</li>
</ul>
<h2>Aria</h2>
<ul class="bullet singletons">
<li><strong>input:</strong> aria-describedby="initInstr" aria-owns="results" aria-expanded="false" aria-autocomplete="both" aria-activedescendant=""</li>
<li><strong>ul:</strong> id="results" role="listbox"</li>
<li><strong>li:</strong> id="" role="option" aria-selected="false"</li>
</ul>
<h2>Code Sample</h2>
<div data-code="a11yAutocomplete"></div>
</div>
<!--
<p>list of suggestions: ul has tabindex="0" li has role="button" and tabindex="-1" (not sure it needs this since list items never really get focus. NEVERMIND, yes it does) When hovered/arrowed selected gets "aria-selected="true"</p>
-->
<div class="overlay"></div>
<div class="block-screen"></div>
<div aria-live="polite" class="screen-reader-text"></div>
<div role="alert" class="screen-reader-text"></div>
</div>
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/namespacing.js"></script>
<script type="text/javascript" src="js/accessibility-helpers.js"></script>
<script type="text/javascript" src="js/autocomplete.js"></script>
<script type="text/javascript" src="js/show-code.js"></script>
<script>
$('#addMobiClass').on('click', function () {
$('[data-widget="accessible-autocomplete"]').toggleClass('mobi');
});
</script>
</body>
</html>