Skip to content

Commit

Permalink
fix(prop-list): setChangeValue when propValue changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lynette-li committed Aug 5, 2020
1 parent d97abbe commit 9eb595f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/panel/components/PropList.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { shallow } from "enzyme";
import { shallow, mount } from "enzyme";
import { Icon, TextArea } from "@blueprintjs/core";
import { PropList, PropItem } from "./PropList";
import { PROP_DEHYDRATED } from "../../shared/constants";
Expand Down Expand Up @@ -155,4 +155,16 @@ describe("PropItem", () => {
wrapper.find(TextArea).invoke("onBlur")({} as any);
expect(wrapper.find(".bp3-intent-danger").length).toBe(0);
});

it("should set changeValue when propValue changes", () => {
const wrapper = mount(
<PropItem propName="quality" propValue="good" editable />
);
wrapper.find(".prop-value").invoke("onDoubleClick")({} as any);
wrapper.setProps({
propValue: "bad",
});
wrapper.update();
expect(wrapper.find(TextArea).prop("value")).toBe('"bad"');
});
});
6 changes: 5 additions & 1 deletion src/panel/components/PropList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect } from "react";
import classNames from "classnames";
import { Icon, TextArea } from "@blueprintjs/core";
import { PROP_DEHYDRATED } from "../../shared/constants";
Expand Down Expand Up @@ -98,6 +98,10 @@ export function PropItem({

const hasChildren = isObject(propValue);

useEffect(() => {
setChangeValue(JSON.stringify(propValue, null, 2));
}, [propValue]);

return React.createElement(
standalone ? "div" : "li",
{
Expand Down

0 comments on commit 9eb595f

Please sign in to comment.