-
Notifications
You must be signed in to change notification settings - Fork 808
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
Forms: add layout support #41428
Comments
OpenAI suggested the following labels for this issue:
|
This issue could use some more labels, to help prioritize and categorize our work. Could you please add at least a |
I've started working on a small spike/experiment to see how possible this is.
It looks like the controls can be configured to be hidden. The downside is that while it's pretty customizable, there are some controls like "Allow to wrap to multiple lines" that can't be controlled, and that one in particular doesn't really make sense for forms. The only option is to set The other thing is that the current layout system for the form block works a little differently to what core expects. It uses what core would consider a 'row' layout, but all the inner blocks are set to The final thing is it's a little challenging to get this working on the frontend, that's what I'm currently solving. |
If there isn't a Gutenberg issue yet to make that configurable, it would make sense to document the finding with real use case. |
At the moment I'm only looking at using the layout system for the top-level form block, that way it shouldn't overlap with @aaronrobertshaw's work. Layouts within fields should hopefully still work (I'll remember to test it). |
I'm going to pause my work on this. Here's a write-up of what I've discovered. TLDR - I don't think this is worth pursuing right now. I think core's layout support needs a few extra enhancements to properly support forms. Grid layout might be an interesting future possibility. I expect there will also be more opportunities after @aaronrobertshaw's work in #41281, that would unlock what the inline label idea mentioned here by using a row layout in the field block. Current stateThe top-level form block has a flexbox layout with Most users won't really consider it a horizontal layout, as each field has This side-by-side field layout seems like something the block is optimized for. Something to note here is that these width percentages automatically take the gap between the blocks into account: jetpack/projects/packages/forms/src/blocks/contact-form/editor.scss Lines 75 to 78 in 6c988c6
This means the fields always fit nicely into a row: There are also some responsive styles, on smaller screens the layout reverts to all fields being full-width again. Porting this to the Block Editor's layout systemOne of my hopes had been to switch the form block over to the block editor's layout system to avoid the hard-coded CSS and make it possible for the block to adopt other kinds of layout where it makes sense. Perhaps the default layout could still be fairly simple, but it would still be possible to build something more advanced, especially for style variations and patterns. Making the block work more idiomatically could also allow a wider variety of child blocks within the form, and they'll just work naturally. An example of how this isn't work so well right now is the way the Button block requires a hard-coded exception to the style rules, and there are a few other examples of this: jetpack/projects/packages/forms/src/blocks/contact-form/editor.scss Lines 56 to 58 in 6c988c6
Row layoutIt's pretty easy to switch to the top-level form block to use a similar flexbox The block editor does also offer size controls on the individual fields and it also allows percentage widths: Unfortunately these widths don't take the block gap into account so the fields won't line up nicely. Here's the same layout as above using the layout system and you can see the fields overflow when set to widths that add up to 100%: There was some discussion about this in the Gutenberg repo, but I can't see that it has been addressed. The row layout also won't provide the same responsive behavior that the form block currently has without some CSS overrides. Grid layoutIt's possible to achieve a very similar layout using a grid layout in manual mode with 4 columns, and this does solve the problem with block gap: In a grid, we'd set the column span for each field instead of a width percentage. Unfortunately, there are also no responsive options for this layout. Still, I think the grid layout might be interesting for forms in the future. There are lots of additional features for grids behind an experiment flag in the Gutenberg plugin that will allow for more responsive behavior with the simpler 'automatic' mode: It gets pretty close to working how the form block currently does without the need for any special CSS, albeit with a few quirks. Other layoutsFlow and Constrained layouts are the default layouts in the block editor. 'Constrained' adopts the content width, while 'flow' doesn't restrict the width of blocks. I don't think they'll provide much value for forms, users would have to wrap fields with columns/row/grid to achieve a a layout that has fields side-by-side, which is more complicated than how the block works right now. |
I've pushed a draft PR #41665 if you want to try out the layout system on the form block. |
It's worth noting that #41281 isn't intended to land. It was meant as a vehicle for exploring blockers, backward compatibility requirements, necessary compromises, and UX implications of inner blocks on form fields. My plan is to close that PR today to avoid further expectations that inner blocks for form fields are imminent. If a decision to commit to inner block based form fields is made, a new PR will be created based off the latest on trunk. |
Forms currently has flex CSS styles, causing issues or making it complicated to design variety of layouts horizontally/vertically.
Adding layout support would solve these issues, but on the flip side potentially add complicated controls, so we need to be careful what exact layout supports we would add.
The text was updated successfully, but these errors were encountered: