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

Sort spacing sizes when all slugs begin numerically #62567

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,8 @@ export default function useSpacingSizes() {
...defaultSizes,
];

// 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
) {
// Using numeric slugs opts-in to sorting by slug.
if ( sizes.every( ( { slug } ) => /^[0-9]/.test( slug ) ) ) {
Copy link
Contributor Author

@ajlende ajlende Jun 14, 2024

Choose a reason for hiding this comment

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

I have this just checking that it starts with a number, allowing slugs like 50-medium to be sorted, but maybe it would make more sense to only sort slugs that are completely numeric.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is good

sizes.sort( ( a, b ) => compare( a.slug, b.slug ) );
}

Expand Down
5 changes: 2 additions & 3 deletions schemas/json/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,8 @@
"type": "string"
},
"slug": {
"description": "Unique identifier for the space size preset. Will be sorted numerically. For best cross theme compatibility these should be in the form '10','20','30','40','50','60', etc. with '50' representing the 'Medium' size step.",
"type": "string",
"pattern": "^[0-9].*$"
"description": "Unique identifier for the space size preset. For best cross theme compatibility these should be in the form '10','20','30','40','50','60', etc. with '50' representing the 'Medium' size step. If all slugs begin with a number they will be merged with default and user slugs and sorted numerically.",
"type": "string"
},
"size": {
"description": "CSS space-size value, including units.",
Expand Down
Loading