Skip to content

readOnly in resolveData for rootProps doesn't work #1556

@ArfatSalman

Description

@ArfatSalman

Description

readOnly in resolveData doesn't seem to work on root props?

Environment

  • Puck version: 0.21.1
  • Browser version: [Chrome 135 (desktop), Firefox 133 (mobile)...]
  • Additional environment info: [bundler, OS, device type...]

Steps to reproduce

  1. Render the <Puck /> component in a grid layout...
import { Puck } from "@puckeditor/core";
import "@puckeditor/core/puck.css";
import { FieldLabel } from "@puckeditor/core";

const config = {
  components: {
    Example: {
      fields: {
        title: {
          type: "custom",
          render: ({ name, onChange, value, readOnly }) => {
            console.log({ readOnly });
            return (
              <input
                defaultValue={value}
                name={name}
                disabled={readOnly}
                onChange={(e) => onChange(e.currentTarget.value)}
              />
            );
          },
        },
      },
      render: ({ title }) => {
        return <p>{title}</p>;
      },
      resolveData() {
        return {
          readOnly: {
            title: true,
          },
        };
      },
    },
  },
  root: {
    resolveData({ props }) {
      console.log("dasd");
      return {
        props: {
          ...props,
        },
        readOnly: {
          title: true,
          b: true,
        },
      };
    },
    fields: {
      b: { type: "text" },
      title: {
        type: "custom",
        render: ({ name, onChange, value, readOnly }) => {
          console.log({ rootRead: readOnly });
          return (
            <input
              defaultValue={value}
              name={name}
              disabled={readOnly}
              onChange={(e) => onChange(e.currentTarget.value)}
            />
          );
        },
      },
    },
  },
};

// Describe the initial data
const initialData = {};

// Save the data to your database
const save = (data) => {};

// Render Puck editor
export function Editor() {
  return <Puck config={config} data={initialData} onPublish={save} />;
}

export { Editor as default };

What happens

The title in root never becomes readOnly. But the component does.

What I expect to happen

I expected the title to be readOnly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions