Skip to content

Commit e82dde0

Browse files
authored
Merge pull request #449 from open-rpc/feat/per-method-default-expanded
feat: per method default expanded uiSchema
2 parents 8e5fd7e + 6565975 commit e82dde0

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

src/Methods/Methods.test.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,62 @@ it("renders collapsed contents with defaultExpanded from uiSchema", () => {
8585
ReactDOM.unmountComponentAtNode(div);
8686
});
8787

88+
it("renders collapsed contents with defaultExpanded with the method from uiSchema", () => {
89+
const div = document.createElement("div");
90+
const schema = {
91+
methods: [
92+
{
93+
name: "foomethod",
94+
params: [{
95+
name: "foobarz",
96+
}],
97+
},
98+
],
99+
};
100+
const uiSchema = {
101+
links: {
102+
},
103+
methods: {
104+
"ui:defaultExpanded": {
105+
foomethod: true,
106+
},
107+
},
108+
params: {
109+
},
110+
};
111+
ReactDOM.render(<Methods uiSchema={uiSchema} schema={schema as any} disableTransitionProps={true} />, div);
112+
expect(div.innerHTML.includes("aria-expanded=\"true\"")).toBe(true);
113+
ReactDOM.unmountComponentAtNode(div);
114+
});
115+
116+
it("doesnt render collapsed contents with wrong method name and defaultExpanded with method", () => {
117+
const div = document.createElement("div");
118+
const uiSchema = {
119+
links: {
120+
},
121+
methods: {
122+
"ui:defaultExpanded": {
123+
foomethod: true,
124+
},
125+
},
126+
params: {
127+
},
128+
};
129+
const schema = {
130+
methods: [
131+
{
132+
name: "foomethod2",
133+
params: [{
134+
name: "foobarz",
135+
}],
136+
},
137+
],
138+
};
139+
ReactDOM.render(<Methods uiSchema={uiSchema} schema={schema as any} />, div);
140+
expect(div.innerHTML.includes("foobarz")).toBe(false);
141+
ReactDOM.unmountComponentAtNode(div);
142+
});
143+
88144
it("renders collapsed contents with disableTransitionProps", () => {
89145
const div = document.createElement("div");
90146
const schema = {

src/Methods/Methods.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ class Methods extends Component<IProps> {
6969
<Typography variant="h3" gutterBottom>Methods</Typography>
7070
{schema.methods.map((method, i) => (
7171
<ExpansionPanel
72+
id={method.name}
7273
key={i + method.name}
7374
TransitionProps={{ unmountOnExit: disableTransitionProps ? false : true }}
74-
defaultExpanded={uiSchema && uiSchema.methods["ui:defaultExpanded"]}
75+
defaultExpanded={uiSchema && (uiSchema.methods["ui:defaultExpanded"] === true || uiSchema.methods["ui:defaultExpanded"][method.name] === true)}
7576
>
7677
<ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>
7778
<Typography key={method.name} className={classes.heading}>{method.name}</Typography>
@@ -89,7 +90,7 @@ class Methods extends Component<IProps> {
8990
uiSchema={uiSchema}
9091
source={method.description}
9192
className={classes.description}
92-
/>
93+
/>
9394
</ExpansionPanelDetails>
9495
}
9596
{method.params && method.params.length > 0 &&

0 commit comments

Comments
 (0)