Skip to content

Commit 6923cd0

Browse files
edits
1 parent d4f133e commit 6923cd0

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ item whose display text needs to be different:
6969
<li role="option" data-autocomplete-value="bb8">BB-8 (astromech)</li>
7070
```
7171
72+
Use `data-no-result-found="true"` to show a no results message inside the autocomplete popover. Be sure to add `role="presentation"`
73+
to this element so that screen readers do not mistake this as an auto-complete option. The auto-complete-element has built in functionality that
74+
handles aria-live announcing number of search results so this should be purely decorative.
75+
76+
```html
77+
<li role="presentation" aria-hidden="true" disabled data-no-result-found="true">No results found!</li>
78+
```
79+
7280
### A Note on Clear button
7381
While `input type="search"` comes with an `x` that clears the content of the field and refocuses it on many browsers, the implementation for this control is not keyboard accessible, and so we've opted to enable a customizable clear button so that your keyboard users will be able to interact with it.
7482

examples/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
window.fetch = (url) => {
106106
const query = url.split('?q=')[1]
107107
if (query === 'none') {
108-
return Promise.resolve(new Response('<li role="presentation" data-no-result-found="true">No results found!</li>'))
108+
return Promise.resolve(new Response('<li role="presentation" aria-hidden="true" data-no-result-found="true">No results found!</li>'))
109109
}
110110
return Promise.resolve(new Response(robotsList));
111111
}

test/auto-complete-element.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,31 @@ describe('auto-complete element', function () {
434434
assert.isFalse(popup.matches(':popover-open'), 'is not popover-open')
435435
})
436436
})
437+
438+
describe('no results', () => {
439+
beforeEach(function () {
440+
document.body.innerHTML = `
441+
<div id="mocha-fixture">
442+
<auto-complete src="/no_results" for="popup">
443+
<input type="text">
444+
<ul id="popup"></ul>
445+
<div id="popup-feedback"></div>
446+
</auto-complete>
447+
</div>
448+
`
449+
})
450+
451+
it('checks that no results is displayed', async () => {
452+
const container = document.querySelector('auto-complete')
453+
const input = container.querySelector('input')
454+
const popup = container.querySelector('#popup')
455+
456+
triggerInput(input, 'hub')
457+
await once(container, 'loadend')
458+
assert.equal(1, popup.children.length)
459+
460+
})
461+
})
437462
})
438463

439464
function waitForElementToChange(el) {

web-test-runner.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export default {
2828
<li role="option" aria-disabled="true"><span>fourth</span></li>
2929
<li><a role="option" href="#hash">link</a></li>
3030
`
31+
} else if (method === 'GET' && url.startsWith('/no_results?q=hub')) {
32+
response.status = 200
33+
response.body = `<li role="presentation" aria-hidden="true" disabled data-no-result-found="true">No results found!</li>`
3134
}
3235
await next()
3336
},

0 commit comments

Comments
 (0)