Skip to content

Commit 0ebd2b9

Browse files
authored
allow pressing enter to perform the 'Execute' action (#255)
1 parent 8cb79f3 commit 0ebd2b9

8 files changed

Lines changed: 43 additions & 25 deletions

File tree

packages/docusaurus-theme-openapi/src/theme/ApiDemoPanel/Authorization/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function LockButton({ mode, children, style, ...rest }: Props) {
3333
marginBottom: "var(--ifm-spacing-vertical)",
3434
...style,
3535
}}
36+
type="button"
3637
{...rest}
3738
>
3839
<span>{children}</span>

packages/docusaurus-theme-openapi/src/theme/ApiDemoPanel/Curl/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ function Curl({ postman, codeSamples }: Props) {
225225
language === lang ? "api-code-tab--active" : undefined,
226226
"api-code-tab"
227227
)}
228+
type="button"
228229
onClick={() => setLanguage(lang)}
229230
>
230231
{lang.tabName || lang.label}

packages/docusaurus-theme-openapi/src/theme/ApiDemoPanel/Execute/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function Execute({ postman, proxy }: Props) {
7878
dispatch(setResponse(e.message ?? "Error fetching."));
7979
}
8080
}}
81+
type="submit"
8182
>
8283
Execute
8384
</button>

packages/docusaurus-theme-openapi/src/theme/ApiDemoPanel/FloatingButton/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ interface Props {
1818
function FloatingButton({ label, onClick, children }: Props) {
1919
return (
2020
<div className={styles.floatingButton}>
21-
{label && <button onClick={onClick}>{label}</button>}
21+
{label && (
22+
<button onClick={onClick} type="button">
23+
{label}
24+
</button>
25+
)}
2226
{children}
2327
</div>
2428
);

packages/docusaurus-theme-openapi/src/theme/ApiDemoPanel/FormFileUpload/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ function FormFileUpload({ placeholder, onChange }: Props) {
9696
<>
9797
<button
9898
style={{ marginTop: "calc(var(--ifm-pre-padding) / 2)" }}
99+
type="button"
99100
onClick={(e) => {
100101
e.stopPropagation();
101102
setAndNotifyFile(undefined);

packages/docusaurus-theme-openapi/src/theme/ApiDemoPanel/ParamOptions/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function ParamOptions() {
8686
<>
8787
<button
8888
className={styles.showMoreButton}
89+
type="button"
8990
onClick={() => setShowOptional((prev) => !prev)}
9091
>
9192
<span
@@ -225,6 +226,7 @@ function ParamArrayFormItem({ param }: ParamProps) {
225226
<ArrayItem param={param} onChange={handleChangeItem(item)} />
226227
<button
227228
className={styles.buttonDelete}
229+
type="button"
228230
onClick={handleDeleteItem(item)}
229231
>
230232
<svg
@@ -245,6 +247,7 @@ function ParamArrayFormItem({ param }: ParamProps) {
245247
))}
246248
<button
247249
className={styles.buttonThin}
250+
type="button"
248251
onClick={handleAddItem}
249252
disabled={
250253
param?.schema?.maxItems != null &&

packages/docusaurus-theme-openapi/src/theme/ApiDemoPanel/Server/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function Server() {
6262
<button
6363
className={styles.showMoreButton}
6464
onClick={() => setIsEditing(false)}
65+
type="button"
6566
>
6667
Hide
6768
</button>

packages/docusaurus-theme-openapi/src/theme/ApiDemoPanel/index.tsx

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,40 +87,46 @@ function ApiDemoPanel({ item }: Props) {
8787
[persistanceMiddleware]
8888
);
8989

90+
const handleSubmit = (e: React.FormEvent) => {
91+
e.preventDefault();
92+
};
93+
9094
const { path, method } = item;
9195

9296
return (
9397
<Provider store={store2}>
9498
<div style={{ marginTop: "3.5em" }}>
95-
<Authorization />
96-
97-
{item.operationId !== undefined && (
98-
<div style={{ marginBottom: "var(--ifm-table-cell-padding)" }}>
99-
<code>
100-
<b>{item.operationId}</b>
101-
</code>
99+
<form onSubmit={handleSubmit}>
100+
<Authorization />
101+
102+
{item.operationId !== undefined && (
103+
<div style={{ marginBottom: "var(--ifm-table-cell-padding)" }}>
104+
<code>
105+
<b>{item.operationId}</b>
106+
</code>
107+
</div>
108+
)}
109+
110+
<MethodEndpoint method={method} path={path} />
111+
112+
<div className={styles.optionsPanel}>
113+
<ParamOptions />
114+
<Body
115+
jsonRequestBodyExample={item.jsonRequestBodyExample}
116+
requestBodyMetadata={item.requestBody}
117+
/>
118+
<Accept />
102119
</div>
103-
)}
104120

105-
<MethodEndpoint method={method} path={path} />
121+
<Server />
106122

107-
<div className={styles.optionsPanel}>
108-
<ParamOptions />
109-
<Body
110-
jsonRequestBodyExample={item.jsonRequestBodyExample}
111-
requestBodyMetadata={item.requestBody}
123+
<Curl
124+
postman={postman}
125+
codeSamples={(item as any)["x-code-samples"] ?? []}
112126
/>
113-
<Accept />
114-
</div>
115-
116-
<Server />
117-
118-
<Curl
119-
postman={postman}
120-
codeSamples={(item as any)["x-code-samples"] ?? []}
121-
/>
122127

123-
<Execute postman={postman} proxy={options?.proxy} />
128+
<Execute postman={postman} proxy={options?.proxy} />
129+
</form>
124130

125131
<Response />
126132
</div>

0 commit comments

Comments
 (0)