Skip to content

Commit

Permalink
Fix accessibility warnings
Browse files Browse the repository at this point in the history
Fixes issues found in #1197 (comment)
  • Loading branch information
johanbissemattsson committed Jan 8, 2025
1 parent de8e3be commit 81729df
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
1 change: 1 addition & 0 deletions lxl-web/src/lib/components/Search.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
paginationQueryFn={handlePaginationQuery}
extensions={[derivedLxlQualifierPlugin]}
toggleWithKeyboardShortcut
comboboxAriaLabel={$page.data.t('search.search')}
defaultRow={-1}
>
{#snippet resultItem(item, getCellId, isFocusedCell)}
Expand Down
16 changes: 14 additions & 2 deletions packages/supersearch/src/lib/components/SuperSearch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
paginationQueryFn?: PaginationQueryFunction;
transformFn?: TransformFunction;
extensions?: Extension[];
comboboxAriaLabel?: string;
resultItem?: Snippet<
[ResultItem, (cellIndex: number) => string, (cellIndex: number) => boolean, number]
>;
Expand All @@ -49,6 +50,7 @@
paginationQueryFn,
transformFn,
extensions = [],
comboboxAriaLabel,
resultItem = fallbackResultItem,
toggleWithKeyboardShortcut = false,
defaultRow = 0,
Expand Down Expand Up @@ -109,21 +111,31 @@
let collapsedContentAttributes = $derived(
EditorView.contentAttributes.of({
role: 'combobox',
...(comboboxAriaLabel && {
'aria-label': comboboxAriaLabel
}),
'aria-haspopup': 'dialog', // indicates the availability and type of interactive popup element that can be triggered by the element
'aria-controls': `${id}-dialog`, // identifies the popup element
'aria-expanded': expanded.toString() // indicates if the popup element is open
'aria-expanded': expanded.toString(), // indicates if the popup element is open
'aria-multiline': 'false' // aria-multineline isn't allowed inside elements with role=combobox
})
);
let includeAriaActiveDescendant = $derived(activeRowIndex >= 0 && !!search?.data); // ensures aria-activedecendant is only shown if the element exists in the DOM
let expandedContentAttributes = $derived(
EditorView.contentAttributes.of({
id: `${id}-content`,
role: 'combobox', // identifies the element as a combobox
...(comboboxAriaLabel && {
'aria-label': comboboxAriaLabel
}),
'aria-haspopup': 'grid', // indicates that the combobox can popup a grid to suggest values
'aria-expanded': 'true', // indicates that the popup element is displayed
'aria-autocomplete': 'list', // indicates that the autocomplete behavior of the input is to suggest a list of possible values in a popup
'aria-controls': `${id}-grid`, // identifies the popup element that lists suggested values
...(activeRowIndex >= 0 && {
'aria-multiline': 'false',
...(includeAriaActiveDescendant && {
'aria-activedescendant': `${id}-result-item-${activeRowIndex}x${activeColIndex}` // enables assistive technologies to know which element the application regards as focused while DOM focus remains on the input element
})
})
Expand Down
28 changes: 17 additions & 11 deletions packages/supersearch/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,19 @@
language={lxlQuery}
extensions={[lxlQualifierPlugin()]}
toggleWithKeyboardShortcut
comboboxAriaLabel="Search"
>
{#snippet resultItem(item, getCellId, isFocusedCell, rowIndex)}
<div class="result-item" data-test-id="result-item">
<a
href={`/test1#${getCellId(0)}`}
role="gridcell"
id={getCellId(0)}
class:focused-cell={isFocusedCell(0)}
>
<h2>{item.heading}</h2>
</a>
<div role="gridcell">
<a
href={`/test1#${getCellId(0)}`}
id={getCellId(0)}
class:focused-cell={isFocusedCell(0)}
>
<h2>{item.heading}</h2>
</a>
</div>
{#if (rowIndex! > 0 && rowIndex! <= 4) || rowIndex == 9}
<button
type="button"
Expand Down Expand Up @@ -103,6 +105,7 @@
paginationQueryFn={handlePaginationQuery}
language={lxlQuery}
extensions={[lxlQualifierPlugin()]}
comboboxAriaLabel="Search"
defaultRow={-1}
>
{#snippet resultItem(item, getCellId, isFocusedCell, rowIndex)}
Expand All @@ -127,14 +130,17 @@
min-width: 480px;
& button,
& a {
& [role='gridcell'] {
min-width: 44px;
min-height: 44px;
}
& a:first-child {
& [role='gridcell']:first-child {
flex: 1;
justify-content: flex-start;
& a {
justify-content: flex-start;
}
}
& a {
Expand Down

0 comments on commit 81729df

Please sign in to comment.