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

Table Block: Table Headers shouldn't default to break-word #24393

Closed
Tracked by #32400
supernovia opened this issue Aug 6, 2020 · 4 comments
Closed
Tracked by #32400

Table Block: Table Headers shouldn't default to break-word #24393

supernovia opened this issue Aug 6, 2020 · 4 comments
Labels
[Block] Table Affects the Table Block Needs Design Feedback Needs general design feedback. [Status] In Progress Tracking issues with work in progress [Status] Needs More Info Follow-up required in order to be actionable.

Comments

@supernovia
Copy link

Describe the bug
Table Headers (th tags) are explicitly set to break words, which can cause the table to look weird if the columns should have different widths. The screenshots say it best.

To reproduce
Steps to reproduce the behavior:

  1. Create a new table in a post or page. For example, try "Workshop, Ages, Description, Times" as table headers. Add a few rows with data a table like that might have.
  2. Make sure cells are not "Fixed" (as that for now means "evenly distributed" which would not be best for this table)
  3. Publish (or preview) the page.

Expected behavior
In the editor, I see the expected behavior:
Screen Shot 2020-08-05 at 6 03 32 PM

The table columns adjust to fit the content.

But, depending on the theme's content width, the table headings may break in awkward ways. See screenshots below from a handful of themes.

Screenshots
Screen Shot 2020-08-05 at 6 05 10 PM

Screen Shot 2020-08-05 at 6 08 13 PM

Screen Shot 2020-08-05 at 6 12 21 PM

Editor version (please complete the following information):
Gutenberg plugin 8.3.0 (also happens without it)

Desktop (please complete the following information):

  • OS: MacOS Current
  • Browser: Chrome Current

(But break-word seems to happen regardless of browser, because we specified it in the CSS.)

Additional context
This came up in a support request on the .com forums. Normally we'd just tell them to edit the HTML to adjust the width for that cell, but right now the block doesn't want to accept any HTML editing.

I can see we explicitly opted to break-words, possibly to avoid long links making widths too wide if people paste long links in the table data. But, could we at least not break the headers? This fixes the issue nicely:

.wp-block-table.aligncenter th {
    word-break: normal;
}

supernovia added a commit to supernovia/gutenberg that referenced this issue Aug 6, 2020
Fixing WordPress#24393

Can we just keep normal word-break with table headers?  I can think of cases where folks might paste a long URL in a table cell, and would need to wrap that. But I would think most people would just name the table header differently if it were too long to fit.  As it stands, this arbitrary break points truly are arbitrary, and it's turning out some strange results.
@talldan
Copy link
Contributor

talldan commented Aug 7, 2020

When testing, I could only reproduce this if the table block has an alignment (e.g. align center). When not aligned the table block should be scrollable horizontally.

@talldan talldan added [Block] Table Affects the Table Block Needs Design Feedback Needs general design feedback. labels Aug 14, 2020
@supernovia
Copy link
Author

Sorry I'm just seeing this. The table headers are aligned center by default, correct?

@skorasaurus skorasaurus added the [Status] In Progress Tracking issues with work in progress label Jul 12, 2021
@t-hamano
Copy link
Contributor

t-hamano commented Feb 4, 2023

Hi @supernovia,

Sorry for the delay in my investigation into this issue.

In the table block, no text-align property is set for the cells. Therefore, the table header cell text will be centered according to the browser's default style. And word-break: break-word applies only when table cells are fixed or aligned left, center, or right.

.has-fixed-layout {
table-layout: fixed;
width: 100%;
td,
th {
word-break: break-word;
}
}
&.alignleft,
&.aligncenter,
&.alignright {
// Override default display property for align styles.
// The table element needs to be kept as display table
// for table features to work reliably.
display: table;
// Table cannot be 100% width if it is aligned, so set
// width as auto.
width: auto;
td,
th {
word-break: break-word;
}
}

I think the default table would not have this problem. Here is the markup data used for the test.

Test Data
<!-- wp:heading -->
<h2 class="wp-block-heading">Default</h2>
<!-- /wp:heading -->

<!-- wp:table -->
<figure class="wp-block-table"><table><thead><tr><th>Workshop</th><th>Ages</th><th>Description</th><th>Time</th></tr></thead><tbody><tr><td>Bag O'cells</td><td></td><td></td><td></td></tr><tr><td>Bee Safari</td><td>All</td><td>Join our facilitator outdoors to learn hou to spot and identify bees and others pollinators in local gardens.</td><td></td></tr><tr><td>Combinatorics</td><td></td><td></td><td></td></tr></tbody></table></figure>
<!-- /wp:table -->

<!-- wp:heading -->
<h2 class="wp-block-heading">Center Aligined</h2>
<!-- /wp:heading -->

<!-- wp:table {"align":"center"} -->
<figure class="wp-block-table aligncenter"><table><thead><tr><th>Workshop</th><th>Ages</th><th>Description</th><th>Time</th></tr></thead><tbody><tr><td>Bag O'cells</td><td></td><td></td><td></td></tr><tr><td>Bee Safari</td><td>All</td><td>Join our facilitator outdoors to learn hou to spot and identify bees and others pollinators in local gardens.</td><td></td></tr><tr><td>Combinatorics</td><td></td><td></td><td></td></tr></tbody></table></figure>
<!-- /wp:table -->

<!-- wp:heading -->
<h2 class="wp-block-heading">Left Aligined</h2>
<!-- /wp:heading -->

<!-- wp:table {"align":"left"} -->
<figure class="wp-block-table alignleft"><table><thead><tr><th>Workshop</th><th>Ages</th><th>Description</th><th>Time</th></tr></thead><tbody><tr><td>Bag O'cells</td><td></td><td></td><td></td></tr><tr><td>Bee Safari</td><td>All</td><td>Join our facilitator outdoors to learn hou to spot and identify bees and others pollinators in local gardens.</td><td></td></tr><tr><td>Combinatorics</td><td></td><td></td><td></td></tr></tbody></table></figure>
<!-- /wp:table -->

<!-- wp:heading -->
<h2 class="wp-block-heading">Right Aligined</h2>
<!-- /wp:heading -->

<!-- wp:table {"align":"right"} -->
<figure class="wp-block-table alignright"><table><thead><tr><th>Workshop</th><th>Ages</th><th>Description</th><th>Time</th></tr></thead><tbody><tr><td>Bag O'cells</td><td></td><td></td><td></td></tr><tr><td>Bee Safari</td><td>All</td><td>Join our facilitator outdoors to learn hou to spot and identify bees and others pollinators in local gardens.</td><td></td></tr><tr><td>Combinatorics</td><td></td><td></td><td></td></tr></tbody></table></figure>
<!-- /wp:table -->

When the browser width is greater than the content width, header cell text will not wrap, except for the center-aligned table.

Screenshot

screenshot-1

When the device is narrow, the default table header cell text will not wrap and horizontal scrolling will occur.

Screenshot

screenshot-2

Are these the behaviors you expect?

@skorasaurus skorasaurus added the [Status] Needs More Info Follow-up required in order to be actionable. label Apr 5, 2023
@priethor
Copy link
Contributor

Let's close this issue, as it needs more info to be actionable. Please feel free to reopen again if there is more information. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Table Affects the Table Block Needs Design Feedback Needs general design feedback. [Status] In Progress Tracking issues with work in progress [Status] Needs More Info Follow-up required in order to be actionable.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants