-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: [Rules > Rule Detail][SCREEN READER]: Abbreviations must be read…
…aloud correctly (#182417) Closes: elastic/security-team#8649 Closes: elastic/security-team#8658 ## Description The Schedule description list on Rule Detail views is announcing hours and minutes incorrectly to screen readers. VoiceOver announced `5m` as "Five meters" and `1h` as "1 eche". This confusion can be remedied by spelling out the whole word and hiding it visually. Screen shot and code sample attached. ### Steps to recreate 1. Open [Detection Rules (SIEM)](https://kibana.siem.estc.dev/app/security/rules/management) 2. Click on a rule name to land on the detail view 3. Start your preferred screen reader 4. Jump down to the Schedule module and listen to the description list items ### What was done?: The `IntervalAbbrScreenReader` component was developed, and it was integrated into `/rule_creation_ui/components/description_step/index.tsx` and `/rule_details/rule_schedule_section.tsx `to handle the `interval` and `from` fields. ### Screen: <img width="1508" alt="image" src="https://github.com/elastic/kibana/assets/20072247/06e54e68-0dcf-45e3-95df-b3c09cb56db5"> #### DOM: <img width="769" alt="image" src="https://github.com/elastic/kibana/assets/20072247/b0ba88f2-79a2-4fd2-9246-ad5639090bec">
- Loading branch information
Showing
17 changed files
with
200 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
*/ | ||
|
||
export * from './tooltip_with_keyboard_shortcut'; | ||
export * from './interval_abbr_screen_reader'; |
39 changes: 39 additions & 0 deletions
39
...olution/public/common/components/accessibility/interval_abbr_screen_reader/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { TestProviders } from '../../../mock'; | ||
import { IntervalAbbrScreenReader } from '.'; | ||
|
||
describe('IntervalAbbrScreenReader', () => { | ||
test('should add screen reader text for 35s', () => { | ||
render( | ||
<TestProviders> | ||
<IntervalAbbrScreenReader interval="35s" /> | ||
</TestProviders> | ||
); | ||
expect(screen.getByText('35 seconds')).toBeDefined(); | ||
}); | ||
|
||
test('should add screen reader text for 1m', () => { | ||
render( | ||
<TestProviders> | ||
<IntervalAbbrScreenReader interval="1m" /> | ||
</TestProviders> | ||
); | ||
expect(screen.getByText('1 minute')).toBeDefined(); | ||
}); | ||
|
||
test('should add screen reader text for 2h', () => { | ||
render( | ||
<TestProviders> | ||
<IntervalAbbrScreenReader interval="2h" /> | ||
</TestProviders> | ||
); | ||
expect(screen.getByText('2 hours')).toBeDefined(); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
...ity_solution/public/common/components/accessibility/interval_abbr_screen_reader/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import React, { useMemo } from 'react'; | ||
import { EuiScreenReaderOnly } from '@elastic/eui'; | ||
|
||
import * as i18n from './translations'; | ||
|
||
interface IntervalAbbrScreenReaderProps { | ||
interval: string; | ||
} | ||
|
||
export const IntervalAbbrScreenReader = ({ interval }: IntervalAbbrScreenReaderProps) => { | ||
const screenReaderInterval: string | undefined = useMemo(() => { | ||
if (interval) { | ||
const number = parseInt(interval.slice(0, -1), 10); | ||
const unit = interval.charAt(interval.length - 1); | ||
|
||
if (Number.isFinite(number)) { | ||
switch (unit) { | ||
case 's': { | ||
return i18n.SECONDS_SCREEN_READER(number); | ||
} | ||
case 'm': { | ||
return i18n.MINUTES_SCREEN_READER(number); | ||
} | ||
case 'h': { | ||
return i18n.HOURS_SCREEN_READER(number); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return undefined; | ||
}, [interval]); | ||
|
||
return ( | ||
<> | ||
<span data-test-subj="interval-abbr-value" aria-hidden={Boolean(screenReaderInterval)}> | ||
{interval} | ||
</span> | ||
{screenReaderInterval && ( | ||
<EuiScreenReaderOnly> | ||
<p>{screenReaderInterval}</p> | ||
</EuiScreenReaderOnly> | ||
)} | ||
</> | ||
); | ||
}; |
32 changes: 32 additions & 0 deletions
32
...lution/public/common/components/accessibility/interval_abbr_screen_reader/translations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const SECONDS_SCREEN_READER = (value: number) => | ||
i18n.translate('xpack.securitySolution.accessibility.intervalAbbrScreenReader.seconds', { | ||
defaultMessage: '{value} {value, plural, one { second } other { seconds }}', | ||
values: { | ||
value, | ||
}, | ||
}); | ||
|
||
export const MINUTES_SCREEN_READER = (value: number) => | ||
i18n.translate('xpack.securitySolution.accessibility.intervalAbbrScreenReader.minutes', { | ||
defaultMessage: '{value} {value, plural, one { minute } other { minutes }}', | ||
values: { | ||
value, | ||
}, | ||
}); | ||
|
||
export const HOURS_SCREEN_READER = (value: number) => | ||
i18n.translate('xpack.securitySolution.accessibility.intervalAbbrScreenReader.hours', { | ||
defaultMessage: '{value} {value, plural, one { hour } other { hours }}', | ||
values: { | ||
value, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.