sanity-io / color-input

Color input and schema for Sanity Studio
MIT License
17 stars 10 forks source link

colorList doesn't show if part of an object #68

Closed richgcook closed 8 months ago

richgcook commented 8 months ago

I've found that when the color input is used as part of an object the predefined colors don't show. I thought this was to do with it being in a collapsed section but forcing collapsed: false doesn't fix the issue.

No errors in console and no element in the DOM.

import { defineField } from 'sanity'

export default defineField({
    type: 'color',
    name: 'colorPicker',
    title: 'Color',
    options: {
        colorList: [
            { hex: '#ffffff' },
            '#141313',
            '#f7f1ee', // Beige
            '#04674a', // Green
            '#e75f5c', // Red
            '#eabad8', // Pink
            '#e4aa58', // Yellow
            '#4976af', // Blue
        ]
    },
})
defineField({
    type: 'object',
    title: 'Colors',
    name: 'colors',
    options: {
        collapsible: true,
        collapsed: false
    },
    fields: [
        defineField({
            type: 'colorPicker',
            title: 'Graphic',
            name: 'graphic',
            options: {
                collapsible: false
            },
            description: 'Used for graphics, if applicable'
        }),
    ],
}),

Screenshot 2024-03-01 at 13 54 22@2x

On using React Developer Tools it looks like colorList is undefined...

Screenshot 2024-03-01 at 14 14 14@2x Screenshot 2024-03-01 at 14 14 09@2x

richgcook commented 8 months ago

Stupidly this was my own mistake. I was adding the following to the field when used which in turn was overwriting the colorList...

options: { collapsible: false },