Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some inputs won't open inside arrays #892

Open
chrisvxd opened this issue Feb 12, 2025 · 0 comments
Open

Some inputs won't open inside arrays #892

chrisvxd opened this issue Feb 12, 2025 · 0 comments
Labels
ready Assumed ready enough to start type: bug 🐛

Comments

@chrisvxd
Copy link
Member

From this discord thread, the native HTML5 color picker won't open inside an array field.

Steps to reproduce

  1. Create a custom field using an HTML 5 color picker
  2. Place the field inside an array field
  3. Attempt to click the color picker

What happens

The color picker didn't open

What I expected to happen

The color picker is shown

Code example

import { ComponentConfig, DropZone, FieldLabel } from "@measured/puck";

export type FlexBlockProps = {
  items: { minItemWidth?: number, itemColor: string }[];
  minItemWidth: number;
}

export const FlexBlock: ComponentConfig<FlexBlockProps> = {
  fields: {
    items: {
      type: "array",
      label: "Items",
      arrayFields: {
        minItemWidth: {
          label: "Minimum Item Width",
          type: "number",
          min: 0,
        },
        itemColor: {
          type: "custom",
          label: "Color",
          render: ({ name, onChange, value, field }) => (
            <FieldLabel label={field.label!}>
              <input
                type="color"
                defaultValue={value}
                name={name}
                onChange={(e) => onChange(e.currentTarget.value)}
              />
            </FieldLabel>
          )
        }
      },
      getItemSummary: (arrayFields, id = -1) => `Item ${id + 1}`,
    },
    minItemWidth: {
      label: "Minimum Item Width",
      type: "number",
      min: 0,
    },
  },
  defaultProps: {
    items: [{ itemColor: '#ff0000' }, { itemColor: '#ff0000' }],
    minItemWidth: 356,
  },
  render: ({ items, minItemWidth }) => {
    return (
      <div className="flex-container">
        {items.map((item, idx) => (
          <div
            key={idx}
            className="flex-item"
            style={{ minWidth: item.minItemWidth || minItemWidth, color: item.itemColor }}
          >
            <DropZone zone={`item-${idx}`} />
          </div>
        ))}
      </div>
    );
  },
};
@chrisvxd chrisvxd added ready Assumed ready enough to start type: bug 🐛 labels Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready Assumed ready enough to start type: bug 🐛
Projects
None yet
Development

No branches or pull requests

1 participant