mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-02 02:25:22 +00:00
[fix] Enter key handling for components explicitly given accessible prop
Close #1783
This commit is contained in:
committed by
Nicolas Gallagher
parent
63c39454de
commit
d9c755dff0
@@ -232,6 +232,18 @@ describe('modules/createDOMProps', () => {
|
|||||||
expect(respondsToEnter('div', 'bogus')).toBe(false);
|
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', () => {
|
test('emulates "onClick" for "Space" for certain roles', () => {
|
||||||
expect(respondsToSpace('div', 'button')).toBe(true);
|
expect(respondsToSpace('div', 'button')).toBe(true);
|
||||||
expect(respondsToSpace('div', 'menuitem')).toBe(true);
|
expect(respondsToSpace('div', 'menuitem')).toBe(true);
|
||||||
|
|||||||
@@ -225,7 +225,12 @@ const createDOMProps = (component, props) => {
|
|||||||
// Keyboard accessibility
|
// Keyboard accessibility
|
||||||
// Button-like roles should trigger 'onClick' if SPACE key is pressed.
|
// Button-like roles should trigger 'onClick' if SPACE key is pressed.
|
||||||
// Button-like roles should not trigger 'onClick' if they are disabled.
|
// 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;
|
const onClick = domProps.onClick;
|
||||||
if (onClick != null) {
|
if (onClick != null) {
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
|
|||||||
Reference in New Issue
Block a user