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

Support nodes in EuiBasicTable column headers #1234

Merged
merged 6 commits into from
Oct 10, 2018

Conversation

cjcenizal
Copy link
Contributor

@cjcenizal cjcenizal commented Oct 4, 2018

Summary

Fixes #1002

image

Looks a bit weird on mobile:

image

Checklist

  • This was checked in mobile
  • This was checked in IE11
  • This was checked in dark mode
  • Any props added have proper autodocs
  • Documentation examples were added
  • A changelog entry exists and is marked appropriately
  • This was checked for breaking changes and labeled appropriately
  • Jest tests were updated or added to match the most common scenarios
  • This was checked against keyboard-only and screenreader scenarios

@@ -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);
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

@sorenlouv sorenlouv Oct 5, 2018

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 🤔

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

@sorenlouv sorenlouv left a 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',
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove what?

Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

@sorenlouv sorenlouv Oct 5, 2018

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">
Copy link
Contributor

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

Copy link
Contributor

@cchaos cchaos left a 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:

screen shot 2018-10-05 at 09 11 12 am


And in mobile, it's inline:

screen shot 2018-10-05 at 09 16 14 am


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)

@cjcenizal
Copy link
Contributor Author

@cchaos I really like your suggestion! I'll implement this.

@cjcenizal
Copy link
Contributor Author

@cchaos Done:

image

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))
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha nope!

Copy link
Contributor

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.

Copy link
Contributor Author

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}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

/**
* The column's header title for use in mobile view (will be added as a data-attr)
*/
header: PropTypes.string,

Copy link
Contributor

@cchaos cchaos Oct 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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.

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

Copy link
Contributor Author

@cjcenizal cjcenizal Oct 6, 2018

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.

src/components/basic_table/basic_table.js Show resolved Hide resolved
@cjcenizal
Copy link
Contributor Author

Thanks for the guidance @cchaos. I put the header prop back. Could you take a look and make sure I didn't miss anything? I also noticed that it was already defined as a propType, but I missed that the first time around somehow.

@cjcenizal cjcenizal merged commit aa50e32 into elastic:master Oct 10, 2018
@cjcenizal cjcenizal deleted the table-header-node-type branch October 10, 2018 14:40
@sorenlouv
Copy link
Member

sorenlouv commented Oct 10, 2018

🎉
Thanks @cjcenizal!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants