Skip to content

Commit

Permalink
[EuiForm] Add a11y labels to the EuiCallOut for validation errors (#4238
Browse files Browse the repository at this point in the history
)
  • Loading branch information
afharo authored Nov 9, 2020
1 parent fca50a4 commit ace700d
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 1 deletion.
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

0 comments on commit ace700d

Please sign in to comment.