Support nodes in EuiBasicTable column headers#1234
Conversation
| } | ||
|
|
||
| shouldComponentUpdate(nextProps, nextState) { | ||
| return JSON.stringify(nextProps) !== JSON.stringify(this.props) || JSON.stringify(nextState) !== JSON.stringify(this.state); |
There was a problem hiding this comment.
Had to remove this due to a circular dependency error.
There was a problem hiding this comment.
There might be some other perf. optimisations we can do here (like PureComponent) but probably not necessary for this PR.
There was a problem hiding this comment.
Thinking about this again: JSON.stringify can be fairly expensive, so this change might actually improve perf 🤔
There was a problem hiding this comment.
Good point! Ironic. 😄 I wasn't sure if PureComponent was a good choice since it does a shallow compare and we might run into some issues with items but we can investigate later.
There was a problem hiding this comment.
Yeah React recommends against using JSON.stringify in shouldComponentUpdate anyway:
We do not recommend doing deep equality checks or using JSON.stringify() in shouldComponentUpdate(). It is very inefficient and will harm performance.
https://reactjs.org/docs/react-component.html#shouldcomponentupdate
| @@ -100,27 +103,68 @@ export class Table extends Component { | |||
| }, { | |||
| field: 'github', | |||
| name: 'Github', | |||
There was a problem hiding this comment.
I guess you meant to remove this?
There was a problem hiding this comment.
The name property (name: 'Github',)
| } | ||
|
|
||
| shouldComponentUpdate(nextProps, nextState) { | ||
| return JSON.stringify(nextProps) !== JSON.stringify(this.props) || JSON.stringify(nextState) !== JSON.stringify(this.state); |
There was a problem hiding this comment.
There might be some other perf. optimisations we can do here (like PureComponent) but probably not necessary for this PR.
| } | ||
|
|
||
| shouldComponentUpdate(nextProps, nextState) { | ||
| return JSON.stringify(nextProps) !== JSON.stringify(this.props) || JSON.stringify(nextState) !== JSON.stringify(this.state); |
There was a problem hiding this comment.
Thinking about this again: JSON.stringify can be fairly expensive, so this change might actually improve perf 🤔
| field: 'github', | ||
| name: 'Github', | ||
| name: ( | ||
| <EuiFlexGroup gutterSize="xs" alignItems="center"> |
There was a problem hiding this comment.
Add responsive={false} to fix in mobile
There was a problem hiding this comment.
I played around with some different ways to add this particular functionality (tooltip to give more info on header) and my feeling is that only having the more tooltip on the icon is both causing rendering issues (mobile) and functional issues (truncation can cause it to not be visible). My solution is to just wrap the entire contents of the header in a tooltip and just append a small, subdued question icon mainly as an indicator.
name: (
<EuiToolTip content="Colloquially known as a 'birthday'">
<span>
Date of Birth <EuiIcon size="s" color="subdued" type="questionInCircle" />
</span>
</EuiToolTip>
),
This means if the header is truncated, you'll still get the tooltip:
And in mobile, it's inline:
Side notes
- the vertical alignment is not great on small icons, but that's something we need to fix with icons themselves
- truncation isn't great when it ends in an icon as the ellipses can be on top of the icon, but that's not easily fixed (unless someone knows how)
|
@cchaos I really like your suggestion! I'll implement this. |
|
@cchaos Done: |
CHANGELOG.md
Outdated
| ## [`master`](https://github.com/elastic/eui/tree/master) | ||
|
|
||
| No public interface changes since `4.4.1`. | ||
| - `EuiBasicTable` accepts nodes as column headers, for supporting things like tooltips and localized text ([#1234](https://github.com/elastic/eui/pull/1234)) |
There was a problem hiding this comment.
Can you re-word to be past tense?
There was a problem hiding this comment.
Not sure what you mean, could you give me an example?
There was a problem hiding this comment.
Adds support for nodes as column headers in
EuiBasicTablefor upporting things like tooltips and localized text.
There was a problem hiding this comment.
Added support for nodes as column headers in
EuiBasicTablefor upporting things like tooltips and localized text.
There was a problem hiding this comment.
Haha thanks, will update.
| return ( | ||
| <EuiTableRowCell | ||
| key={column.id} | ||
| header={column.label} |
There was a problem hiding this comment.
Is there a reason why you removed all these?
There was a problem hiding this comment.
Sorry I should have explained this in the PR description. I came across this and noticed that it's not the correct attribute name (it should be headers). But after some more digging it looks like this is not a recommend practice and isn't even necessary for accessibility. VoiceOver reads the header value for each cell just fine. So after chatting with @lukeelmers we decided to just remove them.
There was a problem hiding this comment.
EuiTableRowCell receives the header prop for displaying the table header inline for mobile. It could probably use a better name (this was one of my early foray's into React). But it is necessary.
eui/src/components/table/table_row_cell.js
Lines 87 to 90 in 0cf8fde
There was a problem hiding this comment.
EuiTableRowCellreceives theheaderprop for displaying the table header inline for mobile.
Ahhhh that makes much more sense then! @cjcenizal and I were going back and forth on this and assumed it was intended to be an actual headers attribute and was actually a typo.
It could probably use a better name
+1 -- I think that could help prevent confusion in the future
There was a problem hiding this comment.
Yup what Luke said! I'll put it back in the meantime and add it to the propTypes definition if it's not already there.
|
Thanks for the guidance @cchaos. I put the |
|
🎉 |



Summary
Fixes #1002
Looks a bit weird on mobile:
Checklist