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

Buttons do not show up properly in a table without a tbody #34184

Open
jsgoupil opened this issue Jun 4, 2021 · 7 comments · May be fixed by #39608 or #34269
Open

Buttons do not show up properly in a table without a tbody #34184

jsgoupil opened this issue Jun 4, 2021 · 7 comments · May be fixed by #39608 or #34269

Comments

@jsgoupil
Copy link

jsgoupil commented Jun 4, 2021

When using Angular, somehow, the tbody does not show up in the resulting HTML.
So this following code:

<body>
  <div class="container">
    <table class="table">
      <tr>
        <td><button class="btn btn-danger">Delete</button>
        </td>
      </tr>
    </table>
  </div>
</body>

will show a button with an incorrect background.
To force the tbody to be removed, I wrote some JavaScript in the code pen.

https://codepen.io/jsgoupil/pen/oNZqKvX

image

This worked fine on version 4.6.0

Version:

  • Bootstrap: 5.0.1
  • Browser: 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36 Edg/91.0.864.37
@alecpl
Copy link
Contributor

alecpl commented Jun 5, 2021

.table > :not(caption) > * > * selector will have to be changed to something more specific.

@lvostinar
Copy link

We are using material virtual scroll so the above selector does not target td/th (we have two extra tags between table and td); so please fix this issue

@ffoodd
Copy link
Member

ffoodd commented Jun 11, 2021

This selector is meant to scope style to the current table, preventing them to leak to nested tables.

And it also targets valid HTML tables : extra tags in the table structure is invalid.

However not having thead, tbody or tfoot is valid so we need to find a way to support it. Probably something like:

.table > tr > * {}
.table > thead > tr > *,
.table > tbody > tr > *,
.table > tfoot > tr > * {}

@twbs twbs deleted a comment from tungphan995 Jun 11, 2021
ffoodd added a commit that referenced this issue Jun 16, 2021
Fixes #34184 

Not quite sure about this, but requiring a `tbody` doesn't feel right either…
@ffoodd ffoodd linked a pull request Jun 16, 2021 that will close this issue
@ffoodd
Copy link
Member

ffoodd commented Jun 16, 2021

@jsgoupil You need JS to drop the tbody since it's automatically added by the browser, isn't it? Why would you skip this feature?
I'm not quite sure about this being an issue at all. Still opened a draft to fix it, but I'm probably against doing this. Do you have any accurate use case that would benefit from breaking a table structure this way?

@jsgoupil
Copy link
Author

The HTML specs say that having a tr element inside a table is valid. Now, some browsers will insert a tbody for you if you use plain old HTML tags.
However, if you use .createElement to actually insert HTML tags inside the DOM, then you are technically allowed to add a tr without a tbody.
This is what Angular does (or other framework doing .createElement). I rarely write tbody, so the Angular framework will insert everything without it.
When using Angular, I don't force removing the tbody; it's just not present. I didn't want to create a full blown example of the code here so I wrote a small JavaScript to handle this situation.

@ffoodd
Copy link
Member

ffoodd commented Jun 16, 2021

In such case, the browser does not add tbody?

@jsgoupil
Copy link
Author

Correct.

mdo pushed a commit that referenced this issue Apr 12, 2022
Fixes #34184 

Not quite sure about this, but requiring a `tbody` doesn't feel right either…
@louismaximepiton louismaximepiton linked a pull request Jan 25, 2024 that will close this issue
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs review
4 participants