Skip to content

Commit 36b02ce

Browse files
ramonjdmirkaciampoannezazundiego
authored andcommitted
PaletteEdit: Stop changing the slug when renaming a preset (WordPress#83750)
Unlinked contributors: tiennguyenvan. Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: annezazu <annezazu@git.wordpress.org> Co-authored-by: ndiego <ndiego@git.wordpress.org> Co-authored-by: davewhitley <drw158@git.wordpress.org> Co-authored-by: Nyiriland <nyiriland@git.wordpress.org>
1 parent 850c6ed commit 36b02ce

4 files changed

Lines changed: 2 additions & 12 deletions

File tree

‎packages/components/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- `BorderControl`, `BorderBoxControl`: Stop offering `%` as a width unit, since `border-width` does not accept percentages. A width already set in `%` keeps showing its unit ([#83492](https://github.com/WordPress/gutenberg/pull/83492)).
2626
- `UnitControl`: After clearing a value whose unit is not in `units`, give the next typed value the unit shown in the select instead of the cleared one ([#83492](https://github.com/WordPress/gutenberg/pull/83492)).
2727
- `ResizableBox`: Update `re-resizable` to `6.11.2`, which supports React 18 and renders the top and left handles before the content so focus order matches visual order ([#83754](https://github.com/WordPress/gutenberg/pull/83754)).
28+
- `PaletteEdit`: Keep an item's slug when it is renamed, so blocks and styles that reference the preset keep working ([#83750](https://github.com/WordPress/gutenberg/pull/83750)).
2829

2930
### Internal
3031

‎packages/components/src/palette-edit/index.tsx‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
import { __, sprintf } from '@wordpress/i18n';
1212
import { lineSolid, moreVertical, plus } from '@wordpress/icons';
1313
import { useDebounce, useInstanceId } from '@wordpress/compose';
14-
import { kebabCase } from '@wordpress/kebab-case';
1514
import { Menu, Stack, useEnableWpCompatOverlaySlot } from '@wordpress/ui';
1615
import Button from '../button';
1716
import { ColorPicker } from '../color-picker';
@@ -418,7 +417,6 @@ function Option< T extends PaletteElement >( {
418417
onChange,
419418
onRemove,
420419
popoverProps: receivedPopoverProps,
421-
slugPrefix,
422420
variant,
423421
colorPalette,
424422
}: OptionProps< T > ) {
@@ -463,9 +461,6 @@ function Option< T extends PaletteElement >( {
463461
onChange( {
464462
...element,
465463
name: nextName,
466-
slug:
467-
slugPrefix +
468-
kebabCase( nextName ?? '' ),
469464
} )
470465
}
471466
/>
@@ -512,7 +507,6 @@ function PaletteEditListView< T extends PaletteElement >( {
512507
elements,
513508
onChange,
514509
canOnlyChangeValues,
515-
slugPrefix,
516510
variant,
517511
colorPalette,
518512
popoverProps,
@@ -566,7 +560,6 @@ function PaletteEditListView< T extends PaletteElement >( {
566560
);
567561
addColorRef.current?.focus();
568562
} }
569-
slugPrefix={ slugPrefix }
570563
popoverProps={ popoverProps }
571564
/>
572565
) ) }
@@ -828,7 +821,6 @@ export function PaletteEdit( {
828821
elements={ elements }
829822
// @ts-expect-error TODO: Don't know how to resolve
830823
onChange={ onChange }
831-
slugPrefix={ slugPrefix }
832824
variant={ variant }
833825
colorPalette={ duotoneColorPalette }
834826
popoverProps={ popoverProps }

‎packages/components/src/palette-edit/test/index.browser.test.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ describe( 'PaletteEdit', () => {
727727
} );
728728
} );
729729

730-
it( 'can update palette name', async () => {
730+
it( 'can update palette name without changing its slug', async () => {
731731
const onChange = vi.fn();
732732

733733
await render(
@@ -762,7 +762,6 @@ describe( 'PaletteEdit', () => {
762762
{
763763
...colors[ 0 ],
764764
name: 'Primary Updated',
765-
slug: 'primary-updated',
766765
},
767766
colors[ 1 ],
768767
] );

‎packages/components/src/palette-edit/types.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ export type OptionProps< T extends PaletteElement > = {
153153
key: Key;
154154
onRemove: MouseEventHandler< HTMLButtonElement >;
155155
popoverProps?: PaletteEditProps[ 'popoverProps' ];
156-
slugPrefix: string;
157156
};
158157

159158
export type PaletteEditListViewProps< T extends PaletteElement > = {
@@ -166,5 +165,4 @@ export type PaletteEditListViewProps< T extends PaletteElement > = {
166165
editingElement?: EditingElement;
167166
popoverProps?: PaletteEditProps[ 'popoverProps' ];
168167
setEditingElement: ( newEditingElement?: EditingElement ) => void;
169-
slugPrefix: string;
170168
};

0 commit comments

Comments
 (0)