diff --git a/src/components/Table/hoc/withTableSelection/withTableSelection.tsx b/src/components/Table/hoc/withTableSelection/withTableSelection.tsx index 6a068dc8a2..77a29c94b6 100644 --- a/src/components/Table/hoc/withTableSelection/withTableSelection.tsx +++ b/src/components/Table/hoc/withTableSelection/withTableSelection.tsx @@ -203,20 +203,26 @@ export function withTableSelection( // eslint-disable-next-line @typescript-eslint/member-ordering private enhanceGetRowDescriptor = _memoize( (getRowDescriptor?: TableProps['getRowDescriptor']) => { - return (item: I, index: number) => { + const currentGetRowDescriptor: TableProps['getRowDescriptor'] = ( + item: I, + index: number, + ) => { const {selectedIds, getRowClassNames} = this.props; - const classNames = - getRowDescriptor?.(item, index)?.classNames?.slice() || - getRowClassNames?.(item, index) || - []; + const descriptor = getRowDescriptor?.(item, index) || {}; + + if (descriptor.classNames === undefined) { + descriptor.classNames = getRowClassNames?.(item, index) || []; + } const id = Table.getRowId(this.props, item, index); const selected = selectedIds.includes(id); - classNames.push(b('row', {selected})); + descriptor.classNames.push(b('row', {selected})); - return classNames; + return descriptor; }; + + return currentGetRowDescriptor; }, );