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

[EuiForm] Add a11y labels to the EuiCallOut for validation errors #4238

Merged
merged 1 commit into from
Nov 9, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Added `EuiColorPaletteDisplay` component ([#3865](https://github.com/elastic/eui/pull/3865))
- Added `initialFocusedItemIndex` support to `EuiContextMenuPanelDescriptor` ([#4223](https://github.com/elastic/eui/pull/4223))
- Added `role="alert"` and `aria-live="assertive"` to `EuiForm`'s `EuiCallOut` for the errors ([#4238](https://github.com/elastic/eui/pull/4238))

**Bug fixes**

Expand Down
105 changes: 105 additions & 0 deletions src/components/form/__snapshots__/form.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,111 @@ exports[`EuiForm renders a form element 1`] = `
/>
`;

exports[`EuiForm renders with error callout when isInvalid is "true" 1`] = `
<div
aria-label="aria-label"
class="euiForm testClass1 testClass2"
data-test-subj="test subject string"
>
<div
aria-live="assertive"
class="euiCallOut euiCallOut--danger euiForm__errors"
role="alert"
>
<div
class="euiCallOutHeader"
>
<span
class="euiCallOutHeader__title"
>
Please address the highlighted errors.
</span>
</div>
</div>
</div>
`;

exports[`EuiForm renders with error callout when isInvalid is "true" and has multiple errors 1`] = `
<div
aria-label="aria-label"
class="euiForm testClass1 testClass2"
data-test-subj="test subject string"
>
<div
aria-live="assertive"
class="euiCallOut euiCallOut--danger euiForm__errors"
role="alert"
>
<div
class="euiCallOutHeader"
>
<span
class="euiCallOutHeader__title"
>
Please address the highlighted errors.
</span>
</div>
<div
class="euiText euiText--small"
>
<ul>
<li
class="euiForm__error"
>
<span>
This is one error
</span>
</li>
<li
class="euiForm__error"
>
<span>
This is another error
</span>
</li>
</ul>
</div>
</div>
</div>
`;

exports[`EuiForm renders with error callout when isInvalid is "true" and has one error 1`] = `
<div
aria-label="aria-label"
class="euiForm testClass1 testClass2"
data-test-subj="test subject string"
>
<div
aria-live="assertive"
class="euiCallOut euiCallOut--danger euiForm__errors"
role="alert"
>
<div
class="euiCallOutHeader"
>
<span
class="euiCallOutHeader__title"
>
Please address the highlighted errors.
</span>
</div>
<div
class="euiText euiText--small"
>
<ul>
<li
class="euiForm__error"
>
<span>
This is one error
</span>
</li>
</ul>
</div>
</div>
</div>
`;

exports[`EuiForm renders without error callout when invalidCallout is "none" 1`] = `
<div
aria-label="aria-label"
Expand Down
30 changes: 30 additions & 0 deletions src/components/form/form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ describe('EuiForm', () => {

expect(component).toMatchSnapshot();
});
test('renders with error callout when isInvalid is "true"', () => {
const component = render(<EuiForm {...requiredProps} isInvalid />);

expect(component).toMatchSnapshot();
});
test('renders with error callout when isInvalid is "true" and has one error', () => {
const component = render(
<EuiForm
{...requiredProps}
isInvalid
error={<span>This is one error</span>}
/>
);

expect(component).toMatchSnapshot();
});
test('renders with error callout when isInvalid is "true" and has multiple errors', () => {
const component = render(
<EuiForm
{...requiredProps}
isInvalid
error={[
<span>This is one error</span>,
<span>This is another error</span>,
]}
/>
);

expect(component).toMatchSnapshot();
});
test('renders without error callout when invalidCallout is "none"', () => {
const component = render(
<EuiForm {...requiredProps} isInvalid invalidCallout="none" />
Expand Down
4 changes: 3 additions & 1 deletion src/components/form/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ export const EuiForm: FunctionComponent<EuiFormProps> = ({
<EuiCallOut
className="euiForm__errors"
title={addressFormErrors}
color="danger">
color="danger"
role="alert"
aria-live="assertive">
{optionalErrors}
</EuiCallOut>
)}
Expand Down