Skip to content

Commit 790ed0a

Browse files
committed
fix(table): only renders the action column when function or non empty array as actions prop
1 parent 9045884 commit 790ed0a

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

demo/TableExamples.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export function TableExamples() {
143143
striped={false}
144144
bordered={true}
145145
rowClass={(doc) => (doc.b % 2 === 1 ? 'table-primary' : '')}
146+
actions={[]}
146147
/>
147148
</div>
148149

src/table/Table.jsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import { isArray, isFunction } from 'js-var-type';
34
import { TableHead } from './TableHead';
45
import { TableBody } from './TableBody';
56
import { normalizeColumns } from './table-helpers';
@@ -31,11 +32,13 @@ export function Table({
3132
dark && 'table-dark',
3233
]);
3334

35+
const hasActions = isFunction(actions) || (isArray(actions) && actions.length > 0);
36+
3437
return (
3538
<div className="table-responsive">
3639
<table className={tableClasses}>
3740
{caption && <caption>{caption}</caption>}
38-
<TableHead {...{ actionLabel, columnHeaderFormat, hasActions: Boolean(actions) }} columns={normalizedColumns} />
41+
<TableHead {...{ actionLabel, columnHeaderFormat, hasActions }} columns={normalizedColumns} />
3942
<TableBody {...{ docs, rowClass, actions, onRowClick }} columns={normalizedColumns} />
4043
</table>
4144
</div>

src/table/TableActions.jsx

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export function TableActions({ doc, docIndex, actions }) {
1111

1212
const normalizedActions = normalizeAction(actions, doc, docIndex);
1313

14+
if (normalizedActions.length === 0) {
15+
return null;
16+
}
17+
1418
return (
1519
<td className="text-center">
1620
{normalizedActions.map((action, actionIndex) => (

0 commit comments

Comments
 (0)