puck icon indicating copy to clipboard operation
puck copied to clipboard

Default value defined in field

Open eyueldk opened this issue 1 month ago • 4 comments

Description

Currently, when defining components defaultProps is defined within a ComponentConfig. The suggestion is to add a defaultValue for the Field as well.

Example,

const Button: ComponentConfig = {
  fields: {
    text: {
      type: "text",
      defaultValue: "Click here!"
    }
  }
};

Considerations

I feel that the proper order of precedence for determining default values would be

  1. defaultProps in ComponentConfig
  2. defaultValue in Field

Proposals

Proposal 1

Add defaultValue prop to all Field that'll be the fallback default value after defaultProps.

eyueldk avatar Nov 11 '25 07:11 eyueldk

Thanks for opening this!

FedericoBonel avatar Nov 11 '25 07:11 FedericoBonel

Another thing we should consider is how this would interact with defaultItemProps in array fields.

Maybe it could serve as the default value that overrides whatever is defined at the nested field level; kind of like how defaultProps would work in your proposal, but scoped specifically to new array field items.

FedericoBonel avatar Nov 11 '25 07:11 FedericoBonel

I think one important part related to this and future development is centralizing the component default props. Currently, it's repeated logic in the code base. If it's centralized then it can be made easier to modify the defaulting behavior.

eyueldk avatar Nov 18 '25 10:11 eyueldk

A few considerations from my end:

  1. defaultProps are strictly typed. There's no easy way I can think of to know if there's already default set elsewhere.
  2. There will be two APIs to achieve the same thing, which may be considered obtuse and harder to communicate
  3. We must also account for this in AI generation

chrisvxd avatar Nov 20 '25 08:11 chrisvxd