@amsterdam/design-system-react 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/Accordion/Accordion.js +4 -1
- package/dist/Accordion/Accordion.test.js +19 -3
- package/dist/Accordion/AccordionSection.test.js +1 -1
- package/dist/ActionGroup/ActionGroup.test.js +1 -1
- package/dist/Alert/Alert.test.js +1 -1
- package/dist/Avatar/Avatar.test.js +1 -1
- package/dist/Badge/Badge.test.js +1 -1
- package/dist/Blockquote/Blockquote.test.js +3 -4
- package/dist/Breadcrumb/Breadcrumb.test.js +1 -1
- package/dist/Breadcrumb/BreadcrumbLink.test.js +1 -1
- package/dist/Breakout/Breakout.test.js +11 -19
- package/dist/Breakout/BreakoutCell.d.ts +3 -1
- package/dist/Breakout/BreakoutCell.js +1 -0
- package/dist/Breakout/BreakoutCell.test.js +20 -16
- package/dist/Button/Button.test.js +8 -1
- package/dist/Card/Card.d.ts +10 -0
- package/dist/Card/Card.js +8 -1
- package/dist/Card/Card.test.js +1 -1
- package/dist/Card/CardHeading.d.ts +11 -0
- package/dist/Card/CardHeading.js +10 -0
- package/dist/Card/CardHeading.test.js +34 -0
- package/dist/Card/CardHeadingGroup.test.js +1 -1
- package/dist/Card/CardImage.d.ts +7 -0
- package/dist/Card/CardImage.js +10 -0
- package/dist/{Footer/FooterSpotlight.test.js → Card/CardImage.test.js} +9 -9
- package/dist/Card/CardLink.test.js +1 -1
- package/dist/CharacterCount/CharacterCount.test.js +1 -1
- package/dist/Checkbox/Checkbox.test.js +2 -3
- package/dist/Column/Column.d.ts +4 -3
- package/dist/Column/Column.js +2 -1
- package/dist/Column/Column.test.js +10 -12
- package/dist/DateInput/DateInput.test.js +1 -1
- package/dist/DescriptionList/DescriptionList.test.js +1 -1
- package/dist/DescriptionList/DescriptionListDescription.test.js +1 -1
- package/dist/DescriptionList/DescriptionListSection.test.js +1 -1
- package/dist/DescriptionList/DescriptionListTerm.test.js +1 -1
- package/dist/Dialog/Dialog.test.js +1 -1
- package/dist/ErrorMessage/ErrorMessage.test.js +1 -1
- package/dist/Field/Field.test.js +1 -1
- package/dist/FieldSet/FieldSet.test.js +1 -1
- package/dist/Figure/Figure.test.js +1 -1
- package/dist/Figure/FigureCaption.test.js +1 -1
- package/dist/FileInput/FileInput.test.js +1 -1
- package/dist/FileList/FileList.test.js +1 -1
- package/dist/FileList/FileListItem.test.js +1 -1
- package/dist/Grid/Grid.d.ts +8 -5
- package/dist/Grid/Grid.js +2 -0
- package/dist/Grid/Grid.test.js +13 -29
- package/dist/Grid/GridCell.test.js +2 -8
- package/dist/Grid/paddingClasses.d.ts +2 -2
- package/dist/Heading/Heading.test.js +17 -11
- package/dist/Hint/Hint.test.js +1 -1
- package/dist/Icon/Icon.d.ts +1 -1
- package/dist/Icon/Icon.test.js +3 -4
- package/dist/IconButton/IconButton.js +1 -1
- package/dist/IconButton/IconButton.test.js +1 -1
- package/dist/Image/Image.d.ts +4 -8
- package/dist/Image/Image.test.js +1 -1
- package/dist/ImageSlider/ImageSlider.test.js +1 -1
- package/dist/ImageSlider/ImageSliderItem.test.js +1 -1
- package/dist/ImageSlider/ImageSliderScroller.test.js +1 -1
- package/dist/ImageSlider/ImageSliderThumbnails.js +1 -1
- package/dist/ImageSlider/ImageSliderThumbnails.test.js +1 -1
- package/dist/InvalidFormAlert/InvalidFormAlert.test.js +1 -1
- package/dist/Label/Label.test.js +3 -4
- package/dist/Link/Link.d.ts +0 -6
- package/dist/Link/Link.js +1 -1
- package/dist/Link/Link.test.js +22 -29
- package/dist/LinkList/LinkList.test.js +1 -1
- package/dist/LinkList/LinkListLink.test.js +1 -1
- package/dist/Logo/Logo.test.js +2 -3
- package/dist/Mark/Mark.test.js +1 -1
- package/dist/OrderedList/OrderedList.test.js +1 -1
- package/dist/OrderedList/OrderedListItem.test.js +1 -1
- package/dist/Overlap/Overlap.test.js +1 -1
- package/dist/{Footer/FooterSpotlight.d.ts → Page/Page.d.ts} +2 -2
- package/dist/Page/Page.js +9 -0
- package/dist/{MegaMenu/MegaMenu.test.js → Page/Page.test.js} +9 -9
- package/dist/Page/index.d.ts +2 -0
- package/dist/Page/index.js +1 -0
- package/dist/{Footer/Footer.d.ts → PageFooter/PageFooter.d.ts} +2 -2
- package/dist/PageFooter/PageFooter.js +17 -0
- package/dist/{Footer/Footer.test.js → PageFooter/PageFooter.test.js} +9 -9
- package/dist/{Footer/FooterMenu.d.ts → PageFooter/PageFooterMenu.d.ts} +2 -2
- package/dist/PageFooter/PageFooterMenu.js +9 -0
- package/dist/{Footer/FooterMenu.test.js → PageFooter/PageFooterMenu.test.js} +9 -9
- package/dist/{Footer/FooterMenuLink.d.ts → PageFooter/PageFooterMenuLink.d.ts} +2 -2
- package/dist/PageFooter/PageFooterMenuLink.js +9 -0
- package/dist/{Footer/FooterMenuLink.test.js → PageFooter/PageFooterMenuLink.test.js} +9 -9
- package/dist/PageFooter/PageFooterSpotlight.d.ts +9 -0
- package/dist/PageFooter/PageFooterSpotlight.js +9 -0
- package/dist/{MegaMenu/MegaMenuListCategory.test.js → PageFooter/PageFooterSpotlight.test.js} +9 -9
- package/dist/PageFooter/index.d.ts +5 -0
- package/dist/PageFooter/index.js +1 -0
- package/dist/{Header/Header.d.ts → PageHeader/PageHeader.d.ts} +4 -4
- package/dist/PageHeader/PageHeader.js +31 -0
- package/dist/{Header/Header.test.js → PageHeader/PageHeader.test.js} +37 -38
- package/dist/PageHeader/PageHeaderGridCellNarrowWindowOnly.d.ts +2 -0
- package/dist/PageHeader/PageHeaderGridCellNarrowWindowOnly.js +6 -0
- package/dist/{Header/HeaderGridCellNarrowWindowOnly.test.js → PageHeader/PageHeaderGridCellNarrowWindowOnly.test.js} +10 -10
- package/dist/PageHeader/PageHeaderMenuIcon.d.ts +2 -0
- package/dist/PageHeader/PageHeaderMenuIcon.js +2 -0
- package/dist/{Header/HeaderMenuLink.d.ts → PageHeader/PageHeaderMenuLink.d.ts} +2 -2
- package/dist/PageHeader/PageHeaderMenuLink.js +5 -0
- package/dist/{Header/HeaderMenuLink.test.js → PageHeader/PageHeaderMenuLink.test.js} +13 -13
- package/dist/PageHeader/index.d.ts +3 -0
- package/dist/PageHeader/index.js +1 -0
- package/dist/PageHeading/PageHeading.test.js +2 -3
- package/dist/Pagination/Pagination.test.js +1 -1
- package/dist/Paragraph/Paragraph.test.js +1 -1
- package/dist/PasswordInput/PasswordInput.test.js +1 -1
- package/dist/Radio/Radio.test.js +1 -1
- package/dist/Row/Row.d.ts +4 -3
- package/dist/Row/Row.js +2 -1
- package/dist/Row/Row.test.js +10 -12
- package/dist/SearchField/SearchField.d.ts +2 -0
- package/dist/SearchField/SearchField.test.js +2 -3
- package/dist/SearchField/SearchFieldInput.test.js +2 -3
- package/dist/Select/Select.test.js +1 -1
- package/dist/Select/SelectOption.test.js +1 -1
- package/dist/Select/SelectOptionGroup.test.js +1 -1
- package/dist/SkipLink/SkipLink.test.js +1 -1
- package/dist/Spotlight/Spotlight.d.ts +4 -2
- package/dist/Spotlight/Spotlight.js +1 -0
- package/dist/Spotlight/Spotlight.test.js +11 -9
- package/dist/StandaloneLink/StandaloneLink.d.ts +17 -0
- package/dist/StandaloneLink/StandaloneLink.js +10 -0
- package/dist/StandaloneLink/StandaloneLink.test.js +40 -0
- package/dist/StandaloneLink/index.d.ts +2 -0
- package/dist/StandaloneLink/index.js +1 -0
- package/dist/Switch/Switch.test.js +1 -1
- package/dist/Table/Table.test.js +1 -1
- package/dist/Table/TableBody.test.js +1 -1
- package/dist/Table/TableCaption.test.js +1 -1
- package/dist/Table/TableCell.test.js +1 -1
- package/dist/Table/TableFooter.test.js +1 -1
- package/dist/Table/TableHeader.test.js +1 -1
- package/dist/Table/TableHeaderCell.test.js +1 -1
- package/dist/Table/TableRow.test.js +1 -1
- package/dist/TableOfContents/TableOfContents.test.js +1 -1
- package/dist/TableOfContents/TableOfContentsLink.test.js +1 -1
- package/dist/TableOfContents/TableOfContentsList.test.js +1 -1
- package/dist/Tabs/Tabs.d.ts +6 -6
- package/dist/Tabs/Tabs.js +4 -5
- package/dist/Tabs/Tabs.test.js +21 -6
- package/dist/Tabs/TabsButton.d.ts +4 -4
- package/dist/Tabs/TabsButton.js +4 -4
- package/dist/Tabs/TabsButton.test.js +10 -10
- package/dist/Tabs/TabsContext.d.ts +2 -7
- package/dist/Tabs/TabsContext.js +0 -1
- package/dist/Tabs/TabsList.js +1 -1
- package/dist/Tabs/TabsList.test.js +1 -1
- package/dist/Tabs/TabsPanel.d.ts +4 -4
- package/dist/Tabs/TabsPanel.js +4 -4
- package/dist/Tabs/TabsPanel.test.js +10 -12
- package/dist/TextArea/TextArea.test.js +1 -1
- package/dist/TextInput/TextInput.test.js +2 -3
- package/dist/TimeInput/TimeInput.test.js +1 -1
- package/dist/UnorderedList/UnorderedList.test.js +1 -1
- package/dist/UnorderedList/UnorderedListItem.test.js +1 -1
- package/dist/common/accessibility.d.ts +9 -1
- package/dist/index.cjs.js +1000 -1057
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +164 -194
- package/dist/index.esm.js +998 -1053
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +4 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/dist/Footer/Footer.js +0 -17
- package/dist/Footer/FooterMenu.js +0 -9
- package/dist/Footer/FooterMenuLink.js +0 -9
- package/dist/Footer/FooterSpotlight.js +0 -9
- package/dist/Footer/index.d.ts +0 -5
- package/dist/Footer/index.js +0 -1
- package/dist/Header/Header.js +0 -31
- package/dist/Header/HeaderGridCellNarrowWindowOnly.d.ts +0 -2
- package/dist/Header/HeaderGridCellNarrowWindowOnly.js +0 -6
- package/dist/Header/HeaderMenuIcon.d.ts +0 -2
- package/dist/Header/HeaderMenuIcon.js +0 -2
- package/dist/Header/HeaderMenuLink.js +0 -5
- package/dist/Header/index.d.ts +0 -3
- package/dist/Header/index.js +0 -1
- package/dist/MegaMenu/MegaMenu.d.ts +0 -14
- package/dist/MegaMenu/MegaMenu.js +0 -12
- package/dist/MegaMenu/MegaMenuListCategory.d.ts +0 -9
- package/dist/MegaMenu/MegaMenuListCategory.js +0 -9
- package/dist/MegaMenu/index.d.ts +0 -3
- package/dist/MegaMenu/index.js +0 -1
- package/dist/PageMenu/PageMenu.d.ts +0 -25
- package/dist/PageMenu/PageMenu.js +0 -12
- package/dist/PageMenu/PageMenu.test.js +0 -45
- package/dist/PageMenu/PageMenuLink.d.ts +0 -13
- package/dist/PageMenu/PageMenuLink.js +0 -10
- package/dist/PageMenu/PageMenuLink.test.js +0 -40
- package/dist/PageMenu/index.d.ts +0 -3
- package/dist/PageMenu/index.js +0 -1
- package/dist/Screen/Screen.d.ts +0 -21
- package/dist/Screen/Screen.js +0 -9
- package/dist/Screen/Screen.test.d.ts +0 -1
- package/dist/Screen/Screen.test.js +0 -40
- package/dist/Screen/index.d.ts +0 -2
- package/dist/Screen/index.js +0 -1
- package/dist/TopTaskLink/TopTaskLink.d.ts +0 -17
- package/dist/TopTaskLink/TopTaskLink.js +0 -9
- package/dist/TopTaskLink/TopTaskLink.test.d.ts +0 -1
- package/dist/TopTaskLink/TopTaskLink.test.js +0 -42
- package/dist/TopTaskLink/index.d.ts +0 -1
- package/dist/TopTaskLink/index.js +0 -1
- /package/dist/{Footer/Footer.test.d.ts → Card/CardHeading.test.d.ts} +0 -0
- /package/dist/{Footer/FooterMenu.test.d.ts → Card/CardImage.test.d.ts} +0 -0
- /package/dist/{Footer/FooterMenuLink.test.d.ts → Page/Page.test.d.ts} +0 -0
- /package/dist/{Footer/FooterSpotlight.test.d.ts → PageFooter/PageFooter.test.d.ts} +0 -0
- /package/dist/{Header/HeaderGridCellNarrowWindowOnly.test.d.ts → PageFooter/PageFooterMenu.test.d.ts} +0 -0
- /package/dist/{Header/HeaderMenuLink.test.d.ts → PageFooter/PageFooterMenuLink.test.d.ts} +0 -0
- /package/dist/{MegaMenu/MegaMenu.test.d.ts → PageFooter/PageFooterSpotlight.test.d.ts} +0 -0
- /package/dist/{Header/Header.test.d.ts → PageHeader/PageHeader.test.d.ts} +0 -0
- /package/dist/{MegaMenu/MegaMenuListCategory.test.d.ts → PageHeader/PageHeaderGridCellNarrowWindowOnly.test.d.ts} +0 -0
- /package/dist/{PageMenu/PageMenu.test.d.ts → PageHeader/PageHeaderMenuLink.test.d.ts} +0 -0
- /package/dist/{Header → PageHeader}/matchMedia.mock.d.ts +0 -0
- /package/dist/{Header → PageHeader}/matchMedia.mock.js +0 -0
- /package/dist/{PageMenu/PageMenuLink.test.d.ts → StandaloneLink/StandaloneLink.test.d.ts} +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* @license EUPL-1.2+
|
|
4
|
+
* Copyright Gemeente Amsterdam
|
|
5
|
+
*/
|
|
6
|
+
import clsx from 'clsx';
|
|
7
|
+
import { forwardRef } from 'react';
|
|
8
|
+
import { Icon } from '../Icon';
|
|
9
|
+
export const StandaloneLink = forwardRef(({ children, className, color, icon, ...restProps }, ref) => (_jsxs("a", { ...restProps, className: clsx('ams-standalone-link', color && `ams-standalone-link--${color}`, icon && 'ams-standalone-link--with-icon', className), ref: ref, children: [icon && _jsx(Icon, { svg: icon }), children] })));
|
|
10
|
+
StandaloneLink.displayName = 'StandaloneLink';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { createRef } from 'react';
|
|
4
|
+
import { StandaloneLink } from './StandaloneLink';
|
|
5
|
+
import '@testing-library/jest-dom';
|
|
6
|
+
describe('Standalone Link', () => {
|
|
7
|
+
it('renders with href attribute', () => {
|
|
8
|
+
render(_jsx(StandaloneLink, { href: "#" }));
|
|
9
|
+
const component = screen.getByRole('link');
|
|
10
|
+
expect(component).toBeInTheDocument();
|
|
11
|
+
expect(component).toBeVisible();
|
|
12
|
+
expect(component).toHaveAttribute('href', '#');
|
|
13
|
+
});
|
|
14
|
+
it('renders a design system BEM class name', () => {
|
|
15
|
+
render(_jsx(StandaloneLink, { href: "#" }));
|
|
16
|
+
const component = screen.getByRole('link');
|
|
17
|
+
expect(component).toHaveClass('ams-standalone-link');
|
|
18
|
+
});
|
|
19
|
+
it('renders an extra class name', () => {
|
|
20
|
+
render(_jsx(StandaloneLink, { className: "extra", href: "#" }));
|
|
21
|
+
const component = screen.getByRole('link');
|
|
22
|
+
expect(component).toHaveClass('ams-standalone-link extra');
|
|
23
|
+
});
|
|
24
|
+
it('renders the class name for contrast color', () => {
|
|
25
|
+
render(_jsx(StandaloneLink, { color: "contrast", href: "#" }));
|
|
26
|
+
const component = screen.getByRole('link');
|
|
27
|
+
expect(component).toHaveClass('ams-standalone-link ams-standalone-link--contrast');
|
|
28
|
+
});
|
|
29
|
+
it('renders the class name for inverse color', () => {
|
|
30
|
+
render(_jsx(StandaloneLink, { color: "inverse", href: "#" }));
|
|
31
|
+
const component = screen.getByRole('link');
|
|
32
|
+
expect(component).toHaveClass('ams-standalone-link ams-standalone-link--inverse');
|
|
33
|
+
});
|
|
34
|
+
it('supports ForwardRef in React', () => {
|
|
35
|
+
const ref = createRef();
|
|
36
|
+
render(_jsx(StandaloneLink, { href: "#", ref: ref }));
|
|
37
|
+
const component = screen.getByRole('link');
|
|
38
|
+
expect(ref.current).toBe(component);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { StandaloneLink } from './StandaloneLink';
|
|
@@ -51,7 +51,7 @@ describe('Switch', () => {
|
|
|
51
51
|
const component = container.querySelector(':only-child');
|
|
52
52
|
expect(component).toHaveClass('ams-switch');
|
|
53
53
|
});
|
|
54
|
-
it('renders an
|
|
54
|
+
it('renders an extra class name', () => {
|
|
55
55
|
const { container } = render(_jsx(Switch, { className: "extra" }));
|
|
56
56
|
const component = container.querySelector(':only-child');
|
|
57
57
|
expect(component).toHaveClass('ams-switch extra');
|
package/dist/Table/Table.test.js
CHANGED
|
@@ -15,7 +15,7 @@ describe('Table', () => {
|
|
|
15
15
|
const component = screen.getByRole('table');
|
|
16
16
|
expect(component).toHaveClass('ams-table__table');
|
|
17
17
|
});
|
|
18
|
-
it('renders an
|
|
18
|
+
it('renders an extra class name', () => {
|
|
19
19
|
render(_jsx(Table, { className: "extra" }));
|
|
20
20
|
const component = screen.getByRole('table');
|
|
21
21
|
expect(component).toHaveClass('ams-table__table extra');
|
|
@@ -16,7 +16,7 @@ describe('Table body', () => {
|
|
|
16
16
|
const component = screen.getByRole('rowgroup');
|
|
17
17
|
expect(component).toHaveClass('ams-table__body');
|
|
18
18
|
});
|
|
19
|
-
it('renders an
|
|
19
|
+
it('renders an extra class name', () => {
|
|
20
20
|
render(_jsx(Table, { children: _jsx(TableBody, { className: "extra" }) }));
|
|
21
21
|
const component = screen.getByRole('rowgroup');
|
|
22
22
|
expect(component).toHaveClass('ams-table__body extra');
|
|
@@ -21,7 +21,7 @@ describe('Table caption', () => {
|
|
|
21
21
|
const caption = component?.querySelector(':only-child');
|
|
22
22
|
expect(caption).toHaveClass('ams-table__caption');
|
|
23
23
|
});
|
|
24
|
-
it('renders an
|
|
24
|
+
it('renders an extra class name', () => {
|
|
25
25
|
render(_jsx(Table, { children: _jsx(TableCaption, { className: "extra", children: "Caption" }) }));
|
|
26
26
|
const component = screen.getByRole('table', {
|
|
27
27
|
name: 'Caption',
|
|
@@ -18,7 +18,7 @@ describe('Table cell', () => {
|
|
|
18
18
|
const component = screen.getByRole('cell');
|
|
19
19
|
expect(component).toHaveClass('ams-table__cell');
|
|
20
20
|
});
|
|
21
|
-
it('renders an
|
|
21
|
+
it('renders an extra class name', () => {
|
|
22
22
|
render(_jsx(Table, { children: _jsx(TableBody, { children: _jsx(TableRow, { children: _jsx(TableCell, { className: "extra", children: "Data" }) }) }) }));
|
|
23
23
|
const component = screen.getByRole('cell');
|
|
24
24
|
expect(component).toHaveClass('ams-table__cell extra');
|
|
@@ -16,7 +16,7 @@ describe('Table footer', () => {
|
|
|
16
16
|
const component = screen.getByRole('rowgroup');
|
|
17
17
|
expect(component).toHaveClass('ams-table__footer');
|
|
18
18
|
});
|
|
19
|
-
it('renders an
|
|
19
|
+
it('renders an extra class name', () => {
|
|
20
20
|
render(_jsx(Table, { children: _jsx(TableFooter, { className: "extra" }) }));
|
|
21
21
|
const component = screen.getByRole('rowgroup');
|
|
22
22
|
expect(component).toHaveClass('ams-table__footer extra');
|
|
@@ -16,7 +16,7 @@ describe('Table header', () => {
|
|
|
16
16
|
const component = screen.getByRole('rowgroup');
|
|
17
17
|
expect(component).toHaveClass('ams-table__header');
|
|
18
18
|
});
|
|
19
|
-
it('renders an
|
|
19
|
+
it('renders an extra class name', () => {
|
|
20
20
|
render(_jsx(Table, { children: _jsx(TableHeader, { className: "extra" }) }));
|
|
21
21
|
const component = screen.getByRole('rowgroup');
|
|
22
22
|
expect(component).toHaveClass('ams-table__header extra');
|
|
@@ -24,7 +24,7 @@ describe('Table header cell', () => {
|
|
|
24
24
|
const component = screen.getByRole('columnheader');
|
|
25
25
|
expect(component).toHaveClass('ams-table__header-cell');
|
|
26
26
|
});
|
|
27
|
-
it('renders an
|
|
27
|
+
it('renders an extra class name', () => {
|
|
28
28
|
render(_jsx(Table, { children: _jsx(TableHeader, { children: _jsx(TableRow, { children: _jsx(TableHeaderCell, { className: "extra", children: "Data" }) }) }) }));
|
|
29
29
|
const component = screen.getByRole('columnheader');
|
|
30
30
|
expect(component).toHaveClass('ams-table__header-cell extra');
|
|
@@ -17,7 +17,7 @@ describe('Table row', () => {
|
|
|
17
17
|
const component = screen.getByRole('row');
|
|
18
18
|
expect(component).toHaveClass('ams-table__row');
|
|
19
19
|
});
|
|
20
|
-
it('renders an
|
|
20
|
+
it('renders an extra class name', () => {
|
|
21
21
|
render(_jsx(Table, { children: _jsx(TableBody, { children: _jsx(TableRow, { className: "extra" }) }) }));
|
|
22
22
|
const component = screen.getByRole('row');
|
|
23
23
|
expect(component).toHaveClass('ams-table__row extra');
|
|
@@ -26,7 +26,7 @@ describe('Table of contents', () => {
|
|
|
26
26
|
const component = container.querySelector(':only-child');
|
|
27
27
|
expect(component).toHaveClass('ams-table-of-contents');
|
|
28
28
|
});
|
|
29
|
-
it('renders an
|
|
29
|
+
it('renders an extra class name', () => {
|
|
30
30
|
const { container } = render(_jsx(TableOfContents, { className: "extra" }));
|
|
31
31
|
const component = container.querySelector(':only-child');
|
|
32
32
|
expect(component).toHaveClass('ams-table-of-contents extra');
|
|
@@ -16,7 +16,7 @@ describe('Table of Contents link', () => {
|
|
|
16
16
|
const component = screen.getByRole('link');
|
|
17
17
|
expect(component).toHaveClass('ams-table-of-contents__link');
|
|
18
18
|
});
|
|
19
|
-
it('renders an
|
|
19
|
+
it('renders an extra class name', () => {
|
|
20
20
|
render(_jsx(TableOfContents.Link, { className: "extra", href: "#", label: "Test" }));
|
|
21
21
|
const component = screen.getByRole('link');
|
|
22
22
|
expect(component).toHaveClass('ams-table-of-contents__link extra');
|
|
@@ -14,7 +14,7 @@ describe('Table of Contents list', () => {
|
|
|
14
14
|
const component = screen.getByRole('list');
|
|
15
15
|
expect(component).toHaveClass('ams-table-of-contents__list');
|
|
16
16
|
});
|
|
17
|
-
it('renders an
|
|
17
|
+
it('renders an extra class name', () => {
|
|
18
18
|
render(_jsx(TableOfContents.List, { className: "extra" }));
|
|
19
19
|
const component = screen.getByRole('list');
|
|
20
20
|
expect(component).toHaveClass('ams-table-of-contents__list extra');
|
package/dist/Tabs/Tabs.d.ts
CHANGED
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { HTMLAttributes, PropsWithChildren } from 'react';
|
|
6
6
|
export type TabsProps = {
|
|
7
|
-
/** The identifier of the initially active
|
|
7
|
+
/** The identifier of the initially active Tab. Corresponds to its Panel `id` value. */
|
|
8
8
|
activeTab?: string;
|
|
9
|
-
onTabChange?: (
|
|
9
|
+
onTabChange?: (panelId: string) => void;
|
|
10
10
|
} & PropsWithChildren<HTMLAttributes<HTMLDivElement>>;
|
|
11
11
|
export declare const Tabs: import("react").ForwardRefExoticComponent<{
|
|
12
|
-
/** The identifier of the initially active
|
|
12
|
+
/** The identifier of the initially active Tab. Corresponds to its Panel `id` value. */
|
|
13
13
|
activeTab?: string;
|
|
14
|
-
onTabChange?: (
|
|
14
|
+
onTabChange?: (panelId: string) => void;
|
|
15
15
|
} & HTMLAttributes<HTMLDivElement> & {
|
|
16
16
|
children?: import("react").ReactNode | undefined;
|
|
17
17
|
} & import("react").RefAttributes<HTMLDivElement>> & {
|
|
18
18
|
Button: import("react").ForwardRefExoticComponent<{
|
|
19
|
-
|
|
19
|
+
'aria-controls': string;
|
|
20
20
|
} & import("react").ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
21
21
|
children?: import("react").ReactNode | undefined;
|
|
22
22
|
} & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -24,7 +24,7 @@ export declare const Tabs: import("react").ForwardRefExoticComponent<{
|
|
|
24
24
|
children?: import("react").ReactNode | undefined;
|
|
25
25
|
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
26
26
|
Panel: import("react").ForwardRefExoticComponent<{
|
|
27
|
-
|
|
27
|
+
id: string;
|
|
28
28
|
} & HTMLAttributes<HTMLDivElement> & {
|
|
29
29
|
children?: import("react").ReactNode | undefined;
|
|
30
30
|
} & import("react").RefAttributes<HTMLDivElement>>;
|
package/dist/Tabs/Tabs.js
CHANGED
|
@@ -4,13 +4,12 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
4
4
|
* Copyright Gemeente Amsterdam
|
|
5
5
|
*/
|
|
6
6
|
import clsx from 'clsx';
|
|
7
|
-
import { forwardRef, useEffect,
|
|
7
|
+
import { forwardRef, useEffect, useMemo, useState } from 'react';
|
|
8
8
|
import { TabsButton } from './TabsButton';
|
|
9
9
|
import { TabsContext } from './TabsContext';
|
|
10
10
|
import { TabsList } from './TabsList';
|
|
11
11
|
import { TabsPanel } from './TabsPanel';
|
|
12
12
|
const TabsRoot = forwardRef(({ activeTab, children, className, onTabChange, ...restProps }, ref) => {
|
|
13
|
-
const tabsId = useId();
|
|
14
13
|
const [activeTabId, setActiveTabId] = useState();
|
|
15
14
|
const allTabIds = useMemo(() => {
|
|
16
15
|
if (!Array.isArray(children))
|
|
@@ -22,11 +21,11 @@ const TabsRoot = forwardRef(({ activeTab, children, className, onTabChange, ...r
|
|
|
22
21
|
// TabsList can have 0, 1, or more children
|
|
23
22
|
// If there is only 1 child, it will be an object
|
|
24
23
|
if (tabsListChildren.props) {
|
|
25
|
-
return [tabsListChildren.props
|
|
24
|
+
return [tabsListChildren.props['aria-controls']];
|
|
26
25
|
}
|
|
27
26
|
// If there is more than 1 child, it will be an array
|
|
28
27
|
if (Array.isArray(tabsListChildren)) {
|
|
29
|
-
return tabsListChildren.map((child) => child.props
|
|
28
|
+
return tabsListChildren.map((child) => child.props['aria-controls']);
|
|
30
29
|
}
|
|
31
30
|
// If there are no children, return an empty array
|
|
32
31
|
return [];
|
|
@@ -47,7 +46,7 @@ const TabsRoot = forwardRef(({ activeTab, children, className, onTabChange, ...r
|
|
|
47
46
|
setActiveTabId(tab);
|
|
48
47
|
onTabChange?.(tab);
|
|
49
48
|
};
|
|
50
|
-
return (_jsx(TabsContext.Provider, { value: { activeTabId,
|
|
49
|
+
return (_jsx(TabsContext.Provider, { value: { activeTabId, updateTab }, children: _jsx("div", { ...restProps, className: clsx('ams-tabs', className), ref: ref, children: children }) }));
|
|
51
50
|
});
|
|
52
51
|
TabsRoot.displayName = 'Tabs';
|
|
53
52
|
export const Tabs = Object.assign(TabsRoot, {
|
package/dist/Tabs/Tabs.test.js
CHANGED
|
@@ -16,7 +16,7 @@ describe('Tabs', () => {
|
|
|
16
16
|
const component = container.querySelector(':only-child');
|
|
17
17
|
expect(component).toHaveClass('ams-tabs');
|
|
18
18
|
});
|
|
19
|
-
it('renders an
|
|
19
|
+
it('renders an extra class name', () => {
|
|
20
20
|
const { container } = render(_jsx(Tabs, { className: "extra" }));
|
|
21
21
|
const component = container.querySelector(':only-child');
|
|
22
22
|
expect(component).toHaveClass('ams-tabs extra');
|
|
@@ -28,14 +28,14 @@ describe('Tabs', () => {
|
|
|
28
28
|
expect(ref.current).toBe(component);
|
|
29
29
|
});
|
|
30
30
|
it('supports children', () => {
|
|
31
|
-
render(_jsxs(Tabs, { children: [_jsxs(Tabs.List, { children: [_jsx(Tabs.Button, {
|
|
31
|
+
render(_jsxs(Tabs, { children: [_jsxs(Tabs.List, { children: [_jsx(Tabs.Button, { "aria-controls": "one", children: "Tab 1" }), _jsx(Tabs.Button, { "aria-controls": "two", children: "Tab 2" })] }), _jsx(Tabs.Panel, { id: "one", children: "Content 1" }), _jsx(Tabs.Panel, { id: "two", children: "Content 2" })] }));
|
|
32
32
|
expect(screen.getByRole('tablist')).toBeInTheDocument();
|
|
33
33
|
expect(screen.getByRole('tab', { selected: true })).toBeInTheDocument();
|
|
34
34
|
expect(screen.getByRole('tabpanel')).toBeInTheDocument();
|
|
35
35
|
});
|
|
36
36
|
it('should select a tab when clicked', async () => {
|
|
37
37
|
const user = userEvent.setup();
|
|
38
|
-
render(_jsxs(Tabs, { children: [_jsxs(Tabs.List, { children: [_jsx(Tabs.Button, {
|
|
38
|
+
render(_jsxs(Tabs, { children: [_jsxs(Tabs.List, { children: [_jsx(Tabs.Button, { "aria-controls": "one", children: "Tab 1" }), _jsx(Tabs.Button, { "aria-controls": "two", children: "Tab 2" })] }), _jsx(Tabs.Panel, { id: "one", children: "Content 1" }), _jsx(Tabs.Panel, { id: "two", children: "Content 2" })] }));
|
|
39
39
|
const tabOne = screen.getByRole('tab', { name: 'Tab 1' });
|
|
40
40
|
const tabTwo = screen.getByRole('tab', { name: 'Tab 2' });
|
|
41
41
|
expect(tabOne).toHaveAttribute('aria-selected', 'true');
|
|
@@ -55,13 +55,13 @@ describe('Tabs', () => {
|
|
|
55
55
|
it('calls onTabChange with the newly activated tab', async () => {
|
|
56
56
|
const user = userEvent.setup();
|
|
57
57
|
const onTabChange = jest.fn();
|
|
58
|
-
render(_jsx(Tabs, { onTabChange: onTabChange, children: _jsx(Tabs.List, { children: _jsx(Tabs.Button, {
|
|
58
|
+
render(_jsx(Tabs, { onTabChange: onTabChange, children: _jsx(Tabs.List, { children: _jsx(Tabs.Button, { "aria-controls": "one", children: "Tab 1" }) }) }));
|
|
59
59
|
const button = screen.getByRole('tab', { name: 'Tab 1' });
|
|
60
60
|
await user.click(button);
|
|
61
61
|
expect(onTabChange).toHaveBeenCalledWith('one');
|
|
62
62
|
});
|
|
63
63
|
it('should be able to set the initially active tab', () => {
|
|
64
|
-
render(_jsxs(Tabs, { activeTab: "three", children: [_jsxs(Tabs.List, { children: [_jsx(Tabs.Button, {
|
|
64
|
+
render(_jsxs(Tabs, { activeTab: "three", children: [_jsxs(Tabs.List, { children: [_jsx(Tabs.Button, { "aria-controls": "one", children: "Tab 1" }), _jsx(Tabs.Button, { "aria-controls": "two", children: "Tab 2" }), _jsx(Tabs.Button, { "aria-controls": "three", children: "Tab 3" }), _jsx(Tabs.Button, { "aria-controls": "four", children: "Tab 4" })] }), _jsx(Tabs.Panel, { id: "one", children: "Content 1" }), _jsx(Tabs.Panel, { id: "two", children: "Content 2" }), _jsx(Tabs.Panel, { id: "three", children: "Content 3" }), _jsx(Tabs.Panel, { id: "four", children: "Content 4" })] }));
|
|
65
65
|
const tabOne = screen.getByRole('tab', { name: 'Tab 1' });
|
|
66
66
|
const tabThree = screen.getByRole('tab', { name: 'Tab 3' });
|
|
67
67
|
expect(tabOne).toHaveAttribute('aria-selected', 'false');
|
|
@@ -73,7 +73,7 @@ describe('Tabs', () => {
|
|
|
73
73
|
it('should set the first tab as the initially active tab when the supplied active tab does not exist', async () => {
|
|
74
74
|
// Disable console.warn for this test, to prevent it from cluttering the test output
|
|
75
75
|
jest.spyOn(console, 'warn').mockImplementation(() => { });
|
|
76
|
-
render(_jsxs(Tabs, { activeTab: "unknown", children: [_jsxs(Tabs.List, { children: [_jsx(Tabs.Button, {
|
|
76
|
+
render(_jsxs(Tabs, { activeTab: "unknown", children: [_jsxs(Tabs.List, { children: [_jsx(Tabs.Button, { "aria-controls": "one", children: "Tab 1" }), _jsx(Tabs.Button, { "aria-controls": "two", children: "Tab 2" }), _jsx(Tabs.Button, { "aria-controls": "three", children: "Tab 3" }), _jsx(Tabs.Button, { "aria-controls": "four", children: "Tab 4" })] }), _jsx(Tabs.Panel, { id: "one", children: "Content 1" }), _jsx(Tabs.Panel, { id: "two", children: "Content 2" }), _jsx(Tabs.Panel, { id: "three", children: "Content 3" }), _jsx(Tabs.Panel, { id: "four", children: "Content 4" })] }));
|
|
77
77
|
const firstTab = screen.getByRole('tab', { name: 'Tab 1' });
|
|
78
78
|
const lastTab = screen.getByRole('tab', { name: 'Tab 4' });
|
|
79
79
|
expect(firstTab).toHaveAttribute('aria-selected', 'true');
|
|
@@ -82,4 +82,19 @@ describe('Tabs', () => {
|
|
|
82
82
|
expect(lastTab).toHaveAttribute('tabindex', '-1');
|
|
83
83
|
expect(screen.getByRole('tabpanel')).toHaveTextContent('Content 1');
|
|
84
84
|
});
|
|
85
|
+
it('sets focus on Tabs buttons when using arrow keys', async () => {
|
|
86
|
+
const user = userEvent.setup();
|
|
87
|
+
render(_jsxs(Tabs, { children: [_jsxs(Tabs.List, { children: [_jsx(Tabs.Button, { "aria-controls": "one", children: "Tab 1" }), _jsx(Tabs.Button, { "aria-controls": "two", children: "Tab 2" }), _jsx(Tabs.Button, { "aria-controls": "three", children: "Tab 3" })] }), _jsx(Tabs.Panel, { id: "one" }), _jsx(Tabs.Panel, { id: "two" }), _jsx(Tabs.Panel, { id: "three" })] }));
|
|
88
|
+
const firstButton = screen.getByRole('tab', { name: 'Tab 1' });
|
|
89
|
+
const thirdButton = screen.getByRole('tab', { name: 'Tab 3' });
|
|
90
|
+
await user.click(firstButton);
|
|
91
|
+
expect(firstButton).toHaveFocus();
|
|
92
|
+
// Click the right arrow key twice
|
|
93
|
+
await user.keyboard('{ArrowRight}');
|
|
94
|
+
await user.keyboard('{ArrowRight}');
|
|
95
|
+
expect(thirdButton).toHaveFocus();
|
|
96
|
+
expect(firstButton).not.toHaveFocus();
|
|
97
|
+
await user.keyboard('{ArrowRight}');
|
|
98
|
+
expect(firstButton).toHaveFocus();
|
|
99
|
+
});
|
|
85
100
|
});
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { ButtonHTMLAttributes, PropsWithChildren } from 'react';
|
|
6
6
|
export type TabsButtonProps = {
|
|
7
|
-
/**
|
|
8
|
-
|
|
7
|
+
/** The identifier of the corresponding tab panel. */
|
|
8
|
+
'aria-controls': string;
|
|
9
9
|
} & PropsWithChildren<ButtonHTMLAttributes<HTMLButtonElement>>;
|
|
10
10
|
export declare const TabsButton: import("react").ForwardRefExoticComponent<{
|
|
11
|
-
/**
|
|
12
|
-
|
|
11
|
+
/** The identifier of the corresponding tab panel. */
|
|
12
|
+
'aria-controls': string;
|
|
13
13
|
} & ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
14
14
|
children?: import("react").ReactNode | undefined;
|
|
15
15
|
} & import("react").RefAttributes<HTMLButtonElement>>;
|
package/dist/Tabs/TabsButton.js
CHANGED
|
@@ -6,14 +6,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
6
6
|
import clsx from 'clsx';
|
|
7
7
|
import { forwardRef, startTransition, useContext } from 'react';
|
|
8
8
|
import { TabsContext } from './TabsContext';
|
|
9
|
-
export const TabsButton = forwardRef(({ children, className, onClick,
|
|
10
|
-
const { activeTabId,
|
|
9
|
+
export const TabsButton = forwardRef(({ 'aria-controls': ariaControls, children, className, onClick, ...restProps }, ref) => {
|
|
10
|
+
const { activeTabId, updateTab } = useContext(TabsContext);
|
|
11
11
|
const handleClick = (event) => {
|
|
12
12
|
onClick?.(event);
|
|
13
13
|
startTransition(() => {
|
|
14
|
-
updateTab(
|
|
14
|
+
updateTab(ariaControls);
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
|
-
return (_jsxs("button", { ...restProps, "aria-controls":
|
|
17
|
+
return (_jsxs("button", { ...restProps, "aria-controls": ariaControls, "aria-selected": activeTabId === ariaControls, className: clsx('ams-tabs__button', className), id: `button-${ariaControls}`, onClick: handleClick, ref: ref, role: "tab", tabIndex: activeTabId === ariaControls ? 0 : -1, type: "button", children: [_jsx("span", { "aria-hidden": "true", className: "ams-tabs__button-label-hidden", children: children }), _jsx("span", { className: "ams-tabs__button-label", children: children })] }));
|
|
18
18
|
});
|
|
19
19
|
TabsButton.displayName = 'Tabs.Button';
|
|
@@ -5,38 +5,38 @@ import { TabsButton } from './TabsButton';
|
|
|
5
5
|
import '@testing-library/jest-dom';
|
|
6
6
|
describe('Tabs button', () => {
|
|
7
7
|
it('renders', () => {
|
|
8
|
-
render(_jsx(TabsButton, {
|
|
8
|
+
render(_jsx(TabsButton, { "aria-controls": "one" }));
|
|
9
9
|
const component = screen.getByRole('tab');
|
|
10
10
|
expect(component).toBeInTheDocument();
|
|
11
11
|
});
|
|
12
12
|
it('renders a design system BEM class name', () => {
|
|
13
|
-
render(_jsx(TabsButton, {
|
|
13
|
+
render(_jsx(TabsButton, { "aria-controls": "one" }));
|
|
14
14
|
const component = screen.getByRole('tab');
|
|
15
15
|
expect(component).toHaveClass('ams-tabs__button');
|
|
16
16
|
});
|
|
17
|
-
it('renders an
|
|
18
|
-
render(_jsx(TabsButton, {
|
|
17
|
+
it('renders an extra class name', () => {
|
|
18
|
+
render(_jsx(TabsButton, { "aria-controls": "one", className: "extra" }));
|
|
19
19
|
const component = screen.getByRole('tab');
|
|
20
20
|
expect(component).toHaveClass('ams-tabs__button extra');
|
|
21
21
|
});
|
|
22
22
|
it('renders a label', () => {
|
|
23
|
-
render(_jsx(TabsButton, {
|
|
23
|
+
render(_jsx(TabsButton, { "aria-controls": "one", children: "Label" }));
|
|
24
24
|
const component = screen.getByRole('tab', { name: 'Label' });
|
|
25
25
|
expect(component).toBeInTheDocument();
|
|
26
26
|
});
|
|
27
27
|
it('renders the correct id based on the tabs prop', () => {
|
|
28
|
-
const { container } = render(_jsx(TabsButton, {
|
|
29
|
-
const component = container.querySelector('
|
|
28
|
+
const { container } = render(_jsx(TabsButton, { "aria-controls": "one" }));
|
|
29
|
+
const component = container.querySelector('#button-one');
|
|
30
30
|
expect(component).toBeInTheDocument();
|
|
31
31
|
});
|
|
32
32
|
it('should associate the button with the correct tab', () => {
|
|
33
|
-
render(_jsx(TabsButton, {
|
|
33
|
+
render(_jsx(TabsButton, { "aria-controls": "one" }));
|
|
34
34
|
const component = screen.getByRole('tab');
|
|
35
|
-
expect(component).toHaveAttribute('aria-controls', '
|
|
35
|
+
expect(component).toHaveAttribute('aria-controls', 'one');
|
|
36
36
|
});
|
|
37
37
|
it('supports ForwardRef in React', () => {
|
|
38
38
|
const ref = createRef();
|
|
39
|
-
render(_jsx(TabsButton, {
|
|
39
|
+
render(_jsx(TabsButton, { "aria-controls": "one", ref: ref }));
|
|
40
40
|
const component = screen.getByRole('tab');
|
|
41
41
|
expect(ref.current).toBe(component);
|
|
42
42
|
});
|
|
@@ -3,14 +3,9 @@
|
|
|
3
3
|
* Copyright Gemeente Amsterdam
|
|
4
4
|
*/
|
|
5
5
|
export type TabsContextValue = {
|
|
6
|
-
/** The identifier of the active
|
|
6
|
+
/** The identifier of the active Tab. */
|
|
7
7
|
activeTabId?: string;
|
|
8
|
-
/**
|
|
9
|
-
* The generated identifier for the entire Tabs component.
|
|
10
|
-
* This lets you have several Tabs components, possibly with the same tabs, on one page.
|
|
11
|
-
*/
|
|
12
|
-
tabsId: string;
|
|
13
|
-
/** A function to update the active tab. */
|
|
8
|
+
/** A function to update the active Tab. */
|
|
14
9
|
updateTab: (tab: string) => void;
|
|
15
10
|
};
|
|
16
11
|
export declare const TabsContext: import("react").Context<TabsContextValue>;
|
package/dist/Tabs/TabsContext.js
CHANGED
package/dist/Tabs/TabsList.js
CHANGED
|
@@ -11,7 +11,7 @@ export const TabsList = forwardRef(({ children, className, ...restProps }, ref)
|
|
|
11
11
|
// Use a passed ref if it's there, otherwise use innerRef
|
|
12
12
|
useImperativeHandle(ref, () => innerRef.current);
|
|
13
13
|
const { keyDown } = useKeyboardFocus(innerRef, {
|
|
14
|
-
focusableElements: ['
|
|
14
|
+
focusableElements: ['.ams-tabs__button:not([disabled])'],
|
|
15
15
|
horizontally: true,
|
|
16
16
|
rotating: true,
|
|
17
17
|
});
|
|
@@ -14,7 +14,7 @@ describe('Tabs list', () => {
|
|
|
14
14
|
const component = screen.getByRole('tablist');
|
|
15
15
|
expect(component).toHaveClass('ams-tabs__list');
|
|
16
16
|
});
|
|
17
|
-
it('renders an
|
|
17
|
+
it('renders an extra class name', () => {
|
|
18
18
|
render(_jsx(TabsList, { className: "extra" }));
|
|
19
19
|
const component = screen.getByRole('tablist');
|
|
20
20
|
expect(component).toHaveClass('ams-tabs__list extra');
|
package/dist/Tabs/TabsPanel.d.ts
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { HTMLAttributes, PropsWithChildren } from 'react';
|
|
6
6
|
export type TabsPanelProps = {
|
|
7
|
-
/** The identifier of the
|
|
8
|
-
|
|
7
|
+
/** The identifier of the Tab Panel. */
|
|
8
|
+
id: string;
|
|
9
9
|
} & PropsWithChildren<HTMLAttributes<HTMLDivElement>>;
|
|
10
10
|
export declare const TabsPanel: import("react").ForwardRefExoticComponent<{
|
|
11
|
-
/** The identifier of the
|
|
12
|
-
|
|
11
|
+
/** The identifier of the Tab Panel. */
|
|
12
|
+
id: string;
|
|
13
13
|
} & HTMLAttributes<HTMLDivElement> & {
|
|
14
14
|
children?: import("react").ReactNode | undefined;
|
|
15
15
|
} & import("react").RefAttributes<HTMLDivElement>>;
|
package/dist/Tabs/TabsPanel.js
CHANGED
|
@@ -6,11 +6,11 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
6
6
|
import clsx from 'clsx';
|
|
7
7
|
import { forwardRef, useContext } from 'react';
|
|
8
8
|
import { TabsContext } from './TabsContext';
|
|
9
|
-
export const TabsPanel = forwardRef(({ children, className,
|
|
10
|
-
const { activeTabId
|
|
11
|
-
if (
|
|
9
|
+
export const TabsPanel = forwardRef(({ children, className, id, ...restProps }, ref) => {
|
|
10
|
+
const { activeTabId } = useContext(TabsContext);
|
|
11
|
+
if (id !== activeTabId) {
|
|
12
12
|
return null;
|
|
13
13
|
}
|
|
14
|
-
return (_jsx("div", { ...restProps, "aria-labelledby":
|
|
14
|
+
return (_jsx("div", { ...restProps, "aria-labelledby": `button-${id}`, className: clsx('ams-tabs__panel', className), id: id, ref: ref, role: "tabpanel", tabIndex: 0, children: children }));
|
|
15
15
|
});
|
|
16
16
|
TabsPanel.displayName = 'Tabs.Panel';
|
|
@@ -5,35 +5,33 @@ import { Tabs } from './Tabs';
|
|
|
5
5
|
import '@testing-library/jest-dom';
|
|
6
6
|
describe('Tabs Panel', () => {
|
|
7
7
|
it('renders', () => {
|
|
8
|
-
render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, {
|
|
8
|
+
render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, { "aria-controls": "one" }) }), _jsx(Tabs.Panel, { id: "one" })] }));
|
|
9
9
|
const component = screen.getByRole('tabpanel');
|
|
10
10
|
expect(component).toBeInTheDocument();
|
|
11
11
|
});
|
|
12
12
|
it('renders a design system BEM class name', () => {
|
|
13
|
-
render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, {
|
|
13
|
+
render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, { "aria-controls": "one" }) }), _jsx(Tabs.Panel, { id: "one" })] }));
|
|
14
14
|
const component = screen.getByRole('tabpanel');
|
|
15
15
|
expect(component).toHaveClass('ams-tabs__panel');
|
|
16
16
|
});
|
|
17
|
-
it('renders an
|
|
18
|
-
render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, {
|
|
17
|
+
it('renders an extra class name', () => {
|
|
18
|
+
render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, { "aria-controls": "one" }) }), _jsx(Tabs.Panel, { className: "extra", id: "one" })] }));
|
|
19
19
|
const component = screen.getByRole('tabpanel');
|
|
20
20
|
expect(component).toHaveClass('ams-tabs__panel extra');
|
|
21
21
|
});
|
|
22
22
|
it('renders the correct id based on the tabs prop', () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
expect(component).toBeInTheDocument();
|
|
23
|
+
render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, { "aria-controls": "one" }) }), _jsx(Tabs.Panel, { id: "one" })] }));
|
|
24
|
+
const component = screen.getByRole('tabpanel');
|
|
25
|
+
expect(component).toHaveAttribute('id', 'one');
|
|
27
26
|
});
|
|
28
27
|
it('should associate the tab with the correct button', () => {
|
|
29
|
-
render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, {
|
|
28
|
+
render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, { "aria-controls": "one" }) }), _jsx(Tabs.Panel, { id: "one" })] }));
|
|
30
29
|
const component = screen.getByRole('tabpanel');
|
|
31
|
-
|
|
32
|
-
expect(component).toHaveAttribute('aria-labelledby', expect.stringMatching(/-tab-one$/));
|
|
30
|
+
expect(component).toHaveAttribute('aria-labelledby', 'button-one');
|
|
33
31
|
});
|
|
34
32
|
it('supports ForwardRef in React', () => {
|
|
35
33
|
const ref = createRef();
|
|
36
|
-
render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, {
|
|
34
|
+
render(_jsxs(Tabs, { children: [_jsx(Tabs.List, { children: _jsx(Tabs.Button, { "aria-controls": "one" }) }), _jsx(Tabs.Panel, { id: "one", ref: ref })] }));
|
|
37
35
|
const component = screen.getByRole('tabpanel');
|
|
38
36
|
expect(ref.current).toBe(component);
|
|
39
37
|
});
|
|
@@ -16,7 +16,7 @@ describe('Text area', () => {
|
|
|
16
16
|
const component = screen.getByRole('textbox');
|
|
17
17
|
expect(component).toHaveClass('ams-text-area');
|
|
18
18
|
});
|
|
19
|
-
it('renders an
|
|
19
|
+
it('renders an extra class name', () => {
|
|
20
20
|
render(_jsx(TextArea, { className: "extra" }));
|
|
21
21
|
const component = screen.getByRole('textbox');
|
|
22
22
|
expect(component).toHaveClass('ams-text-area extra');
|
|
@@ -16,11 +16,10 @@ describe('Text input', () => {
|
|
|
16
16
|
const component = screen.getByRole('textbox');
|
|
17
17
|
expect(component).toHaveClass('ams-text-input');
|
|
18
18
|
});
|
|
19
|
-
it('renders an
|
|
19
|
+
it('renders an extra class name', () => {
|
|
20
20
|
render(_jsx(TextInput, { className: "extra" }));
|
|
21
21
|
const component = screen.getByRole('textbox');
|
|
22
|
-
expect(component).toHaveClass('extra');
|
|
23
|
-
expect(component).toHaveClass('ams-text-input');
|
|
22
|
+
expect(component).toHaveClass('ams-text-input extra');
|
|
24
23
|
});
|
|
25
24
|
it('should be working in a controlled state', async () => {
|
|
26
25
|
function ControlledComponent() {
|
|
@@ -15,7 +15,7 @@ describe('Time input', () => {
|
|
|
15
15
|
const component = container.querySelector(':only-child');
|
|
16
16
|
expect(component).toHaveClass('ams-time-input');
|
|
17
17
|
});
|
|
18
|
-
it('renders an
|
|
18
|
+
it('renders an extra class name', () => {
|
|
19
19
|
const { container } = render(_jsx(TimeInput, { className: "extra" }));
|
|
20
20
|
const component = container.querySelector(':only-child');
|
|
21
21
|
expect(component).toHaveClass('ams-time-input extra');
|
|
@@ -24,7 +24,7 @@ describe('Unordered list', () => {
|
|
|
24
24
|
const component = screen.getByRole('list');
|
|
25
25
|
expect(component).toHaveClass('ams-unordered-list--inverse');
|
|
26
26
|
});
|
|
27
|
-
it('renders an
|
|
27
|
+
it('renders an extra class name', () => {
|
|
28
28
|
render(_jsx(UnorderedList, { className: "extra" }));
|
|
29
29
|
const component = screen.getByRole('list');
|
|
30
30
|
expect(component).toHaveClass('ams-unordered-list extra');
|
|
@@ -14,7 +14,7 @@ describe('Ordered list item', () => {
|
|
|
14
14
|
const component = screen.getByRole('listitem');
|
|
15
15
|
expect(component).toHaveClass('ams-unordered-list__item');
|
|
16
16
|
});
|
|
17
|
-
it('renders an
|
|
17
|
+
it('renders an extra class name', () => {
|
|
18
18
|
render(_jsx(UnorderedListItem, { className: "extra" }));
|
|
19
19
|
const component = screen.getByRole('listitem');
|
|
20
20
|
expect(component).toHaveClass('ams-unordered-list__item extra');
|