Skip to content

Commit a95afe6

Browse files
remyfrenck
andauthored
use html5 details element instead of javascript (#2531)
* use html5 details element instead of javascript Reduces reliance on JS for content. I found when the JS didn't full load (flaky connection), I couldn't open these detail blocks. * fix: remove the unused click handler --------- Co-authored-by: Franck Nijhof <[email protected]>
1 parent 7bb5a07 commit a95afe6

File tree

1 file changed

+17
-35
lines changed

1 file changed

+17
-35
lines changed

static/js/api_endpoint.jsx

+17-35
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,27 @@ import React from 'react';
33
// Styles for this element is defined in src/css/custom.css
44

55
export default class ApiEndpoint extends React.Component {
6-
constructor(props){
7-
super(props);
8-
this.state = {
9-
open: false
10-
}
11-
this.toggleInfo = this.toggleInfo.bind(this);
12-
}
13-
14-
toggleInfo(e){
15-
this.setState({open: !this.state.open})
16-
}
17-
186
render() {
197
return (
20-
<div className="api-endpoint">
21-
<div
22-
onClick={this.toggleInfo}
23-
className="api-endpoint-header"
24-
>
25-
<div className={`api-endpoint-method ${ this.props.method }`}>
8+
<details className="api-endpoint">
9+
<summary className="api-endpoint-header">
10+
<div className={`api-endpoint-method ${this.props.method}`}>
2611
{this.props.method}
2712
</div>
28-
<code>{this.props.path}</code>
29-
<div
30-
className="api-endpoint-protection"
31-
title={this.props.unprotected ?
32-
"Authentication is not required for this endpoint"
33-
: "Authentication is required for this endpoint"
34-
}
35-
>
36-
{this.props.unprotected ? ("🔓") : ("🔒")}
37-
</div>
13+
<code>{this.props.path}</code>
14+
<div
15+
className="api-endpoint-protection"
16+
title={
17+
this.props.unprotected
18+
? 'Authentication is not required for this endpoint'
19+
: 'Authentication is required for this endpoint'
20+
}>
21+
{this.props.unprotected ? '🔓' : '🔒'}
3822
</div>
39-
{this.state.open ? (
40-
<div className="api-endpoint-content">
41-
{this.props.children}
42-
</div>
43-
): null}
44-
</div>
23+
</summary>
24+
25+
<div className="api-endpoint-content">{this.props.children}</div>
26+
</details>
4527
);
4628
}
47-
}
29+
}

0 commit comments

Comments
 (0)