Skip to content

fix(Table) allow empty labels #1587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2018
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
2 changes: 1 addition & 1 deletion src/components/table/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ The following field properties are recognized:
| Property | Type | Description
| ---------| ---- | -----------
| `key` | String | The key for selecting data from the record in the items array. Required when passing the props `fields` an array of objects.
| `label` | String | Appears in the columns table header (and footer if `foot-clone` is set). Defaults to the field's key (in humanized format) if not provided.
| `label` | String | Appears in the columns table header (and footer if `foot-clone` is set). Defaults to the field's key (in humanized format) if not provided. It's possible to use empty labels by assigning an empty string `""`
| `class` | String or Array | Class name (or array of class names) to add to `<th>` **and** `<td>` in the column.
| `formatter` | String or Function | A formatter callback function, can be used instead of (or in conjunction with) slots for real table fields (i.e. fields, that have corresponding data at items array). Refer to [**Custom Data Rendering**](#custom-data-rendering) for more details.
| `sortable` | Boolean | Enable sorting on this column. Refer to the [**Sorting**](#sorting) Section for more details.
Expand Down
5 changes: 2 additions & 3 deletions src/components/table/table.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import startCase from 'lodash.startcase'

import looseEqual from '../../utils/loose-equal'
import stableSort from '../../utils/stable-sort'
import KeyCodes from '../../utils/key-codes'
Expand Down Expand Up @@ -763,12 +762,12 @@ export default {
fields.push({ key: k, label: startCase(k) })
})
}
// Ensure we have a unique array of fields and that they have labels
// Ensure we have a unique array of fields and that they have String labels
const memo = {}
return fields.filter(f => {
if (!memo[f.key]) {
memo[f.key] = true
f.label = f.label || startCase(f.key)
f.label = typeof f.label === 'string' ? f.label : startCase(f.key)
return true
}
return false
Expand Down