Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow edits to be rejected for EditableCell #2228

Merged
merged 1 commit into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/table/src/cell/editableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class EditableCell extends React.Component<IEditableCellProps, IEditableC

public componentWillReceiveProps(nextProps: IEditableCellProps) {
const { value } = nextProps;
if (value !== this.props.value) {
if (value != null) {
this.setState({ savedValue: value, dirtyValue: value });
}
}
Expand Down
15 changes: 8 additions & 7 deletions packages/table/test/editableCellTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe("<EditableCell>", () => {
expect(onConfirm.called).to.be.true;
});

it("doesn't change edited value on non-value prop changes", () => {
it("changes value state on non-value prop changes", () => {
const onCancel = sinon.spy();
const onChange = sinon.spy();
const onConfirm = sinon.spy();
Expand All @@ -83,16 +83,17 @@ describe("<EditableCell>", () => {
expect(onConfirm.called).to.be.false;
expect(elem.find(`.${Classes.TABLE_EDITABLE_TEXT} .pt-editable-content`).text()).to.equal("new-text");

// set non-value prop
elem.setProps({ onChange: null });

// value stays the same
expect(elem.find(`.${Classes.TABLE_EDITABLE_TEXT} .pt-editable-content`).text()).to.equal("new-text");

// confirm
input.simulate("blur");
expect(onCancel.called).to.be.false;
expect(onConfirm.called).to.be.true;
// cell shows user-entered text until re-render
expect(elem.find(`.${Classes.TABLE_EDITABLE_TEXT}`).text()).to.equal("new-text");

// set non-value prop, forces EditableCell update
elem.setProps({ onChange: null });
// value resets to prop
expect(elem.find(`.${Classes.TABLE_EDITABLE_TEXT}`).text()).to.equal("test-value-5000");
});

it("passes index prop to callbacks if index was provided", () => {
Expand Down