|
13 | 13 | } |
14 | 14 | </style> |
15 | 15 | <script> |
| 16 | + var robotsList = ` |
| 17 | + <li role="option" data-autocomplete-value="@hubot">Hubot</li> |
| 18 | + <li role="option" data-autocomplete-value="@bender">Bender</li> |
| 19 | + <li role="option" data-autocomplete-value="@bb-8">BB-8</li> |
| 20 | + <li role="option" data-autocomplete-value="@r2d2" aria-disabled="true">R2-D2 (powered down)</li> |
| 21 | + `; |
16 | 22 | class FakeXMLHttpRequest { |
17 | 23 | abort() { |
18 | 24 | // Do nothing. |
|
25 | 31 | } |
26 | 32 | send() { |
27 | 33 | this.status = 200 |
28 | | - this.responseText = ` |
29 | | - <li role="option" data-autocomplete-value="@hubot">Hubot</li> |
30 | | - <li role="option" data-autocomplete-value="@bender">Bender</li> |
31 | | - <li role="option" data-autocomplete-value="@bb-8">BB-8</li> |
32 | | - <li role="option" data-autocomplete-value="@r2d2" aria-disabled="true">R2-D2 (powered down)</li> |
33 | | - ` |
| 34 | + this.responseText = robotsList |
34 | 35 | setTimeout(this.onload.bind(this), 0) |
35 | 36 | } |
36 | 37 | } |
|
83 | 84 | </auto-complete> |
84 | 85 | <button type="submit">Save</button> |
85 | 86 | </form> |
86 | | - <!--<script type="module" src="./dist/bundle.js"></script>--> |
| 87 | + |
| 88 | + <!-- example with a custom fetching result method --> |
| 89 | + <form> |
| 90 | + <label id="custom-fetching-robots-label" for="custom-fetching-robot">Custom Fetching Robots</label> |
| 91 | + <auto-complete id="custom-fetching-method" src="/demo" for="custom-fetching-items-popup" aria-labelledby="custom-fetching-robots-label" data-autoselect="true"> |
| 92 | + <input name="custom-fetching-robot" type="text" aria-labelledby="custom-fetching-robots-label" autofocus> |
| 93 | + <ul id="custom-fetching-items-popup"></ul> |
| 94 | + <div id="custom-fetching-items-popup-feedback" class="sr-only"></div> |
| 95 | + </auto-complete> |
| 96 | + <button type="submit">Save</button> |
| 97 | + </form> |
| 98 | + <script> |
| 99 | + window.fetch = () => Promise.resolve(new Response(robotsList)); |
| 100 | + // fetchResult must be a function that return a Promise of string and that accepts as parameters an element and an URL |
| 101 | + document.querySelector("auto-complete#custom-fetching-method").fetchResult = async (el, url) => (await fetch(url)).text(); |
| 102 | + </script> |
| 103 | + |
| 104 | +<!-- <script type="module" src="./dist/bundle.js"></script>--> |
87 | 105 | <script type="module" src="https://unpkg.com/@github/auto-complete-element@latest/dist/bundle.js"></script> |
88 | 106 | </body> |
89 | 107 | </html> |
0 commit comments