JavaScript for WordPress Forums Gutenberg Development How to properly set default values?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #107520
    Chantal
    Participant

    I have set an attribute with a default value:

    attributes: {
    width: {
    	type: 'number',
    	value: 425
    },
    height: {
    	type: 'number',
    	value: 450
    },
    },

    In the edit function I use:

    <TextControl
    	label="Size"
    	value={ width }
    	onChange={ ( width ) => setAttributes( { width } ) }
    	className="width"
    />

    Now when I add my block in the editor, the default values are shown, but not saved to the post/page. Unless I edit them to another value and then save my post/page. What am I missing?

    #107525
    Zac Gordon
    Keymaster

    Yup, I have noticed the same thing.

    Default attributes do not save as attributes unless changed or you call set attributed a first time to manually save the value.

    It seems like a bug, but I think they did that on purpose.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.