Skip to content

Commit

Permalink
feat: allow overriding route key property
Browse files Browse the repository at this point in the history
  • Loading branch information
andreialecu committed Nov 30, 2020
1 parent 58fc1c5 commit c7ea905
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/CollapsibleTabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export type Props<T extends Route> = Partial<TabViewProps<T>> &
* 0 and 1. Default is 0.5.
*/
snapThreshold?: number;
/**
* The property from the `routes` map to use for the active route key
* Default is 'key'
*/
routeKeyProp?: keyof Extract<T, string>;
};

/**
Expand All @@ -101,6 +106,7 @@ const CollapsibleTabView = <T extends Route>({
renderTabBar: customRenderTabBar,
onHeaderHeightChange,
snapThreshold = 0.5,
routeKeyProp = 'key',
...tabViewProps
}: React.PropsWithoutRef<Props<T>>): React.ReactElement => {
const [headerHeight, setHeaderHeight] = React.useState(initialHeaderHeight);
Expand Down Expand Up @@ -289,7 +295,7 @@ const CollapsibleTabView = <T extends Route>({
return (
<CollapsibleContextProvider
value={{
activeRouteKey: routes[index].key,
activeRouteKey: routes[index][routeKeyProp as keyof Route] as string,
scrollY,
buildGetRef,
headerHeight,
Expand Down

0 comments on commit c7ea905

Please sign in to comment.