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

Have a way to prevent tables from overflowing by breaking words #5289

Open
frankieroberto opened this issue Sep 3, 2024 · 2 comments
Open
Labels
feature request User requests a new feature sass / css table

Comments

@frankieroberto
Copy link
Contributor

frankieroberto commented Sep 3, 2024

If you have a table containing a long string, such as an email address, then it can cause the table to extend beyond the width of its container:

Screenshot of a table containing a long email address which causes the right hand side of the table to extend out of the image

Adding the govuk-!-text-break-word class makes no difference in this scenario.

Ideally, the table would follow the pattern of the summary list component (which also looks table-like), and would have its contents break across multiple lines if needed to prevent the table overflowing.

@frankieroberto frankieroberto added awaiting triage Needs triaging by team feature request User requests a new feature labels Sep 3, 2024

This comment was marked as outdated.

@alphagov alphagov deleted a comment Sep 3, 2024
@querkmachine
Copy link
Member

querkmachine commented Sep 3, 2024

Note that this is a non-trivial change due to how these two things interact with one another.

  • word-break will only break a word when it is longer than the parent element's inline size.
  • a table cell, by default, will increase its inline size to fit the longest word inside of it (even if this means making the table wider than its container).

So, a bit of a Catch-22 there.

This can be fixed by applying table-layout: fixed to the table, which makes each column an fixed percentage of the table width and removes the ability for columns to resize themselves according to their content. Widths for each column can then be specified manually if some need to be wider than others.

There might be some funky way of specifying a width that permits resizing based on content (using fit-content or min-content keywords perhaps), but I couldn't find one that worked in my initial fiddling.

Using <wbr> or &shy; within the long word works without making any CSS alterations, but naturally comes with the cost of having to manipulate the table data to insert them.

@romaricpascal romaricpascal added table sass / css and removed awaiting triage Needs triaging by team labels Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request User requests a new feature sass / css table
Projects
None yet
Development

No branches or pull requests

3 participants