[fix] Enter key handling for components explicitly given accessible prop

Close #1783
This commit is contained in:
Charlie Croom
2020-10-26 20:54:04 -04:00
committed by Nicolas Gallagher
parent 63c39454de
commit d9c755dff0
2 changed files with 18 additions and 1 deletions
@@ -232,6 +232,18 @@ describe('modules/createDOMProps', () => {
expect(respondsToEnter('div', 'bogus')).toBe(false);
});
test('emulates "onClick" for "Enter" for items marked accessible', () => {
const onClick = jest.fn();
const event = { key: 'Enter', preventDefault: jest.fn() };
const finalProps = createDOMProps('div', {
accessible: true,
accessibilityRole: 'article',
onClick
});
finalProps.onKeyDown(event);
expect(onClick).toHaveBeenCalled();
});
test('emulates "onClick" for "Space" for certain roles', () => {
expect(respondsToSpace('div', 'button')).toBe(true);
expect(respondsToSpace('div', 'menuitem')).toBe(true);
@@ -225,7 +225,12 @@ const createDOMProps = (component, props) => {
// Keyboard accessibility
// Button-like roles should trigger 'onClick' if SPACE key is pressed.
// Button-like roles should not trigger 'onClick' if they are disabled.
if (isNativeInteractiveElement || role === 'button' || role === 'menuitem') {
if (
isNativeInteractiveElement ||
role === 'button' ||
role === 'menuitem' ||
(accessible === true && focusable)
) {
const onClick = domProps.onClick;
if (onClick != null) {
if (disabled) {