Skip to content

Commit 58d1f54

Browse files
authored
fix(file-tab): close button (#1198)
* fix(file-tab): close button * fix * fix
1 parent 292a63c commit 58d1f54

File tree

2 files changed

+17
-36
lines changed

2 files changed

+17
-36
lines changed
Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import React from "react";
33

4-
import { Sandpack } from "./";
4+
import {
5+
SandpackCodeEditor,
6+
SandpackFileExplorer,
7+
SandpackLayout,
8+
SandpackProvider,
9+
} from "./";
510

611
export default {
712
title: "Intro/Playground",
@@ -10,28 +15,12 @@ export default {
1015
export const Basic: React.FC = () => {
1116
return (
1217
<div style={{ height: "400vh" }}>
13-
<Sandpack
14-
options={{
15-
showTabs: true,
16-
closableTabs: true,
17-
experimental_enableServiceWorker: true,
18-
experimental_enableStableServiceWorkerId: true,
19-
}}
20-
// customSetup={{
21-
// dependencies: {
22-
// "react-content-loader": "latest",
23-
// "radix-ui": "latest",
24-
// "styled-components": "latest",
25-
// "react-dom": "latest",
26-
// react: "latest",
27-
// "react-table": "latest",
28-
// },
29-
// }}
30-
// options={{
31-
// bundlerURL: "https://ymxnqs-3000.csb.app",
32-
// }}
33-
template="react"
34-
/>
18+
<SandpackProvider>
19+
<SandpackLayout>
20+
<SandpackFileExplorer />
21+
<SandpackCodeEditor closableTabs showTabs />
22+
</SandpackLayout>
23+
</SandpackProvider>
3524
</div>
3625
);
3726
};

sandpack-react/src/components/FileTabs/index.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,6 @@ export const FileTabs = ({
9696
const { activeFile, visibleFiles, setActiveFile } = sandpack;
9797
const [hoveredIndex, setIsHoveredIndex] = React.useState<null | number>(null);
9898

99-
const handleCloseFile = (ev: React.MouseEvent<HTMLDivElement>): void => {
100-
ev.stopPropagation();
101-
const tabElm = (ev.target as HTMLElement).closest(
102-
"[data-active]"
103-
) as HTMLElement;
104-
const pathToClose = tabElm?.getAttribute("title");
105-
if (!pathToClose) {
106-
return;
107-
}
108-
sandpack.closeFile(pathToClose);
109-
};
110-
11199
const getTriggerText = (currentPath: string): string => {
112100
const documentFileName = getFileName(currentPath);
113101

@@ -224,7 +212,11 @@ export const FileTabs = ({
224212
{closableTabs && visibleFiles.length > 1 && (
225213
<span
226214
className={classNames("close-button", [closeButtonClassName])}
227-
onClick={handleCloseFile}
215+
onClick={(ev) => {
216+
ev.stopPropagation();
217+
218+
sandpack.closeFile(filePath);
219+
}}
228220
style={{
229221
visibility:
230222
filePath === activeFile || hoveredIndex === index

0 commit comments

Comments
 (0)