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

GraphiQL component: disableTabs prop #3408

Merged
merged 2 commits into from
Dec 11, 2023
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
5 changes: 5 additions & 0 deletions .changeset/curvy-balloons-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphiql': minor
---

Allow disabling tabs and added new prop `disableTabs`
74 changes: 39 additions & 35 deletions packages/graphiql/src/components/GraphiQL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
>
<GraphiQLInterface
showPersistHeadersSettings={shouldPersistHeaders !== false}
disableTabs={props.disableTabs ?? false}
{...props}
/>
</GraphiQLProvider>
Expand Down Expand Up @@ -214,6 +215,7 @@
* settings modal.
*/
showPersistHeadersSettings?: boolean;
disableTabs?: boolean;
};

export function GraphiQLInterface(props: GraphiQLInterfaceProps) {
Expand Down Expand Up @@ -518,43 +520,45 @@
)}
<div ref={pluginResize.secondRef} className="graphiql-sessions">
<div className="graphiql-session-header">
<Tabs
values={editorContext.tabs}
onReorder={handleReorder}
aria-label="Select active operation"
>
{editorContext.tabs.length > 1 && (
<>
{editorContext.tabs.map((tab, index) => (
<Tab
key={tab.id}
value={tab}
isActive={index === editorContext.activeTabIndex}
>
<Tab.Button
aria-controls="graphiql-session"
id={`graphiql-session-tab-${index}`}
onClick={() => {
executionContext.stop();
editorContext.changeTab(index);
}}
{props.disableTabs ? null : (
<Tabs
values={editorContext.tabs}
onReorder={handleReorder}
aria-label="Select active operation"
>
{editorContext.tabs.length > 1 && (
<>
{editorContext.tabs.map((tab, index) => (
<Tab
key={tab.id}
value={tab}
isActive={index === editorContext.activeTabIndex}
>
{tab.title}
</Tab.Button>
<Tab.Close
onClick={() => {
if (editorContext.activeTabIndex === index) {
<Tab.Button
aria-controls="graphiql-session"
id={`graphiql-session-tab-${index}`}
onClick={() => {
executionContext.stop();
}
editorContext.closeTab(index);
}}
/>
</Tab>
))}
{addTab}
</>
)}
</Tabs>
editorContext.changeTab(index);

Check warning on line 542 in packages/graphiql/src/components/GraphiQL.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql/src/components/GraphiQL.tsx#L542

Added line #L542 was not covered by tests
}}
>
{tab.title}
</Tab.Button>
<Tab.Close
onClick={() => {
if (editorContext.activeTabIndex === index) {
executionContext.stop();

Check warning on line 550 in packages/graphiql/src/components/GraphiQL.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql/src/components/GraphiQL.tsx#L550

Added line #L550 was not covered by tests
}
editorContext.closeTab(index);
}}
/>
</Tab>
))}
{addTab}
</>
)}
</Tabs>
)}
<div className="graphiql-session-header-right">
{editorContext.tabs.length === 1 && addTab}
{logo}
Expand Down
Loading