Below is the code for the custom editor.
class MaskedEditor extends Handsontable.editors.TextEditor
{
private mask:_InputMask<FactoryArg>|null = null;
prepare(row: number, col: number, prop: string | number, td: HTMLTableCellElement, originalValue: any, cellProperties: Handsontable.CellProperties)
{
super.prepare(row, col, prop, td, originalValue, cellProperties);
const iMaskOptions = cellProperties.iMaskOptions;
if (this.mask != null)
{
this.mask.destroy();
this.mask = null;
}
if (typeof iMaskOptions === "object")
{
this.mask = IMask(this.TEXTAREA, iMaskOptions);
}
}
createElements()
{
super.createElements();
this.TEXTAREA = this.hot.rootDocument.createElement('input');
this.TEXTAREA.setAttribute('data-hot-input', true); // Makes the element recognizable by HOT as its own component's element.
this.textareaStyle = this.TEXTAREA.style;
this.textareaStyle.width = 0;
this.textareaStyle.height = 0;
this.TEXTAREA_PARENT.innerText = '';
this.TEXTAREA_PARENT.appendChild(this.TEXTAREA);
const style = this.TEXTAREA.getAttribute("style") ?? "";
this.TEXTAREA.setAttribute("style", style + " background-color:yellow;");
}
}
Here is a simplified copy of the Handsontable element:
<HotTable ref={hot}
id={hotIdentity}
licenseKey={HOT_LICENSE_KEY}
className="full-size"
data={sheetData}
colHeaders={false}
colWidths={colWidths}
rowHeaders={false}
rowHeights={rowHeights}
cell={sheetCells}
allowInsertColumn={false}
allowInsertRow={false}
allowRemoveRow={false}
autoColumnSize={false}
autoRowSize={false}
//contextMenu={false}
mergeCells={mergeCells}
selectionMode={'single'}
contextMenu=
{
{
items:
{
'custom-undo':
{
name: 'Undo changes',
disabled()
{
return false; // Simplified
},
callback: function()
{
// Do stuff
}
},
'custom-reset':
{
name: 'Reset to default',
hidden()
{
return false; // Simplified
},
callback: function()
{
// Do stuff
}
}
}
} as ContextMenuSettings
}
/>