remove extra key handler on archive button (#13392)
This commit is contained in:
parent
924e41b843
commit
2998cb4555
2 changed files with 12 additions and 34 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue