Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/autocomplete-js/src/createAutocompleteDom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ export function createAutocompleteDom<TItem extends BaseItem>({
isDetached,
});

const inputLiveRegion = createDomElement('div', {
ariaLive: 'assertive',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in UK gov, this is "polite"

hidden: true,
});
const inputWrapperPrefix = createDomElement('div', {
class: classNames.inputWrapperPrefix,
children: [label, loadingIndicator],
Expand All @@ -118,7 +122,7 @@ export function createAutocompleteDom<TItem extends BaseItem>({
});
const inputWrapper = createDomElement('div', {
class: classNames.inputWrapper,
children: [input],
children: [input, inputLiveRegion],
});

const formProps = propGetters.getFormProps({
Expand Down Expand Up @@ -207,6 +211,7 @@ export function createAutocompleteDom<TItem extends BaseItem>({
detachedOverlay,
detachedSearchButtonQuery,
detachedSearchButtonPlaceholder,
inputLiveRegion,
inputWrapper,
input,
root,
Expand Down
6 changes: 6 additions & 0 deletions packages/autocomplete-js/src/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export function renderSearchBox<TItem extends BaseItem>({
setProperties(dom.detachedSearchButtonPlaceholder, {
hidden: Boolean(state.query),
});

// FIXME: Should leverage `translations`
dom.inputLiveRegion.innerText = ((count) =>
count > 0 ? `${count} results available` : 'No results available')(
state.collections.reduce((count, { items }) => count + items.length, 0)
);
}

// Safari will animate the SVG even when it's hidden. We need to pause the
Expand Down
1 change: 1 addition & 0 deletions packages/autocomplete-js/src/types/AutocompleteDom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type AutocompleteDom = {
inputLiveRegion: HTMLDivElement;
inputWrapper: HTMLDivElement;
input: HTMLInputElement;
root: HTMLDivElement;
Expand Down