Skip to content

Commit

Permalink
chore(wip): remove unmountScroll option and include long name tab
Browse files Browse the repository at this point in the history
  • Loading branch information
cafrias committed Jun 1, 2023
1 parent 6188ba1 commit 8470794
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 64 deletions.
2 changes: 2 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@
"Infima",
"jakejarvis",
"libsass",
"llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogochensis",
"localforage",
"lunr",
"microbundle",
"mixins",
"multiselect",
"Myxococcus",
"Patil",
"popperjs",
"progessbar",
Expand Down
5 changes: 2 additions & 3 deletions packages/react/src/components/Tabs/TabScrollButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const styles = {
export const TabScrollButton = ({ type, onClick, disabled }: TabScrollButtonProps) => {
const text = type === 'left' ? 'Previous' : 'Next';
const icon = type === 'left' ? 'chevron-left' : 'chevron-right';
const { variant, unmountScroll } = useTabsState();
const { variant } = useTabsState();

const className = classNames(
styles.base,
Expand All @@ -32,7 +32,7 @@ export const TabScrollButton = ({ type, onClick, disabled }: TabScrollButtonProp
},
);

if (disabled && unmountScroll) {
if (disabled) {
return null;
}

Expand All @@ -42,7 +42,6 @@ export const TabScrollButton = ({ type, onClick, disabled }: TabScrollButtonProp
onClick={onClick}
aria-hidden
tabIndex={-1}
disabled={disabled}
>
<Icon variant={icon} />
<span className={styles.text}>{text}</span>
Expand Down
4 changes: 1 addition & 3 deletions packages/react/src/components/Tabs/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function useInitCommonTabsState({
align,
idPrefix: userSetIdPrefix,
variant,
unmountScroll,
}: CommonTabsProps): Omit<TabsState, 'selectedTabIndex' | 'setSelectedTabIndex'> {
const generatedIdPrefix = useId() as string;
const idPrefix = userSetIdPrefix || generatedIdPrefix;
Expand All @@ -22,8 +21,7 @@ function useInitCommonTabsState({
idPrefix,
align: align || 'left',
variant: variant || 'contained',
unmountScroll: unmountScroll || false,
}), [align, idPrefix, variant, unmountScroll]);
}), [align, idPrefix, variant]);
}

export function useInitUncontrolledTabsState({
Expand Down
35 changes: 14 additions & 21 deletions packages/react/src/components/Tabs/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ControlledTabsProps,
} from '.';
import { Button } from '../Button';
import { Link } from '../Link';

export default {
title: 'Tabs',
Expand All @@ -28,6 +29,8 @@ export const Uncontrolled = () => (
<Tab disabled>Horses</Tab>
<Tab>Cows</Tab>
<Tab>Beavers</Tab>
<Tab>Camels</Tab>
<Tab>Myxococcus llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogochensis</Tab>
</TabList>
<TabPanels>
<TabPanel>Cats content</TabPanel>
Expand All @@ -39,6 +42,17 @@ export const Uncontrolled = () => (
<Button onClick={() => console.log('Moo!')}>Moo!</Button>
</TabPanel>
<TabPanel>Beavers content</TabPanel>
<TabPanel>Camels content</TabPanel>
<TabPanel>
Myxococcus llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogochensis content.
{' '}
<Link
external
href="https://en.wikipedia.org/wiki/Myxococcus_llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogochensis"
>
Wiki page
</Link>
</TabPanel>
</TabPanels>
</Tabs>
</div>
Expand Down Expand Up @@ -114,27 +128,6 @@ export const Line = () => (
</div>
);

export const unmountScroll = () => (
<div style={{ maxWidth: '960px' }}>
<Tabs defaultSelectedIndex={0} unmountScroll>
<TabList>
<Tab>Cats</Tab>
<Tab>Dogs</Tab>
<Tab disabled>Horses</Tab>
<Tab>Cows</Tab>
<Tab>Beavers</Tab>
</TabList>
<TabPanels>
<TabPanel>Cats content</TabPanel>
<TabPanel>Dogs content</TabPanel>
<TabPanel>Horses content</TabPanel>
<TabPanel>Cows content</TabPanel>
<TabPanel>Beavers content</TabPanel>
</TabPanels>
</Tabs>
</div>
);

Controlled.args = {
selectedIndex: 1,
};
2 changes: 0 additions & 2 deletions packages/react/src/components/Tabs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export type CommonTabsProps = React.PropsWithChildren<{
idPrefix?: string;
align?: 'left' | 'center';
variant?: 'contained' | 'line';
unmountScroll?: boolean;
}>;

export type TabListProps = React.ComponentPropsWithRef<'div'> & {
Expand All @@ -45,5 +44,4 @@ export interface TabsState {
setSelectedTabIndex: (index: number) => void;
variant: NonNullable<CommonTabsProps['variant']>;
align: NonNullable<CommonTabsProps['align']>;
unmountScroll: NonNullable<CommonTabsProps['unmountScroll']>;
}
4 changes: 0 additions & 4 deletions packages/react/src/components/Tabs/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import _defer from 'lodash/defer';

const focusableSelectors = [
'[contentEditable=true]:not([tabindex="-1"])',
'[tabindex]:not([tabindex="-1"])',
Expand Down Expand Up @@ -32,9 +30,7 @@ export function moveFocusToTabPanel(id: string) {
const firstFocusable = getFocusable(tabPanel)[0];
if (firstFocusable) {
tabPanel.setAttribute('tabindex', '-1');
_defer(() => firstFocusable.focus());
} else {
tabPanel.setAttribute('tabindex', '0');
_defer(() => tabPanel.focus());
}
}
31 changes: 0 additions & 31 deletions website/docs/components/tabs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,37 +54,6 @@ import { Tabs, TabList, Tab, TabPanels, TabPanel } from '@wwnds/react';
</Tabs>
```

### Unmounted scroll buttons

```tsx live
<Tabs unmountScroll>
<TabList>
<Tab>Cats</Tab>
<Tab>Dogs</Tab>
<Tab disabled>Horses</Tab>
<Tab>Cows</Tab>
<Tab>Beavers</Tab>
<Tab>Pigs</Tab>
<Tab>Chicken</Tab>
<Tab>Elf</Tab>
<Tab>Dragon</Tab>
<Tab>Orc</Tab>
</TabList>
<TabPanels>
<TabPanel>Cats content</TabPanel>
<TabPanel>Dogs content</TabPanel>
<TabPanel>Horses content</TabPanel>
<TabPanel>Cows content</TabPanel>
<TabPanel>Beavers content</TabPanel>
<TabPanel>Pigs content</TabPanel>
<TabPanel>Chicken content</TabPanel>
<TabPanel>Elf content</TabPanel>
<TabPanel>Dragon content</TabPanel>
<TabPanel>Orc content</TabPanel>
</TabPanels>
</Tabs>
```

### Centered Alignment

```tsx live
Expand Down

0 comments on commit 8470794

Please sign in to comment.