Skip to content

Commit

Permalink
fix: [Stateful: Home page] Create an API key dialog information annou…
Browse files Browse the repository at this point in the history
…ncement duplication (elastic#196133)

Closes: elastic#195754
Closes: elastic#195252

## Description
Information about an element (in this case, a dialog) should be
announced once to the user. If the user navigates to another element and
then returns to the same dialog, they should hear the information about
the dialog again (one time).

## What was changed?:

1. Added `aria-labelledby` for `EuiFlyout` based on the EUI
recommendation. This will correctly pronounce the Flyout header without
extra text.
2. Added `aria-labelledby` and `role="region"` for `EuiAccordion` for
the same reason.

## Screen: 

<img width="1792" alt="image"
src="https://github.com/user-attachments/assets/8a7ba05f-381a-4bb1-81fc-eb2c5fdb9fb0">
  • Loading branch information
alexwizp authored Oct 15, 2024
1 parent 5c2df63 commit 0ccfb70
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
EuiSwitchEvent,
EuiText,
EuiTitle,
useGeneratedHtmlId,
} from '@elastic/eui';

import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -161,6 +162,8 @@ export const CreateApiKeyFlyout: React.FC<CreateApiKeyFlyoutProps> = ({ onClose

const apiKeyRef = useRef<HTMLDivElement>(null);

const uniqueId = useGeneratedHtmlId();

useEffect(() => {
if (createdApiKey && apiKeyRef) {
apiKeyRef.current?.scrollIntoView();
Expand All @@ -178,10 +181,11 @@ export const CreateApiKeyFlyout: React.FC<CreateApiKeyFlyoutProps> = ({ onClose
css={css`
max-width: calc(${euiTheme.size.xxxxl} * 10);
`}
aria-labelledby={`${uniqueId}-header`}
>
<EuiFlyoutHeader hasBorder>
<EuiTitle size="m">
<h2>
<h2 id={`${uniqueId}-header`}>
{i18n.translate('xpack.enterpriseSearch.apiKey.flyoutTitle', {
defaultMessage: 'Create an API key',
})}
Expand Down Expand Up @@ -239,6 +243,8 @@ export const CreateApiKeyFlyout: React.FC<CreateApiKeyFlyoutProps> = ({ onClose
id="apiKey.setup"
paddingSize="l"
initialIsOpen
aria-labelledby={`${uniqueId}-setupHeader`}
role="region"
buttonContent={
<div>
<EuiFlexGroup justifyContent="flexStart" alignItems="center" gutterSize="s">
Expand All @@ -247,7 +253,7 @@ export const CreateApiKeyFlyout: React.FC<CreateApiKeyFlyoutProps> = ({ onClose
</EuiFlexItem>
<EuiFlexItem>
<EuiTitle size="xs">
<h4>
<h4 id={`${uniqueId}-setupHeader`}>
{i18n.translate('xpack.enterpriseSearch.apiKey.setup.title', {
defaultMessage: 'Setup',
})}
Expand Down Expand Up @@ -283,6 +289,8 @@ export const CreateApiKeyFlyout: React.FC<CreateApiKeyFlyoutProps> = ({ onClose
<EuiAccordion
id="apiKey.privileges"
paddingSize="l"
role="region"
aria-labelledby={`${uniqueId}-privilegesHeader`}
buttonContent={
<div style={{ paddingRight: euiTheme.size.s }}>
<EuiFlexGroup justifyContent="flexStart" alignItems="center" gutterSize="s">
Expand All @@ -291,7 +299,7 @@ export const CreateApiKeyFlyout: React.FC<CreateApiKeyFlyoutProps> = ({ onClose
</EuiFlexItem>
<EuiFlexItem>
<EuiTitle size="xs">
<h4>
<h4 id={`${uniqueId}-privilegesHeader`}>
{i18n.translate('xpack.enterpriseSearch.apiKey.privileges.title', {
defaultMessage: 'Security Privileges',
})}
Expand Down Expand Up @@ -338,6 +346,8 @@ export const CreateApiKeyFlyout: React.FC<CreateApiKeyFlyoutProps> = ({ onClose
<EuiAccordion
id="apiKey.metadata"
paddingSize="l"
role="region"
aria-labelledby={`${uniqueId}-metadataHeader`}
buttonContent={
<div style={{ paddingRight: euiTheme.size.s }}>
<EuiFlexGroup justifyContent="flexStart" alignItems="center" gutterSize="s">
Expand All @@ -346,7 +356,7 @@ export const CreateApiKeyFlyout: React.FC<CreateApiKeyFlyoutProps> = ({ onClose
</EuiFlexItem>
<EuiFlexItem>
<EuiTitle size="xs">
<h4>
<h4 id={`${uniqueId}-metadataHeader`}>
{i18n.translate('xpack.enterpriseSearch.apiKey.metadata.title', {
defaultMessage: 'Metadata',
})}
Expand Down

0 comments on commit 0ccfb70

Please sign in to comment.