-
Notifications
You must be signed in to change notification settings - Fork 843
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
Support nodes in EuiBasicTable column headers #1234
Conversation
@@ -22,10 +22,6 @@ export class EuiTableSortMobile extends Component { | |||
}; | |||
} | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to remove this due to a circular dependency error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this again: JSON.stringify
can be fairly expensive, so this change might actually improve perf 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
@@ -100,27 +103,68 @@ export class Table extends Component { | |||
}, { | |||
field: 'github', | |||
name: 'Github', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you meant to remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name
property (name: 'Github',
)
@@ -22,10 +22,6 @@ export class EuiTableSortMobile extends Component { | |||
}; | |||
} | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be some other perf. optimisations we can do here (like PureComponent) but probably not necessary for this PR.
@@ -22,10 +22,6 @@ export class EuiTableSortMobile extends Component { | |||
}; | |||
} | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this again: JSON.stringify
can be fairly expensive, so this change might actually improve perf 🤔
@@ -100,27 +103,68 @@ export class Table extends Component { | |||
}, { | |||
field: 'github', | |||
name: 'Github', | |||
name: ( | |||
<EuiFlexGroup gutterSize="xs" alignItems="center"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add responsive={false}
to fix in mobile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -1,6 +1,6 @@ | |||
## [`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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you re-word to be past tense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean, could you give me an example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds support for nodes as column headers in
EuiBasicTable
for upporting things like tooltips and localized text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha nope!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added support for nodes as column headers in
EuiBasicTable
for upporting things like tooltips and localized text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha thanks, will update.
@@ -455,7 +455,6 @@ export default class extends Component { | |||
return ( | |||
<EuiTableRowCell | |||
key={column.id} | |||
header={column.label} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why you removed all these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
/** | |
* The column's header title for use in mobile view (will be added as a data-attr) | |
*/ | |
header: PropTypes.string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EuiTableRowCell
receives theheader
prop 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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