diff --git a/core/README.md b/core/README.md index 61bd636..d0563a7 100644 --- a/core/README.md +++ b/core/README.md @@ -256,7 +256,7 @@ function App() { const newData = [...data, { id: `tab-3-${count}`, children: `New Tab ${count}` }]; setData(newData); }; - const tabDrop = (id, index) => { + const tabDrop = (id, index, offset) => { const oldIndex = [...data].findIndex((m) => m.id === id); const newData = insertAndShift([...data], oldIndex, index); setData(newData); @@ -264,7 +264,10 @@ function App() { return ( - tabClick(id, evn)} onTabDrop={(id, index) => tabDrop(id, index)}> + tabClick(id, evn)} + onTabDrop={(id, index, offset) => tabDrop(id, index, offset)} + > {data.map((m, idx) => { return ( @@ -290,7 +293,7 @@ export interface TabsProps extends React.DetailedHTMLProps void; + onTabDrop?: (id: string, index?: number, offset?: XYCoord | null) => void; } export interface TabProps extends React.DetailedHTMLProps, HTMLDivElement> { id: string; diff --git a/core/src/Tab.tsx b/core/src/Tab.tsx index eaabe3b..e65d91a 100644 --- a/core/src/Tab.tsx +++ b/core/src/Tab.tsx @@ -76,8 +76,9 @@ export const Tab: FC> = ({ children, id, index, ...p item: () => { return { id, index }; }, - end: (item) => { - onTabDrop && onTabDrop(id, item.index); + end: (item, monitor) => { + const clientOffset = monitor.getClientOffset(); + onTabDrop && onTabDrop(id, item.index, clientOffset); }, collect: (monitor) => { return { diff --git a/core/src/index.tsx b/core/src/index.tsx index 6085914..9ff5f33 100644 --- a/core/src/index.tsx +++ b/core/src/index.tsx @@ -4,6 +4,7 @@ import { HTML5Backend } from 'react-dnd-html5-backend'; import { Tabs } from './Tabs'; import { Provider } from './store'; import { useEventCallback } from './hooks'; +import type { XYCoord } from 'dnd-core'; export * from './Tab'; export * from './hooks'; @@ -14,7 +15,7 @@ export interface TabsProps extends React.DetailedHTMLProps void; + onTabDrop?: (id: string, index?: number, offset?: XYCoord | null) => void; } const TabContainer: FC> = ({ activeKey, onTabClick, onTabDrop, ...props }) => {