From 4a8bf47f3e5b0dfbf5a2534cc37757a9acedaa21 Mon Sep 17 00:00:00 2001 From: Alec Flett Date: Mon, 11 Feb 2019 15:50:36 -0800 Subject: [PATCH 1/3] add editabeTextProps to allow adjusting cells during editing --- packages/table/src/cell/editableCell.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/table/src/cell/editableCell.tsx b/packages/table/src/cell/editableCell.tsx index bfeed5b6408..d65dc6bc9b7 100644 --- a/packages/table/src/cell/editableCell.tsx +++ b/packages/table/src/cell/editableCell.tsx @@ -12,6 +12,7 @@ import { Hotkey, Hotkeys, HotkeysTarget, + IEditableTextProps, Utils as CoreUtils, } from "@blueprintjs/core"; @@ -55,6 +56,11 @@ export interface IEditableCellProps extends ICellProps { * were originally provided via props. */ onConfirm?: (value: string, rowIndex?: number, columnIndex?: number) => void; + + /** + * Props that should be passed to the EditableText when it is used to edit + */ + editableTextProps?: IEditableTextProps; } export interface IEditableCellState { @@ -111,17 +117,27 @@ export class EditableCell extends React.Component Date: Mon, 11 Feb 2019 16:00:06 -0800 Subject: [PATCH 2/3] add tests --- packages/table/test/editableCellTests.tsx | 46 +++++++++++++++++++---- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/packages/table/test/editableCellTests.tsx b/packages/table/test/editableCellTests.tsx index e73b1e6e8de..0db14f5d8f3 100644 --- a/packages/table/test/editableCellTests.tsx +++ b/packages/table/test/editableCellTests.tsx @@ -9,14 +9,15 @@ import { mount } from "enzyme"; import * as React from "react"; import * as sinon from "sinon"; -import * as Classes from "../src/common/classes"; +import { Classes } from "@blueprintjs/core"; +import * as TableClasses from "../src/common/classes"; import { EditableCell } from "../src/index"; import { CellType, expectCellLoading } from "./cellTestUtils"; describe("", () => { it("renders", () => { const elem = mount(); - expect(elem.find(`.${Classes.TABLE_TRUNCATED_TEXT}`).text()).to.equal("test-value-5000"); + expect(elem.find(`.${TableClasses.TABLE_TRUNCATED_TEXT}`).text()).to.equal("test-value-5000"); }); it("renders loading state", () => { @@ -29,10 +30,10 @@ describe("", () => { const VALUE_2 = "bar"; const elem = mount(); - expect(elem.find(`.${Classes.TABLE_TRUNCATED_TEXT}`).text()).to.equal(VALUE_1); + expect(elem.find(`.${TableClasses.TABLE_TRUNCATED_TEXT}`).text()).to.equal(VALUE_1); elem.setProps({ value: VALUE_2 }); - expect(elem.find(`.${Classes.TABLE_TRUNCATED_TEXT}`).text()).to.equal(VALUE_2); + expect(elem.find(`.${TableClasses.TABLE_TRUNCATED_TEXT}`).text()).to.equal(VALUE_2); }); it("edits", () => { @@ -73,7 +74,7 @@ describe("", () => { // start editing elem.setState({ isEditing: true, dirtyValue: "test-value-5000" }); - const input = elem.find(`.${Classes.TABLE_EDITABLE_TEXT} input`); + const input = elem.find(`.${TableClasses.TABLE_EDITABLE_TEXT} input`); expect(input.length).to.equal(1); // make changes @@ -129,11 +130,42 @@ describe("", () => { it("defaults to no wrapText", () => { const elem = mount(); - expect(elem.find(`.${Classes.TABLE_NO_WRAP_TEXT}`).exists()).to.be.true; + expect(elem.find(`.${TableClasses.TABLE_NO_WRAP_TEXT}`).exists()).to.be.true; }); it("wraps text when wrapText is true", () => { const elem = mount(); - expect(elem.find(`.${Classes.TABLE_NO_WRAP_TEXT}`).exists()).to.be.false; + expect(elem.find(`.${TableClasses.TABLE_NO_WRAP_TEXT}`).exists()).to.be.false; + }); + + it("Passes editableTextProps to inner EditableText", () => { + const onCancel = sinon.spy(); + const onChange = sinon.spy(); + const onConfirm = sinon.spy(); + + const elem = mount( + , + ); + + // start editing + elem.setState({ isEditing: true, dirtyValue: "test-value-5000" }); + const input = elem.find("input"); + console.log("input = ", elem.debug()); + // input props that EditableCell does not care about should pass through unchanged + expect(input.prop("maxLength")).to.equal(345); + expect(elem.find(`.${Classes.EDITABLE_TEXT}`).prop("className")).to.contain("input-only-class"); + + // But special values should be overridden by EditableCell + expect(input.prop("value")).to.equal("test-value-5000"); }); }); From 5e5e667ad5eda940852693fe5242ad9ab2613c8d Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Wed, 12 Jun 2019 14:46:43 -0400 Subject: [PATCH 3/3] Fix lint --- packages/table/test/editableCellTests.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/table/test/editableCellTests.tsx b/packages/table/test/editableCellTests.tsx index 0db14f5d8f3..ad2c6a100e3 100644 --- a/packages/table/test/editableCellTests.tsx +++ b/packages/table/test/editableCellTests.tsx @@ -160,7 +160,6 @@ describe("", () => { // start editing elem.setState({ isEditing: true, dirtyValue: "test-value-5000" }); const input = elem.find("input"); - console.log("input = ", elem.debug()); // input props that EditableCell does not care about should pass through unchanged expect(input.prop("maxLength")).to.equal(345); expect(elem.find(`.${Classes.EDITABLE_TEXT}`).prop("className")).to.contain("input-only-class");