alphagov / govuk-frontend

GOV.UK Frontend contains the code you need to start building a user interface for government platforms and services.
https://frontend.design-system.service.gov.uk/
MIT License
1.18k stars 322 forks source link

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

Open frankieroberto opened 2 months ago

frankieroberto commented 2 months ago

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.

github-actions[bot] commented 2 months ago

Uh oh! @frankieroberto, the image you shared is missing helpful alt text. Check your issue body.

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

🤖 Beep boop! This comment was added automatically by github/accessibility-alt-text-bot.

querkmachine commented 2 months ago

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

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.