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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
EuiFlyoutHeader,
EuiFormRow,
EuiHealth,
EuiScreenReaderOnly,
EuiSpacer,
EuiText,
useEuiTheme,
Expand Down Expand Up @@ -76,6 +77,7 @@ export const SynonymRuleFlyout: React.FC<SynonymRuleFlyoutProps> = ({
isMapToTermsInvalid,
mapToTermErrors,
mapToTerms,
announcement,
clearFromTerms,
onCreateOption,
onMapToChange,
Expand Down Expand Up @@ -198,6 +200,21 @@ export const SynonymRuleFlyout: React.FC<SynonymRuleFlyoutProps> = ({
color="text"
onClick={() => onSortTerms()}
iconType={currentSortDirection === 'ascending' ? 'sortUp' : 'sortDown'}
aria-label={
currentSortDirection === 'ascending'
? i18n.translate(
'xpack.searchSynonyms.synonymsSetRuleFlyout.sortAscendingAriaLabel',
{
defaultMessage: 'Sort terms A to Z',
}
)
: i18n.translate(
'xpack.searchSynonyms.synonymsSetRuleFlyout.sortDescendingAriaLabel',
{
defaultMessage: 'Sort terms Z to A',
}
)
}
>
{currentSortDirection === 'ascending' ? (
<FormattedMessage
Expand All @@ -220,6 +237,12 @@ export const SynonymRuleFlyout: React.FC<SynonymRuleFlyoutProps> = ({
color="danger"
size="s"
onClick={clearFromTerms}
aria-label={i18n.translate(
'xpack.searchSynonyms.synonymsSetRuleFlyout.clearAllAriaLabel',
{
defaultMessage: 'Remove all terms',
}
)}
>
<FormattedMessage
id="xpack.searchSynonyms.synonymsSetRuleFlyout.clearAll"
Expand Down Expand Up @@ -327,6 +350,12 @@ export const SynonymRuleFlyout: React.FC<SynonymRuleFlyoutProps> = ({
<EuiFlexItem grow={false}>
<EuiButtonEmpty
data-test-subj="searchSynonymsSynonymsRuleFlyoutResetChangesButton"
aria-label={i18n.translate(
Copy link
Contributor

Choose a reason for hiding this comment

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

@seialkali @wildemat — just a note for future reference: there’s no need to set an explicit aria-label on EuiButtonEmpty.
This was an issue we introduced in the ESLint rule, and it’s already been fixed in elastic/eui#9046
.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the update @alexwizp!

'xpack.searchSynonyms.synonymsSetRuleFlyout.resetAriaLabel',
{
defaultMessage: 'Reset all changes',
}
)}
iconType="refresh"
disabled={!hasChanges}
onClick={resetChanges}
Expand All @@ -336,6 +365,11 @@ export const SynonymRuleFlyout: React.FC<SynonymRuleFlyoutProps> = ({
})}
</EuiButtonEmpty>
</EuiFlexItem>
{/* Shared live region for action voiceover announcements*/}
<EuiScreenReaderOnly>
<span aria-live="polite">{announcement}</span>
</EuiScreenReaderOnly>

<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="searchSynonymsSynonymsRuleFlyoutSaveButton"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import type { EuiComboBoxOptionOption } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { useState } from 'react';
import type { SynonymsSynonymRule } from '@elastic/elasticsearch/lib/api/types';
import { synonymToComboBoxOption, synonymsOptionToString } from '../../utils/synonyms_utils';
Expand Down Expand Up @@ -39,6 +40,12 @@ export const useSynonymRuleFlyoutState = ({
const [fromTermErrors, setFromTermErrors] = useState<string[]>([]);
const [mapToTermErrors, setMapToTermErrors] = useState<string[]>([]);
const [currentSortDirection, setCurrentSortDirection] = useState<SortDirection>('ascending');
const [announcement, setAnnouncement] = useState('');

const announce = (message: string) => {
setAnnouncement(message);
setTimeout(() => setAnnouncement(''), 1000); // clear for next use
};

const hasChanges =
flyoutMode === 'create'
Expand Down Expand Up @@ -68,6 +75,11 @@ export const useSynonymRuleFlyoutState = ({
setIsMapToTermsInvalid(false);
setFromTermErrors([]);
setMapToTermErrors([]);
announce(
i18n.translate('xpack.searchSynonyms.synonymsSetRuleFlyout.resetAnnouncement', {
defaultMessage: 'All changes have been reset',
})
);
};

const isValid = (value: string) => {
Expand Down Expand Up @@ -151,7 +163,14 @@ export const useSynonymRuleFlyoutState = ({
setFromTerms(fromTerms.filter((t) => t.label !== term.label));
};

const clearFromTerms = () => setFromTerms([]);
const clearFromTerms = () => {
setFromTerms([]);
announce(
i18n.translate('xpack.searchSynonyms.synonymsSetRuleFlyout.clearedAnnouncement', {
defaultMessage: 'All terms have been removed',
})
);
};
const onMapToChange = (value: string) => {
isMapToValid(value);
setMapToTerms(value);
Expand All @@ -169,6 +188,7 @@ export const useSynonymRuleFlyoutState = ({
isMapToTermsInvalid,
mapToTermErrors,
mapToTerms,
announcement,
onCreateOption,
onMapToChange,
onSearchChange,
Expand Down