Skip to content

Commit a808019

Browse files
authored
GraphiQL component: disableTabs prop (#3408)
1 parent fc1ea4c commit a808019

File tree

2 files changed

+44
-35
lines changed

2 files changed

+44
-35
lines changed

.changeset/curvy-balloons-allow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'graphiql': minor
3+
---
4+
5+
Allow disabling tabs and added new prop `disableTabs`

packages/graphiql/src/components/GraphiQL.tsx

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export function GraphiQL({
167167
>
168168
<GraphiQLInterface
169169
showPersistHeadersSettings={shouldPersistHeaders !== false}
170+
disableTabs={props.disableTabs ?? false}
170171
{...props}
171172
/>
172173
</GraphiQLProvider>
@@ -214,6 +215,7 @@ export type GraphiQLInterfaceProps = WriteableEditorProps &
214215
* settings modal.
215216
*/
216217
showPersistHeadersSettings?: boolean;
218+
disableTabs?: boolean;
217219
};
218220

219221
export function GraphiQLInterface(props: GraphiQLInterfaceProps) {
@@ -518,43 +520,45 @@ export function GraphiQLInterface(props: GraphiQLInterfaceProps) {
518520
)}
519521
<div ref={pluginResize.secondRef} className="graphiql-sessions">
520522
<div className="graphiql-session-header">
521-
<Tabs
522-
values={editorContext.tabs}
523-
onReorder={handleReorder}
524-
aria-label="Select active operation"
525-
>
526-
{editorContext.tabs.length > 1 && (
527-
<>
528-
{editorContext.tabs.map((tab, index) => (
529-
<Tab
530-
key={tab.id}
531-
value={tab}
532-
isActive={index === editorContext.activeTabIndex}
533-
>
534-
<Tab.Button
535-
aria-controls="graphiql-session"
536-
id={`graphiql-session-tab-${index}`}
537-
onClick={() => {
538-
executionContext.stop();
539-
editorContext.changeTab(index);
540-
}}
523+
{props.disableTabs ? null : (
524+
<Tabs
525+
values={editorContext.tabs}
526+
onReorder={handleReorder}
527+
aria-label="Select active operation"
528+
>
529+
{editorContext.tabs.length > 1 && (
530+
<>
531+
{editorContext.tabs.map((tab, index) => (
532+
<Tab
533+
key={tab.id}
534+
value={tab}
535+
isActive={index === editorContext.activeTabIndex}
541536
>
542-
{tab.title}
543-
</Tab.Button>
544-
<Tab.Close
545-
onClick={() => {
546-
if (editorContext.activeTabIndex === index) {
537+
<Tab.Button
538+
aria-controls="graphiql-session"
539+
id={`graphiql-session-tab-${index}`}
540+
onClick={() => {
547541
executionContext.stop();
548-
}
549-
editorContext.closeTab(index);
550-
}}
551-
/>
552-
</Tab>
553-
))}
554-
{addTab}
555-
</>
556-
)}
557-
</Tabs>
542+
editorContext.changeTab(index);
543+
}}
544+
>
545+
{tab.title}
546+
</Tab.Button>
547+
<Tab.Close
548+
onClick={() => {
549+
if (editorContext.activeTabIndex === index) {
550+
executionContext.stop();
551+
}
552+
editorContext.closeTab(index);
553+
}}
554+
/>
555+
</Tab>
556+
))}
557+
{addTab}
558+
</>
559+
)}
560+
</Tabs>
561+
)}
558562
<div className="graphiql-session-header-right">
559563
{editorContext.tabs.length === 1 && addTab}
560564
{logo}

0 commit comments

Comments
 (0)