Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/module/src/ListManager/ListManager.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ describe('ListManager', () => {
});

describe('enableDragDrop prop', () => {
it('places checkboxes in DataListControl so they share spacing with the drag handle', () => {
render(<ListManager columns={mockColumns} />);
const checkbox = screen.getByTestId('column-check-name');
expect(checkbox.closest('.pf-v6-c-data-list__item-control')).toBeInTheDocument();
expect(checkbox.closest('.pf-v6-c-data-list__item-row')).not.toBeInTheDocument();
});

it('keeps non-draggable rows in DataListItemRow', () => {
render(<ListManager columns={mockColumns} enableDragDrop={false} />);
const checkbox = screen.getByTestId('column-check-name');
expect(checkbox.closest('.pf-v6-c-data-list__item-row')).toBeInTheDocument();
});

it('should sync columns when props change', async () => {
const { rerender } = render(<ListManager columns={mockColumns} enableDragDrop={false} />);

Expand Down
57 changes: 38 additions & 19 deletions packages/module/src/ListManager/ListManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DataListItem,
DataListItemRow,
DataListCheck,
DataListControl,
DataListCell,
DataListItemCells,
Button,
Expand Down Expand Up @@ -111,29 +112,47 @@ const ListManager: FunctionComponent<ListManagerProps> = (
onSelectAll?.(newColumns);
};

const renderColumnCheck = (column: ListManagerItem & { id: string }, index: number, otherControls = false) => (
<DataListCheck
data-testid={`column-check-${column.key}`}
otherControls={otherControls}
isChecked={column.isSelected}
onChange={() => handleChange(column.key)}
isDisabled={column.isUntoggleable}
ouiaId={`${ouiaId}-column-${index}-checkbox`}
id={`${ouiaId}-column-${index}-checkbox`}
aria-labelledby={`${ouiaId}-column-${index}-label`}
/>
);

const renderColumnCells = (column: ListManagerItem & { id: string }, index: number) => (
<DataListItemCells
dataListCells={[
<DataListCell key={column.key} data-ouia-component-id={`${ouiaId}-column-${index}-label`}>
<label htmlFor={`${ouiaId}-column-${index}-checkbox`}>
{column.title}
</label>
</DataListCell>
]}
/>
);

const renderDataListItem = (column: ListManagerItem & { id: string }, index: number) => (
<DataListItemRow key={column.key}>
<DataListCheck
data-testid={`column-check-${column.key}`}
isChecked={column.isSelected}
onChange={() => handleChange(column.key)}
isDisabled={column.isUntoggleable}
ouiaId={`${ouiaId}-column-${index}-checkbox`}
id={`${ouiaId}-column-${index}-checkbox`}
aria-labelledby={`${ouiaId}-column-${index}-label`}
/>
<DataListItemCells
dataListCells={[
<DataListCell key={column.key} data-ouia-component-id={`${ouiaId}-column-${index}-label`}>
<label htmlFor={`${ouiaId}-column-${index}-checkbox`}>
{column.title}
</label>
</DataListCell>
]}
/>
{renderColumnCheck(column, index)}
{renderColumnCells(column, index)}
</DataListItemRow>
);

const renderDraggableDataListItem = (column: ListManagerItem & { id: string }, index: number) => (
<>
<DataListControl>
{renderColumnCheck(column, index, true)}
</DataListControl>
{renderColumnCells(column, index)}
</>
);

return (
<>
<div style={{ paddingBlockEnd: 'var(--pf-t--global--spacer--md)' }}>
Expand All @@ -152,7 +171,7 @@ const ListManager: FunctionComponent<ListManagerProps> = (
{enableDragDrop ? (
<DragDropSort
variant="DataList"
items={currentColumns.map((column, index) => ({ id: column.key, content: renderDataListItem(column, index) }))}
items={currentColumns.map((column, index) => ({ id: column.key, content: renderDraggableDataListItem(column, index) }))}
onDrop={onDrag}
overlayProps={{ isCompact: true }}
>
Expand Down
Loading