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

Fix: wrong markup when columns input is empty #12954

Closed

Conversation

jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented Dec 17, 2018

Description

Depends: #12952
When the columns input field was empty previously we generated invalid markup with has-undefined-columns class. The block also started showing empty in the editor.

With this change when the input field is empty the default value for the columns attribute is used and it looks the same as if the user used two columns.

How has this been tested?

Add a columns block.
Write some content.
Make the columns input field empty, and verify no invalid markup is produce and a value of two is used. (previous the block got broken in the editor and invalid markup was produced).

@jorgefilipecosta jorgefilipecosta added [Type] Bug An existing feature does not function as intended [Block] Columns Affects the Columns Block labels Dec 17, 2018
@jorgefilipecosta jorgefilipecosta force-pushed the fix/wrong-markup-when-columns-input-is-empty branch from b2c72fd to 4c76740 Compare December 20, 2018 14:06
@jorgefilipecosta jorgefilipecosta force-pushed the fix/wrong-markup-when-columns-input-is-empty branch from 4c76740 to 2ffd523 Compare January 11, 2019 18:39
@jorgefilipecosta jorgefilipecosta requested a review from a team January 11, 2019 18:55
packages/block-library/src/columns/index.js Outdated Show resolved Hide resolved
@@ -155,7 +164,7 @@ export const settings = {
],

edit( { attributes, setAttributes, className } ) {
const { columns } = attributes;
const columns = attributes.columns || DEFAULT_NUMBER_OF_COLUMNS;
Copy link
Member

Choose a reason for hiding this comment

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

Begs the question: Should a block developer ever need to anticipate an attribute value being undefined when its definition includes a default ? Is this something which ought to be handled when setting attributes? Probably a decent amount of overhead included in doing so. Alternatively it could be block specific in only letting the RangeControl's onChange trigger when a valid nextColumns, or provide the defaulting there, or RangeControl provides a fallback value when its input is invalid.

Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @aduth, you are comments are right, given that a block has a default we should not need to anticipate an undefined value.
But setting changing the attribute to the default when an undefined value exists causes some problems. E.g: a user has 3 columns wants to set to two 4 columns, deletes the 3 and in the UI automatically sees a 2 instead of an empty field to write the 3.

This problem is resolved with a PR I created that fixes some behaviors in the RangeControl #12952.
If these changes are merged after the other PR everything will work smoothly.

@jorgefilipecosta jorgefilipecosta force-pushed the fix/wrong-markup-when-columns-input-is-empty branch from 2ffd523 to 2bd6c95 Compare January 24, 2019 11:14
@jorgefilipecosta jorgefilipecosta force-pushed the fix/wrong-markup-when-columns-input-is-empty branch from 2bd6c95 to c359733 Compare January 24, 2019 11:15
@gziolo gziolo added this to the 5.1 (Gutenberg) milestone Feb 7, 2019
@jorgefilipecosta
Copy link
Member Author

In my tests after the merge of #12952 given the logical changes that happened there, the problem is fixed so I'm closing this PR.

@jorgefilipecosta jorgefilipecosta deleted the fix/wrong-markup-when-columns-input-is-empty branch February 20, 2019 12:50
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 [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants