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(tabs): vertical variation with inner grid #16738

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dc9cbad
feat(vertical-tabs): new tab variant
ariellalgilmore Jun 5, 2024
7bdd11b
fix(tabs): update vertical docs
ariellalgilmore Jun 5, 2024
f0e9267
fix(vertical-tabs): sm to use contained
ariellalgilmore Jun 5, 2024
dbda7c7
fix(tablistvertical): add scrollintoview
ariellalgilmore Jun 6, 2024
7703de1
fix(tabs): hover & disabled styles
ariellalgilmore Jun 10, 2024
66c7133
fix(tabs-vertical): hover border style
ariellalgilmore Jun 10, 2024
31b2232
feat(tabs): vertical variation with inner grid
ariellalgilmore Jun 11, 2024
c9ce4ff
fix(tab-panel): have to account if there is no set height
ariellalgilmore Jun 12, 2024
9373bf5
Merge branch 'main' into feat/vertical-tabs-with-inner-grid
ariellalgilmore Jun 12, 2024
0276bba
fix(tabs): add description to each set
ariellalgilmore Jun 12, 2024
a193306
fix(tabs-v): show tooltip resize & remove right border when selected
ariellalgilmore Jun 14, 2024
80ef618
fix(fields-on-layer): create new style utility to use
ariellalgilmore Jun 17, 2024
0d3034b
fix(tabs): create TabsVertical
ariellalgilmore Jun 18, 2024
5944e2e
fix(tabs): remove no longer needed styles
ariellalgilmore Jun 18, 2024
379ea6c
chore(test): add initial vertical test
ariellalgilmore Jun 18, 2024
3a66f86
fix(tabs-vertical): update to keep index state
ariellalgilmore Jun 20, 2024
92e06ac
chore(merge): update branch and add layer in story
ariellalgilmore Jun 25, 2024
d9d1a26
Merge branch 'main' into feat/vertical-tabs-with-inner-grid
alisonjoseph Jun 27, 2024
7b3e3e4
fix(tabs): remove layer from story add into styles
ariellalgilmore Jun 28, 2024
493be26
fix(tabs): remove layer from story add into styles
ariellalgilmore Jun 28, 2024
c180167
Merge branch 'main' into feat/vertical-tabs-with-inner-grid
ariellalgilmore Jun 28, 2024
d7fae8d
Merge branch 'main' into feat/vertical-tabs-with-inner-grid
ariellalgilmore Jul 1, 2024
5ba02e1
Merge branch 'main' into feat/vertical-tabs-with-inner-grid
alisonjoseph Jul 1, 2024
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
58 changes: 58 additions & 0 deletions e2e/components/Tabs/Tabs-test.avt.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ test.describe('@avt Tabs', () => {
await expect(page).toHaveNoACViolations('Tabs-contained');
});

test('@avt-advanced-states tabs vertical', async ({ page }) => {
await visitStory(page, {
component: 'Tabs',
id: 'components-tabs--vertical',
globals: {
theme: 'white',
},
});
await expect(page).toHaveNoACViolations('Tabs-vertical');
});

