Skip to content

Commit f5a877c

Browse files
authored
feat(typescript): Add new type for custom tabs function components (#469)
1 parent 4e3eff1 commit f5a877c

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
@@ -363,16 +363,18 @@ Possible values for tabsRole are:
363363
- Tab
364364
- TabPanel
365365
- TabList
366+
- Tabs
366367
367368
#### Pass through properties
368369
369370
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.
370371
371-
```javascript
372+
```tsx
372373
import { Tabs, TabList, Tab, TabPanel } from 'react-tabs';
374+
import type { ReactTabsFunctionComponent, TabProps } from 'react-tabs';
373375
374376
// All custom elements should pass through other props
375-
const CustomTab = ({ children, ...otherProps }) => (
377+
const CustomTab = ({ children, ...otherProps }): ReactTabsFunctionComponent<TabProps> => (
376378
<Tab {...otherProps}>
377379
<h1>{children}</h1>
378380
</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)