Skip to content

Commit

Permalink
Removed deprecated props/logic from remaining components
Browse files Browse the repository at this point in the history
  • Loading branch information
thatblindgeye committed Nov 23, 2022
1 parent 50de1ff commit 21d98af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 58 deletions.
26 changes: 10 additions & 16 deletions packages/react-core/src/components/DataList/DataListDragButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from 'react';
import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/DataList/data-list';
import GripVerticalIcon from '@patternfly/react-icons/dist/esm/icons/grip-vertical-icon';
import { DataListContext } from './DataList';

export interface DataListDragButtonProps extends React.HTMLProps<HTMLButtonElement> {
/** Additional classes added to the drag button */
Expand All @@ -18,20 +17,15 @@ export const DataListDragButton: React.FunctionComponent<DataListDragButtonProps
isDisabled = false,
...props
}: DataListDragButtonProps) => (
<DataListContext.Consumer>
{({ dragKeyHandler }) => (
<button
className={css(styles.dataListItemDraggableButton, isDisabled && styles.modifiers.disabled, className)}
onKeyDown={dragKeyHandler}
type="button"
disabled={isDisabled}
{...props}
>
<span className={css(styles.dataListItemDraggableIcon)}>
<GripVerticalIcon />
</span>
</button>
)}
</DataListContext.Consumer>
<button
className={css(styles.dataListItemDraggableButton, isDisabled && styles.modifiers.disabled, className)}
type="button"
disabled={isDisabled}
{...props}
>
<span className={css(styles.dataListItemDraggableIcon)}>
<GripVerticalIcon />
</span>
</button>
);
DataListDragButton.displayName = 'DataListDragButton';
43 changes: 1 addition & 42 deletions packages/react-core/src/components/DataList/DataListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/DataList/data-list';
import { DataListContext } from './DataList';
import { KeyTypes } from '../../helpers/constants';
import { DataListDragButton, DataListDragButtonProps } from './DataListDragButton';

export interface DataListItemProps extends Omit<React.HTMLProps<HTMLLIElement>, 'children' | 'ref'> {
/** Flag to show if the expanded content of the DataList item is visible */
Expand All @@ -25,25 +24,6 @@ export interface DataListItemChildProps {
rowid: string;
}

function findDataListDragButton(node: React.ReactNode): React.ReactElement<DataListDragButtonProps> | null {
if (!React.isValidElement(node)) {
return null;
}
if (node.type === DataListDragButton) {
return node as React.ReactElement<DataListDragButtonProps>;
}
if (node.props.children) {
for (const child of React.Children.toArray(node.props.children)) {
const button = findDataListDragButton(child);
if (button) {
return button;
}
}
}

return null;
}

export class DataListItem extends React.Component<DataListItemProps> {
static displayName = 'DataListItem';
static defaultProps: DataListItemProps = {
Expand All @@ -65,16 +45,7 @@ export class DataListItem extends React.Component<DataListItemProps> {
} = this.props;
return (
<DataListContext.Consumer>
{({
isSelectable,
selectedDataListItemId,
updateSelectedDataListItem,
selectableRow,
isDraggable,
dragStart,
dragEnd,
drop
}) => {
{({ isSelectable, selectedDataListItemId, updateSelectedDataListItem, selectableRow }) => {
const selectDataListItem = (event: React.MouseEvent) => {
let target: any = event.target;
while (event.currentTarget !== target) {
Expand All @@ -98,17 +69,6 @@ export class DataListItem extends React.Component<DataListItemProps> {
}
};

// We made the DataListDragButton determine if the entire item is draggable instead of
// DataListItem like we should have.
// Recursively search children for the DataListDragButton and see if it's disabled...
const dragButton = findDataListDragButton(children);
const dragProps = isDraggable && {
draggable: dragButton ? !dragButton.props.isDisabled : true,
onDrop: drop,
onDragEnd: dragEnd,
onDragStart: dragStart
};

const isSelected = selectedDataListItemId === id;

const selectableInputAriaProps = selectableInputAriaLabel
Expand All @@ -129,7 +89,6 @@ export class DataListItem extends React.Component<DataListItemProps> {
{...(isSelectable && { tabIndex: 0, onClick: selectDataListItem, onKeyDown })}
{...(isSelectable && isSelected && { 'aria-selected': true })}
{...props}
{...dragProps}
>
{selectableRow && (
<input
Expand Down

0 comments on commit 21d98af

Please sign in to comment.