@@ -9,6 +9,8 @@ import styled from 'styled-components'
9
9
export interface SimplerColorType {
10
10
label : string
11
11
value : string
12
+ _type ?: string // included in textColor and highlightColor annotation types
13
+ _key ?: string // included in textColor and highlightColor annotation types
12
14
}
13
15
14
16
export interface ColorOptions extends Omit < ObjectOptions , 'columns' > {
@@ -29,7 +31,7 @@ export const SimplerColorInput = (props: ObjectInputProps) => {
29
31
const { onChange} = props
30
32
const value = props . value as SimplerColorType | undefined
31
33
const type = props . schemaType as SimplerColorSchemaType
32
- const [ selectedColor , setSelectedColor ] = useState < SimplerColorType | undefined > ( value )
34
+ const [ selectedColor , setSelectedColor ] = useState < Partial < SimplerColorType > | undefined > ( value )
33
35
34
36
const handleChange = useCallback (
35
37
( color : SimplerColorType ) => {
@@ -142,8 +144,16 @@ export const SimplerColorInput = (props: ObjectInputProps) => {
142
144
< Button
143
145
mode = "ghost"
144
146
onClick = { ( ) => {
145
- setSelectedColor ( undefined )
146
- onChange ( unset ( ) )
147
+ if ( value !== undefined && value . _key ) {
148
+ // we need to handle annotations differently to
149
+ // prevent errors in the Portable Text editor
150
+ const annotationValue = { _type : value . _type , _key : value . _key }
151
+ setSelectedColor ( annotationValue )
152
+ onChange ( set ( annotationValue ) )
153
+ } else {
154
+ setSelectedColor ( undefined )
155
+ onChange ( unset ( ) )
156
+ }
147
157
} }
148
158
style = { { borderTopLeftRadius : '0' , borderBottomLeftRadius : '0' } }
149
159
>
0 commit comments