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 UI order for theme.json spacing sizes #62199

Merged
merged 6 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backport-changelog/6.6/6616.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ https://github.com/WordPress/wordpress-develop/pull/6616

* https://github.com/WordPress/gutenberg/pull/58409
* https://github.com/WordPress/gutenberg/pull/61328
* https://github.com/WordPress/gutenberg/pull/61842
* https://github.com/WordPress/gutenberg/pull/61842
* https://github.com/WordPress/gutenberg/pull/62199
5 changes: 5 additions & 0 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -3852,13 +3852,18 @@ public function set_spacing_sizes() {
* @return array The merged set of spacing sizes.
*/
private static function merge_spacing_sizes( $base, $incoming ) {
// Preserve the order if there are no base (spacingScale) values.
if ( empty( $base ) ) {
return $incoming;
}
$merged = array();
foreach ( $base as $item ) {
$merged[ $item['slug'] ] = $item;
}
foreach ( $incoming as $item ) {
$merged[ $item['slug'] ] = $item;
}
ksort( $merged, SORT_NUMERIC );
return array_values( $merged );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,19 @@ export default function useSpacingSizes() {
...customSizes,
...themeSizes,
...defaultSizes,
].sort( ( a, b ) => compare( a.slug, b.slug ) );
];

// Only sort if more than one origin has presets defined in order to
// preserve order for themes that don't include default presets and
// want a custom order.
if (
( customSizes.length && 1 ) +
( themeSizes.length && 1 ) +
( defaultSizes.length && 1 ) >
1
) {
sizes.sort( ( a, b ) => compare( a.slug, b.slug ) );
}

return sizes.length > RANGE_CONTROL_MAX_SIZE
? [
Expand All @@ -53,8 +65,6 @@ export default function useSpacingSizes() {
},
...sizes,
]
: // See https://github.com/WordPress/gutenberg/pull/44247 for reasoning
// to use the index as the name in the range control.
sizes.map( ( { slug, size }, i ) => ( { name: i, slug, size } ) );
: sizes;
}, [ customSizes, themeSizes, defaultSizes ] );
}
Loading