Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,33 @@ describe('enhanceColumnsWithSmartFiltering', () => {
});
});

describe('radio filterFn', () => {
const col = { id: 'gender', meta: { filterVariant: 'radio' } };
const [enhanced] = enhanceColumnsWithSmartFiltering([col]);

it('matches exact value only, not substrings', () => {
const maleRow = { getValue: () => 'Male' };
const femaleRow = { getValue: () => 'Female' };
expect(enhanced.filterFn(maleRow, 'gender', '')).toBe(true);
expect(enhanced.filterFn(maleRow, 'gender', 'Male')).toBe(true);
expect(enhanced.filterFn(femaleRow, 'gender', 'Male')).toBe(false);
expect(enhanced.filterFn(femaleRow, 'gender', 'Female')).toBe(true);
});
});

describe('select filterFn', () => {
const col = { id: 'location', meta: { filterVariant: 'select' } };
const [enhanced] = enhanceColumnsWithSmartFiltering([col]);

it('matches exact value only, not substrings', () => {
const newYorkRow = { getValue: () => 'New York' };
const yorkRow = { getValue: () => 'York' };
expect(enhanced.filterFn(newYorkRow, 'location', null)).toBe(true);
expect(enhanced.filterFn(newYorkRow, 'location', 'York')).toBe(false);
expect(enhanced.filterFn(yorkRow, 'location', 'York')).toBe(true);
});
});

describe('time filterFn', () => {
const col = { id: 'time', meta: { filterVariant: 'time' } };
const [enhanced] = enhanceColumnsWithSmartFiltering([col]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('stickyColumnHelpers', () => {
borderLeft: 0,
left: '24px',
right: undefined,
opacity: 0.95,
position: 'sticky',
width: '180px',
minWidth: '180px',
Expand All @@ -50,7 +49,6 @@ describe('stickyColumnHelpers', () => {
borderLeft: '1px solid var(--cds-border-subtle)',
left: undefined,
right: '36px',
opacity: 0.95,
position: 'sticky',
width: '120px',
minWidth: '120px',
Expand All @@ -75,7 +73,6 @@ describe('stickyColumnHelpers', () => {
borderLeft: 0,
left: undefined,
right: undefined,
opacity: 1,
position: 'relative',
zIndex: 0,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,20 @@ export const enhanceColumnsWithSmartFiltering = (columns) => {
};
}

// NOTE: Radio / select filter — filterValue is one exact option from the column's unique
// values. The default string filter uses "includes", so "Male" would also match "Female".
if (filterVariant === 'radio' || filterVariant === 'select') {
return {
...column,
filterFn: (row, columnId, filterValue) => {
if (filterValue === '' || filterValue === undefined || filterValue === null) {
return true;
}
return String(row.getValue(columnId)) === String(filterValue);
},
};
}

// NOTE: Time filter — filterValue is a string like "09:30 AM".
// Raw column value is typically "09:30" (HH:MM, no period).
// Match if the raw value is contained within the filter string or vice-versa.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const getCommonPinningStyles = (column, isHeader = false) => {
: 0,
left: isPinned === 'left' ? `${column.getStart('left')}px` : undefined,
right: isPinned === 'right' ? `${column.getAfter('right')}px` : undefined,
opacity: isPinned ? 0.95 : 1,
position: isPinned ? 'sticky' : 'relative',
/* NOTE: Pinned (sticky) columns always need an explicit width and min-width so that:
1. The cell does not grow/shrink with its content — sticky cells must be fixed-size.
Expand Down
Loading