Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Commit

Permalink
fix(tabs): when on mobile the inital active tab should be scrolled in…
Browse files Browse the repository at this point in the history
…to view
  • Loading branch information
fritzschoff committed Jul 28, 2022
1 parent 8d8a862 commit 518a778
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/components/Tab/Tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ export type TabProps = {
onClick: () => void;
className?: string;
testId?: string;
id: string;
};

export const Tab: React.FC<TabProps> = ({ text, active, onClick, disabled, className, testId }) => (
export const Tab: React.FC<TabProps> = ({
text,
active,
onClick,
disabled,
className,
testId,
id
}) => (
<button
className={clsx(
'ui-transition ui-border ui-border-transparent ui-ease-out ui-rounded-[100px] ui-px-2 ui-py-1.5 ui-whitespace-nowrap',
Expand All @@ -24,6 +33,7 @@ export const Tab: React.FC<TabProps> = ({ text, active, onClick, disabled, class
className
)}
data-testid={testId}
id={id}
onClick={onClick}
>
{text}
Expand Down
7 changes: 6 additions & 1 deletion src/components/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import clsx from 'clsx';
import React, { useCallback, useMemo, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';

import { Tab } from '../Tab/Tab';

Expand Down Expand Up @@ -45,6 +45,10 @@ export const Tabs: React.FC<TabsProps> = ({
[activeTab, items]
);

useEffect(() => {
if (typeof document !== 'undefined') document.getElementById(String(initial))?.scrollIntoView();
}, [initial]);

return (
<>
<div
Expand All @@ -57,6 +61,7 @@ export const Tabs: React.FC<TabsProps> = ({
active={item.id === activeTab}
className={clsx('ui-mx-2', tabClassName)}
disabled={item.disabled}
id={item.id}
testId={'tab-' + item.id}
text={item.label}
onClick={() => selectTab(item)}
Expand Down

0 comments on commit 518a778

Please sign in to comment.