I dont know if this is a React question or a Monday UI question. Look at this reproduction
I am using EditableHeading
When you edit the field - a discard button appears. how can i change the value of the editableHeader in this example?
Here is my component
import { EditableHeading, Label } from 'monday-ui-react-core';
import { useState } from 'react';
export declare enum HeadingTypes {
h1 = 'h1',
h2 = 'h2',
h3 = 'h3',
h4 = 'h4',
h5 = 'h5',
h6 = 'h6',
}
type HeadingTypeValues = `${HeadingTypes}`;
export interface Props {
val: string;
type: HeadingTypeValues;
save: (val: string) => void;
}
export const Field = ({ val, type, save }: Props) => {
const [edits, setEdits] = useState('');
const [value, setValue] = useState(val);
function editVal(name: string) {
console.log(`🚀 => Field => editVal => name:`, name);
setEdits(name);
}
function discard() {
setEdits('');
setValue(val);
}
return (
<div className='block relative'>
<EditableHeading
type={(EditableHeading as any).types[type]}
value={value}
onChange={editVal}
/>
{edits.length > 0 && (
<div className='actions absolute right-3 top-3 flex text-xs'>
<Label
className='cursor-pointer opacity-90 hover:opacity-100'
text='Discard'
color={Label.colors.DARK}
onClick={discard}
/>
</div>
)}
</div>
);
};