remove extra key handler on archive button (#13392)

This commit is contained in:
Suzanne Aitchison 2021-04-14 13:34:47 +01:00 committed by GitHub
parent 924e41b843
commit 2998cb4555
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 34 deletions

View file

@ -9,26 +9,17 @@ import { h } from 'preact';
import PropTypes from 'prop-types';
import { Button } from '@crayons';
export const ItemListItemArchiveButton = ({ text, onClick }) => {
const onKeyUp = (e) => {
if (e.key === 'Enter') {
onClick(e);
}
};
return (
<Button
onClick={onClick}
onKeyUp={onKeyUp}
aria-label="Archive item"
role="button"
variant="ghost"
size="s"
>
{text}
</Button>
);
};
export const ItemListItemArchiveButton = ({ text, onClick }) => (
<Button
onClick={onClick}
aria-label="Archive item"
role="button"
variant="ghost"
size="s"
>
{text}
</Button>
);
ItemListItemArchiveButton.propTypes = {
text: PropTypes.string.isRequired,

View file

@ -1,5 +1,5 @@
import { h } from 'preact';
import { render, fireEvent } from '@testing-library/preact';
import { render } from '@testing-library/preact';
import { axe } from 'jest-axe';
import { ItemListItemArchiveButton } from '../ItemListItemArchiveButton';
@ -18,17 +18,4 @@ describe('<ItemListItemArchiveButton />', () => {
expect(queryByText(/archive/i)).toBeDefined();
});
it('triggers the onClick if the Enter key is pressed', () => {
const onClick = jest.fn();
const { getByRole } = render(
<ItemListItemArchiveButton text="archive" onClick={onClick} />,
);
fireEvent.keyUp(getByRole('button'), { key: 'Enter', code: 'Enter' });
expect(onClick).toHaveBeenCalledTimes(1);
fireEvent.keyUp(getByRole('button'), { key: 'Space', code: 'Space' });
expect(onClick).toHaveBeenCalledTimes(1);
});
});