Skip to content

Commit

Permalink
feat: scroll tab in view on active
Browse files Browse the repository at this point in the history
affects: @medly-components/core
  • Loading branch information
gmukul01 committed Aug 29, 2024
1 parent 73d9539 commit 5b4168a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/core/src/components/Tabs/Tab/Tab.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { WithStyle } from '@medly-components/utils';
import { memo, useContext } from 'react';
import type { FC } from 'react';
import { memo, useContext, useEffect, useRef } from 'react';
import { TabsContext } from '../Tabs.context';
import * as Styled from './Tab.styled';
import { TabProps } from './types';
import type { FC } from 'react';

const Component: FC<TabProps> = memo(props => {
const ref = useRef<HTMLButtonElement>(null);
const { id, active, label, icon: Icon = null, helperText, count, disabled, disabledLabel, ...restProps } = props,
{ tabSize, tabBackground, variant } = useContext(TabsContext);

useEffect(() => {
active && ref.current && ref.current.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
}, [active]);

return (
<Styled.TabWrapper
{...{ id, active, tabSize, disabled, variant, tabBackground, ...restProps }}
Expand All @@ -16,6 +22,7 @@ const Component: FC<TabProps> = memo(props => {
aria-selected={active ? 'true' : 'false'}
aria-controls={`panel-${id}`}
tabIndex={active ? 0 : -1}
ref={ref}
>
{Icon && <Icon variant={tabSize === 'S' ? 'flat' : 'solid'} />}
<Styled.LabelAndDetailsWrapper>
Expand Down

0 comments on commit 5b4168a

Please sign in to comment.