Skip to content

Commit

Permalink
GraphiQL component: disableTabs prop (#3408)
Browse files Browse the repository at this point in the history
  • Loading branch information
TuvalSimha authored Dec 11, 2023
1 parent fc1ea4c commit a808019
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 35 deletions.
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 @@ export function GraphiQL({
>
<GraphiQLInterface
showPersistHeadersSettings={shouldPersistHeaders !== false}
disableTabs={props.disableTabs ?? false}
{...props}
/>
</GraphiQLProvider>
Expand Down Expand Up @@ -214,6 +215,7 @@ export type GraphiQLInterfaceProps = WriteableEditorProps &
* settings modal.
*/
showPersistHeadersSettings?: boolean;
disableTabs?: boolean;
};

export function GraphiQLInterface(props: GraphiQLInterfaceProps) {
Expand Down Expand Up @@ -518,43 +520,45 @@ export function GraphiQLInterface(props: GraphiQLInterfaceProps) {
)}
<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);
}}
>
{tab.title}
</Tab.Button>
<Tab.Close
onClick={() => {
if (editorContext.activeTabIndex === index) {
executionContext.stop();
}
editorContext.closeTab(index);
}}
/>
</Tab>
))}
{addTab}
</>
)}
</Tabs>
)}
<div className="graphiql-session-header-right">
{editorContext.tabs.length === 1 && addTab}
{logo}
Expand Down

0 comments on commit a808019

Please sign in to comment.