Skip to content

Commit cd59c2f

Browse files
authored
fix(DataList): allow keyboard to trigger DataListActions (#11974)
* fix(DataList): allow keyboard to trigger DataListActions * fix - ignore menu item events in datalist
1 parent 4385077 commit cd59c2f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/react-core/src/components/DataList/DataListItem.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Children, Component, cloneElement, isValidElement } from 'react';
22
import { css } from '@patternfly/react-styles';
33
import styles from '@patternfly/react-styles/css/components/DataList/data-list';
4+
import menuStyles from '@patternfly/react-styles/css/components/Menu/menu';
45
import { DataListContext } from './DataList';
56
import { KeyTypes } from '../../helpers/constants';
67

@@ -65,6 +66,17 @@ class DataListItem extends Component<DataListItemProps> {
6566

6667
const onKeyDown = (event: React.KeyboardEvent) => {
6768
if ([KeyTypes.Enter, KeyTypes.Space].includes(event.key)) {
69+
const target: any = event.target as HTMLElement;
70+
71+
if (
72+
target.closest(`.${menuStyles.menuItem}`) ||
73+
target.parentNode.classList.contains(styles.dataListItemAction) ||
74+
target.parentNode.classList.contains(styles.dataListItemControl)
75+
) {
76+
// check other event handlers are not present.
77+
return;
78+
}
79+
6880
event.preventDefault();
6981
updateSelectedDataListItem(event, id);
7082
}

0 commit comments

Comments
 (0)