Support gradients with omitted stop positions in CustomGradientPicker #27413
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds logic to test the color stops of the parsed gradient for any positions that are undefined or set with a unit other than percent. If some are found then each color stop in the gradient is reassigned a new equidistant position as percent.
Will fix #27382 and fix #23501 (duplicates).
Commentary
These changes were aimed at doing the simplest thing to prevent errors and support common use cases. The 'fixup' applied when stop positions are omitted is simpler than the spec (which wouldn't make sense to implement with the current UI). Additionally, a use case not handled by this is when stops are defined outside of 0-100:
linear-gradient( 135deg, crimson -10%, gold 50%, lime 110% )
Such cases produce no errors but the outside stops can be out of reach in the UI.
The reassignment of non-percentage units is coverage for an edge case not mentioned in either of the issues but is something that causes similar issues. It may be worthwhile to add some note about this in the documentation for the gradient presets, e.g. gradient presets support omitting positions or defining them in percentage only.
How has this been tested?
In WP 5.5.3
Types of changes
Bug fix
Checklist: