Skip to content

Commit

Permalink
fix: remove drop-down layer of editor (#1545)
Browse files Browse the repository at this point in the history
* fix: editors with drop-down layer to follow scrolling

* test: add tests for editors with drop-down layer to follow scrolling

* chore: apply code reviews

* chore: fix lint error

* test: add tests for remove drop-down layer of editor

* fix: remove drop-down layer of editor

* chore: remove destructuring

* chore: apply code reviews
  • Loading branch information
jajugoguma authored Jan 7, 2022
1 parent 95eb78f commit 13947c1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
26 changes: 23 additions & 3 deletions packages/toast-ui.grid/cypress/integration/editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ it('should do synchronous rendering of the editing cell', () => {
});

describe('select, checkbox, radio editor', () => {
const dataForGridWithType = [{ name: '1' }, { name: '2' }, { name: '3' }, { name: '4' }];
function createGridWithType(type: string) {
const data = [{ name: '1' }, { name: '2' }, { name: '3' }, { name: '4' }];
const columns = [
{
name: 'name',
Expand All @@ -364,7 +364,7 @@ describe('select, checkbox, radio editor', () => {
},
];

cy.createGrid({ data, columns });
cy.createGrid({ data: dataForGridWithType, columns });
}

context('UI', () => {
Expand Down Expand Up @@ -452,6 +452,26 @@ describe('select, checkbox, radio editor', () => {
assertOptionHighlighted(3);
});
});

describe('remove drop-down layer', () => {
['radio', 'select', 'checkbox'].forEach((type) => {
it(`should remove drop-down layer when calling cancelEditing() API (${type})`, () => {
createGridWithType(type);

cy.gridInstance().invoke('cancelEditing');

cy.getByCls('editor-select-box-layer').should('be.not.visible');
});

it(`should remove drop-down layer when calling resetData() API (${type})`, () => {
createGridWithType(type);

cy.gridInstance().invoke('resetData', dataForGridWithType);

cy.getByCls('editor-select-box-layer').should('be.not.visible');
});
});
});
});

// @TODO: should rewrite test case after modifying casting editing value
Expand Down Expand Up @@ -586,7 +606,7 @@ describe('original cell value should be kept', () => {
});
});

describe.only('Scroll with editor that has drop-down layer', () => {
describe('Scroll with editor that has drop-down layer', () => {
function scrollTo(position: Cypress.PositionType) {
cy.getByCls('rside-area', 'body-area').wait(0).scrollTo(position);
}
Expand Down
12 changes: 5 additions & 7 deletions packages/toast-ui.grid/src/view/editingLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ export class EditingLayerComp extends Component<Props> {
private cancelEditing() {
const { rowKey, columnName, value } = this.getEditingCellInfo();

// eslint-disable-next-line no-unused-expressions
this.editor?.beforeDestroy?.();

this.props.dispatch('finishEditing', rowKey, columnName, value, {
save: false,
triggeredByKey: true,
Expand All @@ -104,10 +101,6 @@ export class EditingLayerComp extends Component<Props> {
const { rowKey, columnName, value } = this.getEditingCellInfo();

dispatch('setValue', rowKey, columnName, value);

// eslint-disable-next-line no-unused-expressions
this.editor?.beforeDestroy?.();

dispatch('finishEditing', rowKey, columnName, value, { save: true, triggeredByKey });
}
}
Expand Down Expand Up @@ -195,6 +188,11 @@ export class EditingLayerComp extends Component<Props> {
} = this.props;
const { focusedColumnName, focusedRowKey, active, forcedDestroyEditing } = nextProps;

if (prevActive && !active) {
// eslint-disable-next-line no-unused-expressions
this.editor?.beforeDestroy?.();
}

if (
(prevActive && !active && forcedDestroyEditing) ||
(prevActive &&
Expand Down

0 comments on commit 13947c1

Please sign in to comment.