Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[A11y] [SearchBar] [Filters] Improve accessibility of the Filters toggle button #8091

Merged
merged 15 commits into from
Nov 26, 2024
Merged
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: 7 additions & 0 deletions packages/eui/changelogs/upcoming/8091.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**Accessibility**

- Ensures `autoFocus` on `EuiSelectableList` triggers initial focus
- Improved the accessibility of `EuiSearchBarFilters` by:
- adding a more descriptive `aria-label` to selection filter buttons
- ensuring the selection listbox is initially focused when opening a selection popover

2 changes: 1 addition & 1 deletion packages/eui/src/components/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ export class EuiPopover extends Component<Props, State> {
// it will be on the panel instead on mount when isOpen=true
if (
document.activeElement === document.body ||
document.activeElement === this.panel
this.panel?.contains(document.activeElement) // if focus is on OR within this.panel
) {
if (!this.button) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ exports[`SearchBar render - provided query, filters 1`] = `
class="euiPopover emotion-euiPopover-inline-block"
>
<button
aria-label="Tag Selection"
class="euiButtonEmpty euiFilterButton emotion-euiButtonDisplay-euiButtonEmpty-m-empty-text-euiFilterButton"
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ exports[`EuiSearchBarFilters render - with filters 1`] = `
class="euiPopover emotion-euiPopover-inline-block"
>
<button
aria-label="Tag Selection"
class="euiButtonEmpty euiFilterButton emotion-euiButtonDisplay-euiButtonEmpty-m-empty-text-euiFilterButton"
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { EuiFilterButton } from '../../filter_group';
import { euiFilterGroupStyles } from '../../filter_group/filter_group.styles';
import { EuiSelectable, EuiSelectableProps } from '../../selectable';
import { EuiSelectableOptionCheckedType } from '../../../components/selectable/selectable_option';
import { EuiI18n } from '../../i18n';
import { Query } from '../query';
import { Clause, Operator, OperatorType, Value } from '../query/ast';

Expand Down Expand Up @@ -298,16 +299,27 @@ export class FieldValueSelectionFilter extends Component<
const active = (activeTop || activeItem) && activeItemsCount > 0;

const button = (
<EuiFilterButton
iconType="arrowDown"
iconSide="right"
onClick={this.onButtonClick.bind(this)}
hasActiveFilters={active}
numActiveFilters={active ? activeItemsCount : undefined}
grow
<EuiI18n
token="euiFieldValueSelectionFilter.buttonLabelHint"
default="Selection"
>
{config.name}
</EuiFilterButton>
{(buttonLabelHint: string) => {
const ariaLabel = `${config.name} ${buttonLabelHint}`;
return (
<EuiFilterButton
iconType="arrowDown"
iconSide="right"
hasActiveFilters={active}
numActiveFilters={active ? activeItemsCount : undefined}
grow
aria-label={ariaLabel}
onClick={this.onButtonClick.bind(this)}
>
{config.name}
</EuiFilterButton>
);
}}
</EuiI18n>
);

const items = options
Expand Down Expand Up @@ -390,6 +402,7 @@ export class FieldValueSelectionFilter extends Component<
noMatchesMessage={config.noOptionsMessage}
listProps={{
isVirtualized: isOverSearchThreshold || false,
autoFocus: true,
}}
onChange={(options, event, changedOption) => {
if (changedOption.data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ describe('EuiSearchBar', () => {
it('has zero violations after filtering by Tags', () => {
cy.get('button.euiButtonEmpty').last().focus();
cy.realPress('Enter');
cy.realPress('Tab');
cy.realPress('ArrowDown');
cy.realPress('Enter');
cy.realPress('Escape');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export class EuiSelectableList<T> extends Component<
listId,
searchable,
singleSelection,
autoFocus,
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledby,
'aria-describedby': ariaDescribedby,
Expand All @@ -259,6 +260,12 @@ export class EuiSelectableList<T> extends Component<
if (typeof ariaDescribedby === 'string') {
ref.setAttribute('aria-describedby', ariaDescribedby);
}

if (autoFocus === true) {
// manually focus listbox once available
// use last stack execution to prevent potential focus order issues
setTimeout(() => ref.focus());
}
}
};

Expand Down Expand Up @@ -714,6 +721,7 @@ export class EuiSelectableList<T> extends Component<
isVirtualized,
textWrap,
truncationProps,
autoFocus,
...rest
} = this.props;

Expand Down