Add tableLayout prop to EuiTable, EuiBasicTable and EuiInMemoryTable#2697
Add tableLayout prop to EuiTable, EuiBasicTable and EuiInMemoryTable#2697andreadelrio merged 13 commits intoelastic:masterfrom
Conversation
src/components/table/table.tsx
Outdated
| TableHTMLAttributes<HTMLTableElement>; | ||
|
|
||
| const tableLayoutToClassMap: { [tableLayout: string]: string | null } = { | ||
| fixed: 'euiTable--fixed', |
There was a problem hiding this comment.
Since you're not actually using this class in the CSS, but the default .euiTable class gets the fixed layout and you're just overriding this with the auto class, you should just set this to null.
| fixed: 'euiTable--fixed', | |
| fixed: null, |
src/components/table/table.tsx
Outdated
| export type Props = { | ||
| compressed?: boolean; | ||
| responsive?: boolean; | ||
| tableLayout?: string; |
There was a problem hiding this comment.
All new props in TS need a comment explaining what it is. This helps consumers via their IDE's auto-complete. Probably just duplicate what was written in the props_info file.
src/components/table/_table.scss
Outdated
| &.euiTable--auto { | ||
| table-layout: auto; | ||
| } | ||
|
|
| return ( | ||
| <div> | ||
| <EuiSwitch | ||
| label="Show auto layout" |
There was a problem hiding this comment.
| label="Show auto layout" | |
| label="Auto layout" |
| <div> | ||
| <p> | ||
| <EuiCode>EuiBasicTable</EuiCode> has a fixed layout by default. You can | ||
| change it to auto using the <EuiCode>tableLayout</EuiCode> prop. |
There was a problem hiding this comment.
Seems like this description isn't enough to warrant an entire example in the docs? Consider beefing up this explanation or removing the example and just relying on props comments to explain the prop.
There was a problem hiding this comment.
Agree that a props comment is likely enough and this concept doesn't need a full example. Only alternative (which should be handled in a separate PR) would be to do something similar to EuiDataGrid where we devote a full section to styling concerns and add an example with lots of toggles.
There was a problem hiding this comment.
That was going to be my third suggestion, but figured it out of scope of this PR. So probably best to just remove this example for now.
| type: { name: '(criteria: #Criteria) => void' }, | ||
| }, | ||
| tableLayout: { | ||
| description: 'Configures table layout', |
There was a problem hiding this comment.
Probably want to explain that it's configuring the CSS table-layout property.
@cchaos With this I find myself in a loop: to truncate text we would need to set the cell width which would defeat the purpose of setting layout to auto in the first place? Is there any other way to look at it? I think that when the consumer wants some columns wider than others while still being able to use Auto layout ( Fixed layout ( Fixed layout with If we stick with this, I would add a note in the docs that |
I would do that, though it doesn't technically "override" truncateText, but it does inhibit it from calculating the other columns properly. This would then also warrant keeping the docs example so you can also add in this width to your example. |
@cchaos I've updated the example to look like this. Let me know what you think |
|
PR to simplify TypeScript type definitions and extensions: andreadelrio#5 |
TypeScript cleanup
cchaos
left a comment
There was a problem hiding this comment.
Looks good, just had a couple more suggestions for the doc example
| }, | ||
| tableLayout: { | ||
| description: | ||
| 'Sets the table-layout CSS property. Note that auto tableLayout prevents truncateText from working regularly.', |
There was a problem hiding this comment.
| 'Sets the table-layout CSS property. Note that auto tableLayout prevents truncateText from working regularly.', | |
| 'Sets the table-layout CSS property. Note that auto tableLayout prevents truncateText from working properly.', |
| const html = renderToHtml(Table); | ||
|
|
||
| export const section = { | ||
| title: 'A BasicTable with auto layout', |
There was a problem hiding this comment.
This section is no longer about just auto layout but layout in general
| title: 'A BasicTable with auto layout', | |
| title: 'Table layout', |
cchaos
left a comment
There was a problem hiding this comment.
Looks great! I think this PR satisfies the issue but pushes towards a better solution (using widths) in the docs.





Summary
This PR adds the
tableLayoutprop toEuiTablewhich in turns makes it available inEuiBasicTableandEuiInMemoryTable. The default value isfixedwith the option to change it toauto.I thought it'd be good to add a small example to the docs to show the new prop in action.
Fixes #461
Checklist
- [ ] Check against all themes for compatability in both light and dark modes- [ ] Checked in mobile- [ ] Checked for breaking changes and labeled appropriately- [ ] Checked for accessibility including keyboard-only and screenreader modes