test('@avt-advanced-states tabs contained with icons', async ({ page }) => {
await visitStory(page, {
component: 'Tabs',
Expand Down Expand Up @@ -150,6 +161,53 @@ test.describe('@avt Tabs', () => {
await expect(page.getByRole('tab', { name: 'Tab label 4' })).toBeFocused();
});

test.slow('@avt-keyboard-nav', async ({ page }) => {
await visitStory(page, {
component: 'Tabs',
id: 'components-tabs--default',
globals: {
theme: 'white',
},
});

// Focus on the first tab via keyboard navigation
await page.keyboard.press('Tab');
await expect(page.getByRole('tab', { name: 'Tab label 1' })).toBeVisible();

// Focus should be on content within the first Tab
await page.keyboard.press('Tab');
await expect(
page.getByRole('tabpanel', { name: 'Tab Panel 1' })
).toBeFocused();

// Moving back one tab stop we should back on Tab label 1
await page.keyboard.press('Shift+Tab');
await expect(page.getByRole('tab', { name: 'Tab label 1' })).toBeFocused();

// Nav through the default tab panel via keyboard navigation
await page.keyboard.press('ArrowDown');
await expect(page.getByRole('tab', { name: 'Tab label 2' })).toBeVisible();

// Move through the actions in the second tab
await page.keyboard.press('Tab');
await expect(page.getByRole('checkbox')).toBeVisible();

await page.keyboard.press('Tab');
await expect(page.getByRole('button', { name: 'Submit' })).toBeVisible();

await page.keyboard.press('Tab');
await expect(page.getByRole('textbox')).toBeVisible();

await page.keyboard.press('Shift+Tab');
await page.keyboard.press('Shift+Tab');
await page.keyboard.press('Shift+Tab');
await expect(page.getByRole('tab', { name: 'Tab label 2' })).toBeFocused();

// Continue to nav through the default tab panel via keyboard navigation
await page.keyboard.press('ArrowDown');
await expect(page.getByRole('tab', { name: 'Tab label 4' })).toBeFocused();
});

test.slow('@avt-keyboard-nav - dismissable state', async ({ page }) => {
await visitStory(page, {
component: 'Tabs',
Expand Down
8 changes: 8 additions & 0 deletions e2e/components/Tabs/Tabs-test.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ test.describe('Tabs', () => {
theme,
});
});

test('vertical @vrt', async ({ page }) => {
await snapshotStory(page, {
component: 'Tabs',
id: 'components-tabs--vertical',
theme,
});
});
});
});
});
57 changes: 56 additions & 1 deletion packages/react/src/components/Tabs/Tabs-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import React from 'react';
import { Tabs, Tab, TabPanel, TabPanels, TabList } from './Tabs';
import {
Tabs,
TabsVertical,
Tab,
TabPanel,
TabPanels,
TabList,
TabListVertical,
} from './Tabs';
import { act } from 'react';

import { render, screen } from '@testing-library/react';
Expand Down Expand Up @@ -650,3 +658,50 @@ describe('TabList', () => {
expect(container.firstChild).not.toHaveClass(`${prefix}--tabs--full-width`);
});
});

describe('TabListVertical', () => {
it('should render TabList if screen smaller than md', () => {
jest.spyOn(hooks, 'useMatchMedia').mockImplementation(() => false);
const { container } = render(
<TabsVertical>
<TabListVertical aria-label="List of tabs">
<Tab>Tab Label 1</Tab>
<Tab>Tab Label 2</Tab>
<Tab>Tab Label 3</Tab>
</TabListVertical>
<TabPanels>
<TabPanel className="custom-class">
Tab Panel 1<button type="button">Submit</button>
</TabPanel>
<TabPanel>Tab Panel 2</TabPanel>
<TabPanel>Tab Panel 3</TabPanel>
</TabPanels>
</TabsVertical>
);

expect(container.firstChild).not.toHaveClass(`${prefix}--tabs--vertical`);
});

it('should have set height', () => {
const { container } = render(
<TabsVertical height="100px">
<TabListVertical aria-label="List of tabs">
<Tab>Tab Label 1</Tab>
<Tab>Tab Label 2</Tab>
<Tab>Tab Label 3</Tab>
<Tab>Tab Label 4</Tab>
</TabListVertical>
<TabPanels>
<TabPanel className="custom-class">
Tab Panel 1<button type="button">Submit</button>
</TabPanel>
<TabPanel>Tab Panel 2</TabPanel>
<TabPanel>Tab Panel 3</TabPanel>
<TabPanel>Tab Panel 4</TabPanel>
</TabPanels>
</TabsVertical>
);

expect(container.firstChild).toHaveAttribute('style', 'height: 100px;');
});
});
9 changes: 8 additions & 1 deletion packages/react/src/components/Tabs/Tabs.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsTable, Canvas, Story } from '@storybook/blocks';
import { Tabs, TabList, Tab, TabPanels, TabPanel } from './Tabs';
import { Tabs, TabList, TabListVertical, Tab, TabPanels, TabPanel } from './Tabs';
import * as TabsStories from './Tabs.stories';
import { Grid, Column } from '../Grid';

Expand All @@ -20,6 +20,7 @@ import { Grid, Column } from '../Grid';
- [Contained Tabs](#contained-tabs)
- [Icon Tabs](#icon-tabs)
- [Dismissable Tabs](#dismissable-tabs)
- [Vertical Tabs](#vertical-tabs)
- [Component API](#component-api)
- [Tab - render content on click](#tab---render-content-on-click)
- [Tabs and the Grid - fullWidth prop](#tabs-and-the-grid---fullwidth-prop)
Expand Down Expand Up @@ -183,6 +184,12 @@ And there you have it! Working dismissable tabs.
<Story of={TabsStories.Dismissable} />
</Canvas>

### Vertical tabs

<Canvas>
<Story of={TabsStories.Vertical} />
</Canvas>

## Component API

<ArgsTable />
Expand Down
83 changes: 82 additions & 1 deletion packages/react/src/components/Tabs/Tabs.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@
*/

import React, { useState } from 'react';
import { Tabs, TabList, Tab, TabPanels, TabPanel, IconTab } from './Tabs';
import {
Tabs,
TabsVertical,
TabList,
TabListVertical,
Tab,
TabPanels,
TabPanel,
IconTab,
} from './Tabs';
import TextInput from '../TextInput';
import Checkbox from '../Checkbox';
import Button from '../Button';
import RadioButtonGroup from '../RadioButtonGroup';
import RadioButton from '../RadioButton';
import { Stack } from '../Stack';
import { Grid, Column } from '../Grid';
import mdx from './Tabs.mdx';

Expand All @@ -30,7 +42,9 @@ export default {
title: 'Components/Tabs',
component: Tabs,
subcomponents: {
TabsVertical,
TabList,
TabListVertical,
Tab,
TabPanels,
TabPanel,
Expand Down Expand Up @@ -542,6 +556,73 @@ export const ContainedFullWidth = () => (
</Grid>
);

export const Vertical = ({ ...args }) => (
<TabsVertical {...args}>
<TabListVertical aria-label="List of tabs">
<Tab>Dashboard</Tab>
<Tab>
Extra long label that will go two lines then truncate when it goes
beyond the Tab length
</Tab>
<Tab>Activity</Tab>
<Tab>Analyze</Tab>
<Tab>Investigate </Tab>
<Tab>Learn</Tab>
<Tab disabled>Settings</Tab>
</TabListVertical>
<TabPanels>
<TabPanel>Tab Panel 1</TabPanel>
<TabPanel>
<form style={{ margin: '2em' }}>
<Stack gap={7}>
<TextInput id="one" labelText="First Name" />
<TextInput id="three" labelText="Middle Initial" />
<TextInput id="two" labelText="Last Name" />
<RadioButtonGroup
legendText="Radio button heading"
name="formgroup-default-radio-button-group"
defaultSelected="radio-1">
<RadioButton labelText="Option 1" value="radio-1" id="radio-1" />
<RadioButton labelText="Option 2" value="radio-2" id="radio-2" />
<RadioButton labelText="Option 3" value="radio-3" id="radio-3" />
</RadioButtonGroup>
<Checkbox labelText={`Checkbox one`} id="checkbox-label-1" />
<Checkbox labelText={`Checkbox two`} id="checkbox-label-2" />
<Button>Submit</Button>
</Stack>
</form>
</TabPanel>
<TabPanel>Tab Panel 3</TabPanel>
<TabPanel>Tab Panel 4</TabPanel>
<TabPanel>Tab Panel 5</TabPanel>
<TabPanel>Tab Panel 6</TabPanel>
<TabPanel>Tab Panel 7</TabPanel>
</TabPanels>
</TabsVertical>
);

Vertical.args = {
height: '',
};

Vertical.argTypes = {
height: {
control: {
type: 'text',
},
},
dismissable: {
table: {
disable: true,
},
},
onTabCloseRequest: {
table: {
disable: true,
},
},
};

export const Skeleton = () => {
return (
<div style={{ maxWidth: '100%' }}>
Expand Down
Loading
Loading