diff --git a/src/GridItem.ts b/src/GridItem.ts index f92f391..daaff88 100644 --- a/src/GridItem.ts +++ b/src/GridItem.ts @@ -28,7 +28,7 @@ export interface GridItemStatus { mountState?: MOUNT_STATE; updateState?: UPDATE_STATE; isFirstUpdate?: boolean; - attributes?: Record; + attributes?: Record; orgCSSText?: string; orgRect?: Required; rect?: Required; diff --git a/src/ItemRenderer.ts b/src/ItemRenderer.ts index 9807062..77f94a7 100644 --- a/src/ItemRenderer.ts +++ b/src/ItemRenderer.ts @@ -67,7 +67,7 @@ export class ItemRenderer { if (updatedItem) { totalItems.forEach((item) => { if (items.indexOf(item) === -1) { - this._updateItem(item, true); + this.updateItem(item, true); } }); } @@ -75,7 +75,7 @@ export class ItemRenderer { } public updateItems(items: GridItem[]) { items.forEach((item) => { - this._updateItem(item); + this.updateItem(item); }); } public getStatus(): ItemRendererStatus { @@ -107,7 +107,7 @@ export class ItemRenderer { this.posPercetage = posPercentage; this.sizePercetage = sizePercentage; } - private _updateItem(item: GridItem, checkSizeGroup?: boolean) { + public updateItem(item: GridItem, checkSizeGroup?: boolean) { const { isEqualSize, isConstantSize, useRoundedSize } = this.options; const initialRects = this.initialRects; const { orgRect, element } = item; @@ -118,10 +118,10 @@ export class ItemRenderer { const attributes: Record = element ? getDataAttributes(element, this.options.attributePrefix) : item.attributes; - const sizeGroup = attributes.sizeGroup || ""; + const sizeGroup = attributes.sizeGroup ?? ""; const isNotEqualSize = attributes.notEqualSize; - if (sizeGroup && initialRects[sizeGroup]) { + if (sizeGroup !== "" && initialRects[sizeGroup]) { rect = initialRects[sizeGroup]; } else if (isEqualSize && !isNotEqualSize && !sizeGroup && initialRects[""]) { rect = initialRects[""]; diff --git a/test/unit/ItemRenderer.spec.ts b/test/unit/ItemRenderer.spec.ts index 9fb2591..0a53b37 100644 --- a/test/unit/ItemRenderer.spec.ts +++ b/test/unit/ItemRenderer.spec.ts @@ -358,7 +358,6 @@ describe("test ItemRenderer", () => { } }); }); - it(`should check get status and restore status`, () => { // Given el.style.cssText = "position: absolute; left: 50px; top: 50px; width: 200px; height: 100px;"; @@ -422,4 +421,44 @@ describe("test ItemRenderer", () => { "test": "data-grid-test", }); }); + it("should check if width and height are entered by sizeGroup", () => { + // Given + itemRenderer = new ItemRenderer({ + horizontal: false, + }); + + itemRenderer.setStatus({ + initialRects: { + "0": { + left: 0, + top: 0, + width: 100, + height: 100, + }, + }, + }); + + const item1 = new GridItem(false, { + attributes: { + sizeGroup: 0, + }, + }); + const item2 = new GridItem(false, { + attributes: { + sizeGroup: 1, + }, + }); + + // When + // update + itemRenderer.updateItem(item1, true); + + // not update + itemRenderer.updateItem(item2, true); + + // Then + expect(item1.rect.width).to.be.deep.equals(100); + expect(item2.rect.width).to.be.deep.equals(0); + }); + });