Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('is triggered by ESC keydown', () => {
const { getByTestId } = render();
fireEvent.keyDown(getByTestId('modal'), { keyCode: KEY_CODES.ESCAPE });
expect(onCloseSpy).toHaveBeenCalled();
});
});
it('closes datepicker when correct keys are used', () => {
const { getByTestId, queryByTestId } = render(
);
const input = getByTestId('input');
fireEvent.mouseDown(getByTestId('input'));
fireEvent.click(input);
fireEvent.keyDown(input, { keyCode: KEY_CODES.ESCAPE });
expect(queryByTestId('datepicker-menu')).toBeNull();
fireEvent.mouseDown(getByTestId('input'));
fireEvent.click(input);
fireEvent.keyDown(input, { keyCode: KEY_CODES.ENTER });
expect(queryByTestId('datepicker-menu')).toBeNull();
});
it('closes modal when ESC is pressed', () => {
const { getByTestId } = render();
fireEvent.keyDown(getByTestId('modal'), { keyCode: KEY_CODES.ESCAPE });
expect(onCloseSpy).toHaveBeenCalled();
});
onKeyDown: composeEventHandlers(onKeyDown, (event: KeyboardEvent) => {
if (event.keyCode === KEY_CODES.ESCAPE && visibility) {
closeTooltip(0);
}
}),
'aria-describedby': _id,
onKeyDown: composeEventHandlers(onKeyDown, (event: KeyboardEvent) => {
if (event.keyCode === KEY_CODES.ESCAPE) {
closeModal(event);
}
}),
...other
onKeyDown: e => {
switch (e.keyCode) {
case KEY_CODES.ESCAPE:
case KEY_CODES.ENTER:
dispatch({ type: 'CLOSE' });
break;
case KEY_CODES.UP:
case KEY_CODES.DOWN:
case KEY_CODES.SPACE:
dispatch({ type: 'OPEN' });
break;
}
},
autoComplete: 'off',