Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add allowScrollCrossTabOnTouchMove props into Tabs Component to improve UX on mobile device #524

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export interface TabsProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'o
moreIcon?: React.ReactNode;
/** @private Internal usage. Not promise will rename in future */
moreTransitionName?: string;

allowScrollCrossTabOnTouchMove?: boolean;
}

function parseTabList(children: React.ReactNode): Tab[] {
Expand Down Expand Up @@ -110,6 +112,7 @@ function Tabs(
onChange,
onTabClick,
onTabScroll,
allowScrollCrossTabOnTouchMove,
...restProps
}: TabsProps,
ref: React.Ref<HTMLDivElement>,
Expand Down Expand Up @@ -215,12 +218,24 @@ function Tabs(
style: tabBarStyle,
panes: children,
};

if (renderTabBar) {
tabNavBar = renderTabBar(tabNavBarProps, TabNavList);
} else {
tabNavBar = <TabNavList {...tabNavBarProps} />;
}

useEffect(() => {
if(allowScrollCrossTabOnTouchMove){
const rcTabsNav : Element | undefined = document.getElementsByClassName('rc-tabs-nav')[0];
if(rcTabsNav){
rcTabsNav.addEventListener('touchmove', function(ev){
ev.stopPropagation();
})
}
}

}, []);

return (
<TabContext.Provider value={{ tabs, prefixCls }}>
Expand Down