SAP / ui5-webcomponents

UI5 Web Components - the enterprise-flavored sugar on top of native APIs! Build SAP Fiori user interfaces with the technology of your choice.
https://sap.github.io/ui5-webcomponents/
Apache License 2.0
1.51k stars 263 forks source link

[SF] Table - When the column header labels are very long, show them as truncated text instead of increasing the table header height to accommodate them #5268

Closed Vir-Mittal closed 2 years ago

Vir-Mittal commented 2 years ago

Feature Request Description

Sandbox - https://codesandbox.io/s/table-with-long-column-header-labels-vdrofi?file=/src/App.js

For the Table component, when very long labels are used for the column headers and the screen width is large, the column headers are displayed as expected, taking up as much space as possible -

Table long column labels with large width

However, when the screen width is small, the table header height increases in order to accommodate the long labels -

Table long column labels with small width

Instead of increasing the column header height, would it be possible to show the long labels as truncated text instead, something like this -

Table columns labels with truncated text

This would be similar to how other components such as the Card Header show truncated text when the text is too long

Proposed Solution

Instead of increasing the column header height, would it be possible to show the long labels as truncated text instead, something like this -

Table columns labels with truncated text

Priority

A clear and concise description of the impact/urgency of the required feature.

Stakeholder Info (if applicable)

terezamch commented 2 years ago

Hello @SAP/ui5-webcomponents-topic-rl,

The reporter requests truncation behaviour of the column text of the table. Could you please process the feature request?

Best regards, Tereza

nikolay-kolarov commented 2 years ago

Hello,

You can use a label in the column to control the wrapping. For example:

<Label wrappingType="Normal">
    {col.label}
</Label>

Keep in mind that the tooltip is not accessible on mobile devices, so you will get into an accessibility issue due to the truncation.

Best Regards, Nikolay

Vir-Mittal commented 2 years ago

Hello @nikolay-kolarov,

Sorry I'm not sure if I missed something but when I tried to use a label in the column with wrappingType="None", instead of truncating the text, the table gets a horizontal scrollbar -

https://codesandbox.io/s/table-with-long-column-header-labels-vdrofi?file=/src/App.js

I also tried restricting the width of the table/columns but it did not help either.

Is there another way around this to achieve the truncation behaviour?

Thank you

nikolay-kolarov commented 2 years ago

Hi @Vir-Mittal ,

You have not imported the css. And you can use the exposed part "column" to style the column (e.g. #tbl ui5-table-column::part(column) { ....). Please check the API for more info https://sap.github.io/ui5-webcomponents/master/playground/components/Table/

Best Regards, Nikolay

Vir-Mittal commented 2 years ago

Hi @nikolay-kolarov,

Thank you for your help. We tried implementing the truncation as you suggested and on first glance it seemed to be working alright. However, we found that we need to customize the max-width of the column to say 100 px and when the screen size/table size changes, this causes issues because for small screen widths, it just ends up adding a scroll bar which is not ideal. So, a fixed max-width would not work in this case.

You can see this behaviour in this sandbox - https://codesandbox.io/s/table-with-long-column-header-labels-vdrofi?file=/src/styles.module.css

Works fine with some screen sizes -

Screen Shot 2022-06-14 at 3 03 14 PM

Does not works when screen width is small, ends up adding a scroll bar -

Screen Shot 2022-06-14 at 3 03 52 PM

Is there a way for you to add the truncation as part of the component so that we can avoid using these customizations?

Best, Vir

Vir-Mittal commented 2 years ago

@nikolay-kolarov @terezamch Hi, just following up, is there any update on this?