Skip to content
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

Introduce Column headerStyle #877

Merged
merged 2 commits into from
Nov 25, 2017
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
1 change: 1 addition & 0 deletions docs/Column.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Describes the header and cell contents of a table column.
| flexShrink | Number | | Flex shrink style; defaults to 1 |
| headerClassName | String | | CSS class to apply to this column's header |
| headerRenderer | Function | | Optional callback responsible for rendering a column's header column. [Learn more](#headerrenderer) |
| headerStyle | Object | | Optional inline style to apply to this column's header |
| id | String | | Optional id to set on the column header; used for [`aria-describedby`](https://www.w3.org/TR/wai-aria/states_and_properties#aria-describedby) |
| label | Node | | Header label for this column |
| maxWidth | Number | | Maximum width of column; this property will only be used if :flexGrow is greater than 0 |
Expand Down
3 changes: 3 additions & 0 deletions source/Table/Column.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export default class Column extends Component {
*/
headerRenderer: PropTypes.func.isRequired,

/** Optional inline style to apply to this column's header */
headerStyle: PropTypes.object,

/** Optional id to set on the column header */
id: PropTypes.string,

Expand Down
8 changes: 8 additions & 0 deletions source/Table/Table.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('Table', () => {
columnData = {data: 123},
columnID,
columnStyle,
columnHeaderStyle,
disableSort = false,
headerRenderer,
maxWidth,
Expand Down Expand Up @@ -74,6 +75,7 @@ describe('Table', () => {
disableSort={disableSort}
defaultSortDirection={defaultSortDirection}
style={columnStyle}
headerStyle={columnHeaderStyle}
id={columnID}
/>
<Column
Expand Down Expand Up @@ -1048,13 +1050,15 @@ describe('Table', () => {
it('should use custom :styles if specified', () => {
const columnStyle = {backgroundColor: 'red'};
const headerStyle = {backgroundColor: 'blue'};
const columnHeaderStyle = {color: 'yellow'};
const rowStyle = {backgroundColor: 'green'};
const style = {backgroundColor: 'orange'};
const node = findDOMNode(
render(
getMarkup({
columnStyle,
headerStyle,
columnHeaderStyle,
rowStyle,
style,
}),
Expand All @@ -1068,6 +1072,10 @@ describe('Table', () => {
node.querySelector('.ReactVirtualized__Table__headerColumn').style
.backgroundColor,
).toEqual('blue');
expect(
node.querySelector('.ReactVirtualized__Table__headerColumn').style
.color,
).toEqual('yellow');
expect(
node.querySelector('.ReactVirtualized__Table__row').style
.backgroundColor,
Expand Down
5 changes: 4 additions & 1 deletion source/Table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,10 @@ export default class Table extends PureComponent {
ReactVirtualized__Table__sortableHeaderColumn: sortEnabled,
},
);
const style = this._getFlexStyleForColumn(column, headerStyle);
const style = this._getFlexStyleForColumn(column, {
...headerStyle,
...column.props.headerStyle,
});

const renderedHeader = headerRenderer({
columnData,
Expand Down