From 65f99f9b71da9c1c2d9a0dfb0f3369b014966659 Mon Sep 17 00:00:00 2001 From: mertsincan Date: Wed, 19 Jan 2022 09:47:11 +0300 Subject: [PATCH] Fixed #2561 - Calendar as editor inside DataTable in row edit mode --- components/lib/datatable/BodyCell.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/components/lib/datatable/BodyCell.js b/components/lib/datatable/BodyCell.js index 34fd270618..2467606bc9 100644 --- a/components/lib/datatable/BodyCell.js +++ b/components/lib/datatable/BodyCell.js @@ -196,7 +196,7 @@ export class BodyCell extends Component { clearTimeout(this.tabindexTimeout); this.tabindexTimeout = setTimeout(() => { if (this.state.editing) { - const focusableEl = DomHandler.getFirstFocusableElement(this.el, ':not(.p-cell-editor-key-helper)'); + const focusableEl = this.props.editMode === 'cell' ? DomHandler.getFirstFocusableElement(this.el, ':not(.p-cell-editor-key-helper)') : DomHandler.findSingle(this.el, '.p-row-editor-save'); focusableEl && focusableEl.focus(); } @@ -204,6 +204,14 @@ export class BodyCell extends Component { }, 1); } + focusOnInit() { + clearTimeout(this.initFocusTimeout); + this.initFocusTimeout = setTimeout(() => { + const focusableEl = this.props.editMode === 'row' ? DomHandler.findSingle(this.el, '.p-row-editor-init') : null; + focusableEl && focusableEl.focus(); + }, 1); + } + updateStickyPosition() { if (this.getColumnProp('frozen')) { let styleObject = { ...this.state.styleObject }; @@ -424,10 +432,12 @@ export class BodyCell extends Component { onRowEditSave(event) { this.props.onRowEditSave({ originalEvent: event, data: this.props.rowData, newData: this.getEditingRowData(), field: this.field, index: this.props.rowIndex }); + this.focusOnInit(); } onRowEditCancel(event) { this.props.onRowEditCancel({ originalEvent: event, data: this.props.rowData, newData: this.getEditingRowData(), field: this.field, index: this.props.rowIndex }); + this.focusOnInit(); } bindDocumentEditListener() {