Negative values in column's width redistribution #27616
Labels
[Block] Columns
Affects the Columns Block
[Type] Bug
An existing feature does not function as intended
Describe the bug
During the sanity testing before mobile release @chipsnyder noticed that we are able to get negative percentages in
Columns
and mentioned about it in the comment. Since the logic for width redistribution is shared the same occurs on web editor.To reproduce
Steps to reproduce the behavior:
Result:
With those numbers I got: 73.34%, -6.66% and 33.33%.
The same will happen when adding new column to the following columns:
90/5/5
and many other.The problem is the wrong math within the function called
getRedistributedColumnWidths
located in columns utils.Mentioned method is assuming that difference (difference between available width and new columns width sum) is divided equally between columns and subtracted from each of them. As a result we can get negative values, since adjustment has higher value than width.
Let's consider it on the example from reproduction steps:
availableWidth
refers to the sum of first two columns after adding the third one: 66.67 (100 - 33)total width
refer to the sum of all columns: 100difference
is -33.33 (66.67 - 100)adjustment
is -16.665 (-33.33 / 2)Finally we have
Possible problem solution
Imo the mechanism should be a bit different and width should be calculated proportionally to the totalWidth:
As a result we get positive values, divided proportionally:
Expected behavior
Columns shouldn't have negative width values
Screenshots
Attached above.
If applicable, add screenshots to help explain your problem.
Editor version (please complete the following information):
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: