Skip to content

Commit 51b30bb

Browse files
committed
feat(typescript): Add new type for custom tabs function components (#469)
1 parent 0cb15ff commit 51b30bb

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -374,16 +374,18 @@ Possible values for tabsRole are:
374374
- Tab
375375
- TabPanel
376376
- TabList
377+
- Tabs
377378
378379
#### Pass through properties
379380
380381
Note: Because of how react-tabs works internally (it uses cloning to opaquely control various parts of the tab state), you need to pass any incoming props to the component you're wrapping. The easiest way to do this is to use the rest and spread operators, e.g. see `{...otherProps}` below.
381382
382-
```javascript
383+
```tsx
383384
import { Tabs, TabList, Tab, TabPanel } from 'react-tabs';
385+
import type { ReactTabsFunctionComponent, TabProps } from 'react-tabs';
384386
385387
// All custom elements should pass through other props
386-
const CustomTab = ({ children, ...otherProps }) => (
388+
const CustomTab = ({ children, ...otherProps }): ReactTabsFunctionComponent<TabProps> => (
387389
<Tab {...otherProps}>
388390
<h1>{children}</h1>
389391
</Tab>

index.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export interface TabPanelProps
4141
selectedClassName?: string | undefined;
4242
}
4343

44+
export interface ReactTabsFunctionComponent<P = {}> extends FunctionComponent<P> {
45+
tabsRole: 'Tabs' | 'TabList' | 'Tab' | 'TabPanel';
46+
}
47+
4448
export const Tabs: FunctionComponent<TabsProps>;
4549
export const TabList: FunctionComponent<TabListProps>;
4650
export const Tab: FunctionComponent<TabProps>;

0 commit comments

Comments
 (0)