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

Use UnitControl instead of RangeControl for column width #24711

Merged
merged 25 commits into from
Sep 29, 2020

Conversation

aristath
Copy link
Member

@aristath aristath commented Aug 21, 2020

I've got an itch I need to scratch... With FSE users will be able to use the editor to create their layouts. However, there is currently no way to create a layout with a side-header, or do a lot of other cool stuff.
The reason why they can't is simple: Columns are restricted to only use percent (%) values for their width.
This PR changes the control for column width from a RangeControl to a UnitControl, and makes all necessary changes to ensure backwards-compatibility and everything seems to be working the way it should. (see #24193)
The width control now looks like this:
Screenshot of the new width control using a UnitControl

The benefit of that is that we can now create a layout like this:

Screencast showing a layout with a 250 pixels wide side-header

In the screencast above, the left column has a width of 250px and is the site header.
With percentage values that wouldn't be possible unless the user added custom classes and then custom HTML - which is totally possible but is the very thing Gutenberg was created to solve.
You can see there that resizing the viewport doesn't change the width of the 1st column since we used absolute units for that.

Though the range control is admittedly prettier, UnitControl allows for greater versatility and can accommodate many more scenarios.


EDIT:
Originally this PR aimed to allow arbitrary values for column widths.
Since then I realized the original plan was too ambitious and maybe too confusing for certain users. Some of the first commits here were using a TextControl and a custom validation function with notices. This is no longer the case and I switched it to UnitControl which is a more familiar pattern in the editor.

@aristath aristath added [Block] Columns Affects the Columns Block [Feature] Full Site Editing Needs Design Feedback Needs general design feedback. labels Aug 21, 2020
@carolinan
Copy link
Contributor

I agree that this change is needed since it will enable more precise layouts.

I have tested the PR by creating a couple of column blocks without the plugin installed, and then activating the plugin (master + the pr). The original % values that were saved are working correctly in the editor and front.
I have edited the blocks and entered different values and the new values are saved as expected.

@aristath
Copy link
Member Author

aristath commented Aug 24, 2020

Comment no longer relevant since it refers to a previous implementation using a TextControl. (Click to expand) Added some rudimentary values validation in dc3b8b7 with a notice in case the value is invalid. Example screencast with various units can be seen below:

Screencast showcasing the input field with test cases for various CSS length values, and the notice thrown when a value is invalid.

@aristath
Copy link
Member Author

Switched the plaintext input with validation to a UnitControl.
As a 1st step it's less ambitious but probably makes more sense.

Screenshot_2020-08-27 Edit Post ‹ test — WordPress

@aristath aristath changed the title Allow arbitrary widths for columns Use UnitControl instead of RangeControl for column width Aug 27, 2020
@ZebulanStanphill ZebulanStanphill added the Needs Accessibility Feedback Need input from accessibility label Aug 28, 2020
@aristath aristath added the [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. label Aug 31, 2020
@aristath
Copy link
Member Author

@ZebulanStanphill I'm curious, why was the Needs Accessibility Feedback tag added here?
Was it perhaps referring to a previous implementation that had custom notices, validation etc instead of the now standard RangeControl?

Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @aristath! Thanks for working on this! - I haven't check the branch thoroughly because some more involved into these kind of things folks should have a better context/opinions. @ItsJonQ can you take a look here?

I have left some notes on the deprecation of the block though that I think you should check. I'm not 100% sure if I have missed something from the API or have understood something different, but seems worth asking a few things :)

packages/block-library/src/column/deprecated.js Outdated Show resolved Hide resolved
packages/block-library/src/column/deprecated.js Outdated Show resolved Hide resolved
packages/block-library/src/column/deprecated.js Outdated Show resolved Hide resolved
packages/block-library/src/column/deprecated.js Outdated Show resolved Hide resolved
packages/block-library/src/column/edit.js Outdated Show resolved Hide resolved
@ntsekouras ntsekouras requested a review from ItsJonQ September 21, 2020 15:05
@ItsJonQ
Copy link

ItsJonQ commented Sep 29, 2020

@aristath Yay!! I made one minor adjustment to the UI (reducing the width of the input)

Screen Shot 2020-09-29 at 10 52 01 AM

If this you're okay with this, then I think it's ready 👍

@aristath aristath requested a review from ellatrix as a code owner September 29, 2020 15:04
@aristath
Copy link
Member Author

aristath commented Sep 29, 2020

I made one minor adjustment to the UI (reducing the width of the input)

@ItsJonQ Looks great! ❤️ Yes, of course I'm OK with it.

Copy link

@ItsJonQ ItsJonQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aristath for this update! 👍 from me

@aristath aristath merged commit 1cad0e1 into WordPress:master Sep 29, 2020
@aristath aristath deleted the aristath/try-column-width branch September 29, 2020 15:41
@github-actions github-actions bot added this to the Gutenberg 9.2 milestone Sep 29, 2020
@lukewalczak
Copy link
Member

lukewalczak commented Oct 12, 2020

Hello, I would like to discuss some aspects of that PR 🤔

  1. I've noticed that your PR involved some kind of regression in Columns block, unless the new behavior is intended. Basically some functions such as hasExplicitColumnWidths or toWidthPrecision from columns/utils.js cannot work since there is a check Number.isFinite(value). Value always comes with the unit, so the result is false. Unfortunately it has an effect on columns width distribution (please notice that on presented gif, the third column width is different)
before PR after PR
before_pr after_pr
  1. The second thing which I would like to raise is the fact that these changes (adding unit to the width attribute) are affecting the mobile part as well and unfortunately we have a crash when user is changing columns width and saving the post. The PR template should have Checklist, where one of the bullet is:

I've updated all React Native files affected by any refactoring/renamings in this PR..

I'm aware that it can be hard to run the mobile, but you can always ping someone from mobile team to test and confirm if changes don't break anything.

  1. The third point is that Columns on mobile accepts only % so I don't know how it will behave when user on web will set:
  • first column: 100px
  • second column: 50%

and then will open the post on mobile app.

@youknowriad
Copy link
Contributor

@aristath What do you think about the regressions above? Can we fix this on time for 5.6 or should we revert this PR temporarily?

@lukewalczak
Copy link
Member

One more thing to note is that function in columns/utils called getTotalColumnsWidth used within getRedistributedColumnWidths sums the width attribute of the individual column defined in % (correct me if I'm wrong). With the approach where width can be defined in different units, function mentioned above should take into account somehow.

@aristath
Copy link
Member Author

I currently have to focus on the twentytwentyone theme if we want to make the deadline, so I can't work on this issue this week.
If nobody else is willing to fix the issues then reverting it temporarily for the 5.6 release is the only option. 👍

@ceyhun
Copy link
Member

ceyhun commented Oct 13, 2020

Created a PR to temporarily revert: #26056

@ntsekouras
Copy link
Contributor

ntsekouras commented Oct 13, 2020

I think even the revert could potentially affect other merged PRs (after this one) that had to do with Columns block. For example it will affect this one: #25829.

And this one is I know because I was the author. There could be many more... 🤔

@aristath aristath mentioned this pull request Oct 14, 2020
17 tasks
@tellthemachines tellthemachines mentioned this pull request Nov 6, 2020
6 tasks
migrate( attributes ) {
return {
...attributes,
width: `${ attributes.width }%`,
Copy link
Member

@gziolo gziolo Nov 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tellthemachines, @ntsekouras - this one might need isEligible check. width might be not set at all. It's very likely we can avoid adding another deprecation in #26757.

"type": "number",
"min": 0,
"max": 100
"type": "string"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also creates some issues when adding a new column because it still uses number values. See #27756.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Columns Affects the Columns Block [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Needs Design Feedback Needs general design feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants