Skip to content

Commit

Permalink
Fix resetting individual blocks to empty values for Pattern Overrides (
Browse files Browse the repository at this point in the history
…#59170)

Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: talldan <talldanwp@git.wordpress.org>
  • Loading branch information
4 people authored Feb 21, 2024
1 parent 09dc127 commit a04a8e9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/patterns/src/components/reset-overrides-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,19 @@ export default function ResetOverridesControl( props ) {
const blocks = editedRecord.blocks ?? parse( editedRecord.content );
const block = recursivelyFindBlockWithId( blocks, id );

props.setAttributes( block.attributes );
const newAttributes = Object.assign(
// Reset every existing attribute to undefined.
Object.fromEntries(
Object.keys( props.attributes ).map( ( key ) => [
key,
undefined,
] )
),
// Then assign the original attributes.
block.attributes
);

props.setAttributes( newAttributes );
};

return (
Expand Down

0 comments on commit a04a8e9

Please sign in to comment.