Skip to content

Commit

Permalink
refactor: added aria-label attribute for internal error icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Kharitonov committed Jan 31, 2024
1 parent 17b3e78 commit 6e33a2c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/components/Select/__tests__/Select.error.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';

import {render, screen} from '@testing-library/react';

import {CONTROL_ERROR_ICON_QA, CONTROL_ERROR_MESSAGE_QA} from '../../controls/utils';
import {CONTROL_ERROR_MESSAGE_QA} from '../../controls/utils';
import {Select} from '../Select';

describe('Select error', () => {
Expand Down Expand Up @@ -31,7 +31,7 @@ describe('Select error', () => {
<Select errorMessage="Some Error" validationState="invalid" errorPlacement="inside" />,
);

expect(screen.getByTestId(CONTROL_ERROR_ICON_QA)).toBeInTheDocument();
expect(screen.getByLabelText('Show popup with error info')).toBeInTheDocument();
});

test('do not show error message without error/errorMessage prop', () => {
Expand All @@ -55,12 +55,12 @@ describe('Select error', () => {
test('do not show error icon if error prop is an empty string', () => {
render(<Select error={''} errorPlacement="inside" />);

expect(screen.queryByTestId(CONTROL_ERROR_ICON_QA)).not.toBeInTheDocument();
expect(screen.queryByLabelText('Show popup with error info')).not.toBeInTheDocument();
});

test('do not show error icon if errorMessage prop is an empty string', () => {
render(<Select errorMessage={''} errorPlacement="inside" />);

expect(screen.queryByTestId(CONTROL_ERROR_ICON_QA)).not.toBeInTheDocument();
expect(screen.queryByLabelText('Show popup with error info')).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import isEmpty from 'lodash/isEmpty';

import {Icon} from '../../../Icon';
import {Popover} from '../../../Popover';
import {CONTROL_ERROR_ICON_QA} from '../../../controls/utils';
import type {CnMods} from '../../../utils/cn';
import {selectControlBlock, selectControlButtonBlock} from '../../constants';
import i18n from '../../i18n';
import type {
SelectProps,
SelectRenderClearArgs,
Expand Down Expand Up @@ -170,7 +170,7 @@ export const SelectControl = React.forwardRef<HTMLButtonElement, ControlProps>((

{errorMessage && (
<Popover content={errorMessage}>
<span data-qa={CONTROL_ERROR_ICON_QA}>
<span aria-label={i18n('label_show-error-info')}>
<Icon
data={TriangleExclamation}
className={selectControlBlock('error-icon')}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Select/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"label_clear": "Clear"
"label_clear": "Clear",
"label_show-error-info": "Show popup with error info"
}
3 changes: 2 additions & 1 deletion src/components/Select/i18n/ru.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"label_clear": "Очистить"
"label_clear": "Очистить",
"label_show-error-info": "Показать попап с информацей об ошибке"
}

0 comments on commit 6e33a2c

Please sign in to comment.