Skip to content

Commit

Permalink
fix(a11y): make a short text for the clear button (#1172)
Browse files Browse the repository at this point in the history
  • Loading branch information
inigomontoya722 authored Nov 30, 2023
1 parent 504b05c commit d767727
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
10 changes: 4 additions & 6 deletions src/components/controls/TextArea/__tests__/TextArea.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,17 @@ describe('TextArea', () => {
render(<TextArea hasClear />);
const user = userEvent.setup();
const input = screen.getByRole('textbox');
let clearButton = screen.queryByRole('button', {name: 'Clear input value'});
let clearButton = screen.queryByRole('button', {name: 'Clear'});
expect(clearButton).not.toBeInTheDocument();
await user.type(input, 'abc');
clearButton = screen.queryByRole('button', {name: 'Clear input value'});
clearButton = screen.queryByRole('button', {name: 'Clear'});
expect(clearButton).toBeInTheDocument();
});

test('do not render clear button without hasClear prop', () => {
render(<TextArea />);

expect(
screen.queryByRole('button', {name: 'Clear input value'}),
).not.toBeInTheDocument();
expect(screen.queryByRole('button', {name: 'Clear'})).not.toBeInTheDocument();
});

test('call onChange when input changes value', () => {
Expand Down Expand Up @@ -79,7 +77,7 @@ describe('TextArea', () => {
render(<TextArea hasClear onChange={onChangeFn} />);
const input = screen.getByRole('textbox');
await user.type(input, 'abc');
const clear = screen.getByRole('button', {name: 'Clear input value'});
const clear = screen.getByRole('button', {name: 'Clear'});

if (clear) {
await user.click(clear);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,17 @@ describe('TextInput input', () => {
render(<TextInput hasClear />);
const user = userEvent.setup();
const input = screen.getByRole('textbox');
let clearButton = screen.queryByRole('button', {name: 'Clear input value'});
let clearButton = screen.queryByRole('button', {name: 'Clear'});
expect(clearButton).not.toBeInTheDocument();
await user.type(input, 'abc');
clearButton = screen.queryByRole('button', {name: 'Clear input value'});
clearButton = screen.queryByRole('button', {name: 'Clear'});
expect(clearButton).toBeInTheDocument();
});

test('do not render clear button without hasClear prop', () => {
render(<TextInput />);

expect(
screen.queryByRole('button', {name: 'Clear input value'}),
).not.toBeInTheDocument();
expect(screen.queryByRole('button', {name: 'Clear'})).not.toBeInTheDocument();
});

test('call onChange when input changes value', () => {
Expand Down Expand Up @@ -80,7 +78,7 @@ describe('TextInput input', () => {
render(<TextInput hasClear onChange={onChangeFn} />);
const input = screen.getByRole('textbox');
await user.type(input, 'abc');
const clear = screen.getByRole('button', {name: 'Clear input value'});
const clear = screen.getByRole('button', {name: 'Clear'});

if (clear) {
await user.click(clear);
Expand Down
2 changes: 1 addition & 1 deletion src/components/controls/common/ClearButton/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"label_clear-button": "Clear input value"
"label_clear-button": "Clear"
}
2 changes: 1 addition & 1 deletion src/components/controls/common/ClearButton/i18n/ru.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"label_clear-button": "Очистить введённое значение"
"label_clear-button": "Очистить"
}

0 comments on commit d767727

Please sign in to comment.