-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: Should we use InnerBlocks? #18768
Comments
How exactly would moving a cell work? Would it swap places with another cell? How would you handle moving rows or columns, if you handle that at all? If there were row blocks, then there couldn't be column blocks, and vice-versa. |
I agree with this, specially with adding buttons inside the table. |
For what it's worth, @ellatrix made this happen in a pull request a while back, and what we found trying to style the editor version to match the front-end was that it was extremely difficult due to the extra divs and elements that are necessary to make editable fields in the block editor. At the time we decided not to pursue it until we can reliably use something like display: contents;. Those "caniuse" stats look better, but require us to shed support for IE11 and to an extent, even classic Edge (the new Chromium based Edge is fine: https://www.microsoftedgeinsider.com/en-us/). Additional refactorings, such as improvements to horizontal margins, have happened since that conversation, so it's looking more realistic now than it did then. But it's still going to be a challenge! |
I've refactored |
@ellatrix I agree that moving the block toolbar outside of the block DOM would be a good idea. Is it too late to change the implementation now? I think you could do it with something like React Portals? |
@ZebulanStanphill No, definitely not too late. With some adjustments to |
I've thought a bit about how this might work. First off, there would probably have to be inner blocks for table headers ( Each of those Table Sections could render inner Table Row blocks ( The tricky part is columns. A column is individual Maybe someone has a good idea how that might be possible. |
It would be great to have table row blocks and cell blocks, maybe even "virtual" column blocks. |
I wonder if the new Now that the A wrapper around const { sections } = useInnerBlockTable(
{},
{ sections: [ 'thead', 'tbody', 'tfoot' ], rows: 4, columns: 4 }
);
return (
<table>
{ sections.map( ( { name: Tag, props: sectionProps, rows } ) => (
<Tag { ...sectionProps }>
{ rows.map( ( { props: rowProps, cells }, index ) => (
<tr { ...rowProps }>
{ cells.map( ( { cell } ) => cell ) }
</tr>
) ) }
</Tag>
) ) }
</table>
); I think the main challenge would still be selecting blocks—the block editor doesn't support row or column selection, only sequential selection. 🤔 |
The lighter DOM prop will help the table a lot. But this is still the primary blocker:
Table is almost a textbook example for why we might need the "passthrough" prop from #7694. In the following example markup:
For a good user experience you should never have to select anything other than the |
I was thinking that there'd be no need for passthrough blocks (for table sections/rows). My idea is there'd be two blocks With const { children } = useInnerBlocksProps();
// inner blocks for the table block are table cell blocks like this:
// [
// <TableCell />,
// <TableCell />,
// <TableCell />,
// <TableCell />,
// ...
// ] Now that we have access to that array (thanks to const rows = mapToRows( children, rowSizes );
// The previous single array of cells is now mapped into rows:
// [
// row 1:
// [
// <TableCell />,
// <TableCell />,
// ],
// row 2:
// [
// <TableCell />,
// <TableCell />,
// ],
// ...
// ] Then elements like The issue I mentioned with selection is not related to clicking through the block heirarchy, but multi-block selection. Not really an issue for rows which is just selecting consecutive blocks and already supported, but column selections would be a non-contiguous block selection (as described in these issues: #2320, #16895), as the selection would be every nth inner block element. That would still be a beneficial feature for the block editor generally, but something that's been tricky to implement before. Other challenges:
|
Awesome approach, and thank you for outlining it so clearly.
I recall conversations about non-contiguous multi selections in the past. Would a good first step be to allow you to select multiple separate cells by holding ⌘ when you click? |
Can we get a status update? |
I would love to help this move forward however I can, since we have some needs for this functionality, especially the ability to merge cells. I'm not sure how much I would be able to offer on the editor dev side of things, but I'd be happy to do some testing. |
Same here :) would love to help move this forward. Merging cells and having some more flexibility in tables is something that I keep running into. And the approach by @talldan seems very feasible. @talldan do you have any particular blockers that came out of your discovery or is this just a lack of time? :) Thanks in advance! :) |
I definitely don't have time at the moment, unfortunately. But I think a good first step would be to bring more awareness to this issue. I've outlined a potential option, but always good to get a few more ideas and critique. There are also things to be learnt from the similar change for the gallery block about how we might approach such a transition. |
For the approach to the table block, I would say it is important that the highly nested HTML markup a table comes with, does not dictate the user experience; the nesting UI would get unwieldy quick. In that vein, it might be good to revisit #7694 before going too far down the path. |
@jasmussen I agree, I think we had a similar discussion already above. My idea was to only have two block types, table and table cell. I think the other parts (sections, columns, rows) could be treated as multi-cell selections, so #7694 wouldn't be required. I definitely don't think it makes sense to pursue column/row blocks, not even sure how that could work. |
Apologies, I'm tired these days 🙈 — yes, table and table cell makes sense. |
I stumbled across this issue as block cell selection/merging was something I am missing too! 😄 I was wondering, would we need to migrate to inner blocks before we look at the selection/merge cell functionality? A script that tracks and manages a table matrix (cell states, merges etc), along with DOM events to detect selected cells, might be useful to look at first. A "cell" today is a I was thinking so long as our script in the Table Block can discern cell metadata (be it a regular |
Last we experimented with this, the challenge was primarily the amount of extra markup that the editor creates when nesting is involved. Since then the situation here has vastly improved with the "lighter DOM" explorations, possibly making it more feasible. So as a rule of thumb, I'd say that if the elements in the editor match the elements on the frontend (give or take a few classes), stylewise we should be in a good place. |
It is going to be a big leap to migrate the table block over to inner blocks, and it probably needs more discussion on whether there's value in proceeding. Doing so would probably need one or two dedicated developers. There's still some distance between how inner blocks work currently, and how a table might use inner blocks. I think the big challenge is around how inner blocks currently only have a single dimension (they're a 1 dimensional list), while tables are two dimensional (with columns and rows). I think some ideas and proof of concepts for that are needed. Using inner blocks would bring some advantages because blocks already support some functionality that a table does (insertion, deletion, reordering, multi-selection, merging). Using those existing features would be pretty elegant, and leaning into the block system means that improvements to the table block benefit more than just the table block. But I can definitely see how challenging it is, and that there isn't a very clear path forwards. I think some of these features (merging in particular) will be very challenging anyway! |
Yes, handling two dimensions will be tough, especially with the extra |
+1 would love this feature |
Can the grid feature being worked on #57478 also be used in a similar way for the Table block? |
After using Media & Text, Cover, Columns, etc., it feels weird to use the Table block and have it not somehow use InnerBlocks — I keep expecting individual cell options, or row-column options, and the ability to easily move cells around using block movers.
The text was updated successfully, but these errors were encountered: