@scottish-government/designsystem-react 0.5.1 → 0.7.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/.svgrrc +2 -1
- package/.svgrrc_documents +15 -0
- package/@types/common/FileIcon.d.ts +7 -0
- package/@types/components/Accordion.d.ts +2 -2
- package/@types/components/ConfirmationMessage.d.ts +1 -1
- package/@types/components/FileDownload.d.ts +11 -0
- package/@types/components/NotificationPanel.d.ts +1 -1
- package/@types/components/SummaryCard.d.ts +1 -1
- package/@types/components/Tabs.d.ts +1 -1
- package/@types/sgds.d.ts +2 -1
- package/CHANGELOG.md +81 -0
- package/README.md +4 -0
- package/dist/common/AbstractNotificationBanner.jsx +63 -0
- package/dist/common/ConditionalWrapper.jsx +8 -0
- package/dist/common/FileIcon.jsx +51 -0
- package/dist/common/HintText.jsx +9 -0
- package/dist/common/Icon.jsx +57 -0
- package/dist/common/ScreenReaderText.jsx +9 -0
- package/dist/common/WrapperTag.jsx +11 -0
- package/dist/common/file-icon.jsx +51 -0
- package/dist/common/icon.jsx +1 -1
- package/dist/components/Accordion/Accordion.jsx +102 -0
- package/dist/components/AspectBox/AspectBox.jsx +79 -0
- package/dist/components/BackToTop/BackToTop.jsx +27 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.jsx +28 -0
- package/dist/components/Button/Button.jsx +30 -0
- package/dist/components/Checkbox/Checkbox.jsx +62 -0
- package/dist/components/ConfirmationMessage/ConfirmationMessage.jsx +24 -0
- package/dist/components/ContentsNav/ContentsNav.jsx +33 -0
- package/dist/components/CookieBanner/CookieBanner.jsx +21 -0
- package/dist/components/DatePicker/DatePicker.jsx +54 -0
- package/dist/components/Details/Details.jsx +17 -0
- package/dist/components/ErrorMessage/ErrorMessage.jsx +12 -0
- package/dist/components/ErrorSummary/ErrorSummary.jsx +27 -0
- package/dist/components/FileDownload/FileDownload.jsx +50 -0
- package/dist/components/HideThisPage/HideThisPage.jsx +71 -0
- package/dist/components/InsetText/InsetText.jsx +14 -0
- package/dist/components/NotificationBanner/NotificationBanner.jsx +26 -0
- package/dist/components/NotificationPanel/NotificationPanel.jsx +21 -0
- package/dist/components/PageHeader/PageHeader.jsx +15 -0
- package/dist/components/PageMetadata/PageMetadata.jsx +26 -0
- package/dist/components/Pagination/Pagination.jsx +97 -0
- package/dist/components/PhaseBanner/PhaseBanner.jsx +23 -0
- package/dist/components/Question/Question.jsx +22 -0
- package/dist/components/RadioButton/RadioButton.jsx +43 -0
- package/dist/components/Select/Select.jsx +52 -0
- package/dist/components/SequentialNavigation/SequentialNavigation.jsx +31 -0
- package/dist/components/SideNavigation/SideNavigation.jsx +52 -0
- package/dist/components/SiteHeader/SiteHeader.jsx +68 -0
- package/dist/components/SiteNavigation/SiteNavigation.jsx +22 -0
- package/dist/components/SiteSearch/SiteSearch.jsx +55 -0
- package/dist/components/SkipLinks/SkipLinks.jsx +21 -0
- package/dist/components/SummaryCard/SummaryCard.jsx +67 -0
- package/dist/components/SummaryList/SummaryList.jsx +75 -0
- package/dist/components/Table/Table.jsx +24 -0
- package/dist/components/Tabs/Tabs.jsx +99 -0
- package/dist/components/Tag/Tag.jsx +13 -0
- package/dist/components/TaskList/TaskList.jsx +95 -0
- package/dist/components/TextInput/TextInput.jsx +58 -0
- package/dist/components/Textarea/Textarea.jsx +54 -0
- package/dist/components/WarningText/WarningText.jsx +16 -0
- package/dist/components/file-download/file-download.jsx +50 -0
- package/dist/images/documents/audio.jsx +47 -0
- package/dist/images/documents/csv.jsx +57 -0
- package/dist/images/documents/excel.jsx +57 -0
- package/dist/images/documents/file.jsx +48 -0
- package/dist/images/documents/generic.jsx +47 -0
- package/dist/images/documents/geodata.jsx +44 -0
- package/dist/images/documents/ical.jsx +48 -0
- package/dist/images/documents/ico.jsx +48 -0
- package/dist/images/documents/image.jsx +43 -0
- package/dist/images/documents/index.js +50 -0
- package/dist/images/documents/odf.jsx +46 -0
- package/dist/images/documents/odg.jsx +46 -0
- package/dist/images/documents/odp.jsx +45 -0
- package/dist/images/documents/ods.jsx +55 -0
- package/dist/images/documents/odt.jsx +46 -0
- package/dist/images/documents/pdf.jsx +48 -0
- package/dist/images/documents/ppt.jsx +47 -0
- package/dist/images/documents/rtf.jsx +48 -0
- package/dist/images/documents/text.jsx +48 -0
- package/dist/images/documents/video.jsx +47 -0
- package/dist/images/documents/word.jsx +48 -0
- package/dist/images/documents/xml.jsx +48 -0
- package/dist/images/documents/zip.jsx +48 -0
- package/dist/images/icons/arrow_upward.jsx +41 -0
- package/dist/images/icons/calendar_today.jsx +41 -0
- package/dist/images/icons/cancel.jsx +40 -0
- package/dist/images/icons/check_circle.jsx +41 -0
- package/dist/images/icons/chevron_left.jsx +41 -0
- package/dist/images/icons/chevron_right.jsx +41 -0
- package/dist/images/icons/close.jsx +41 -0
- package/dist/images/icons/description.jsx +41 -0
- package/dist/images/icons/double_chevron_left.jsx +40 -0
- package/dist/images/icons/double_chevron_right.jsx +40 -0
- package/dist/images/icons/error.jsx +41 -0
- package/dist/images/icons/expand_less.jsx +41 -0
- package/dist/images/icons/expand_more.jsx +41 -0
- package/dist/images/icons/index.js +40 -0
- package/dist/images/icons/list.jsx +44 -0
- package/dist/images/icons/menu.jsx +41 -0
- package/dist/images/icons/priority_high.jsx +42 -0
- package/dist/images/icons/search.jsx +41 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/src/common/{abstract-notification-banner.test.tsx → AbstractNotificationBanner.test.tsx} +11 -11
- package/src/common/{abstract-notification-banner.tsx → AbstractNotificationBanner.tsx} +2 -2
- package/src/common/{conditional-wrapper.test.tsx → ConditionalWrapper.test.tsx} +1 -1
- package/src/common/FileIcon.test.tsx +50 -0
- package/src/common/FileIcon.tsx +25 -0
- package/src/common/{hint-text.test.tsx → HintText.test.tsx} +12 -12
- package/src/common/{icon.test.tsx → Icon.test.tsx} +16 -16
- package/src/common/{icon.tsx → Icon.tsx} +1 -1
- package/src/common/{screen-reader-text.test.tsx → ScreenReaderText.test.tsx} +5 -5
- package/src/common/{wrapper-tag.test.tsx → WrapperTag.test.tsx} +5 -5
- package/src/components/{accordion/accordion.test.tsx → Accordion/Accordion.test.tsx} +35 -35
- package/src/components/{accordion/accordion.tsx → Accordion/Accordion.tsx} +5 -5
- package/src/components/{aspect-box/aspect-box.test.tsx → AspectBox/AspectBox.test.tsx} +2 -2
- package/src/components/{back-to-top/back-to-top.test.tsx → BackToTop/BackToTop.test.tsx} +1 -1
- package/src/components/{back-to-top/back-to-top.tsx → BackToTop/BackToTop.tsx} +1 -1
- package/src/components/{breadcrumbs/breadcrumbs.test.tsx → Breadcrumbs/Breadcrumbs.test.tsx} +7 -7
- package/src/components/{button/button.test.tsx → Button/Button.test.tsx} +1 -1
- package/src/components/{button/button.tsx → Button/Button.tsx} +3 -3
- package/src/components/{checkbox/checkbox.test.tsx → Checkbox/Checkbox.test.tsx} +16 -16
- package/src/components/{checkbox/checkbox.tsx → Checkbox/Checkbox.tsx} +1 -1
- package/src/components/{confirmation-message/confirmation-message.test.tsx → ConfirmationMessage/ConfirmationMessage.test.tsx} +12 -14
- package/src/components/{confirmation-message/confirmation-message.tsx → ConfirmationMessage/ConfirmationMessage.tsx} +4 -4
- package/src/components/{contents-nav/contents-nav.test.tsx → ContentsNav/ContentsNav.test.tsx} +21 -28
- package/src/components/{contents-nav/contents-nav.tsx → ContentsNav/ContentsNav.tsx} +1 -1
- package/src/components/{cookie-banner/cookie-banner.test.tsx → CookieBanner/CookieBanner.test.tsx} +3 -3
- package/src/components/{cookie-banner/cookie-banner.tsx → CookieBanner/CookieBanner.tsx} +1 -1
- package/src/components/{date-picker/date-picker.test.tsx → DatePicker/DatePicker.test.tsx} +76 -66
- package/src/components/{date-picker/date-picker.tsx → DatePicker/DatePicker.tsx} +2 -2
- package/src/components/{details/details.test.tsx → Details/Details.test.tsx} +10 -10
- package/src/components/{error-message/error-message.test.tsx → ErrorMessage/ErrorMessage.test.tsx} +10 -10
- package/src/components/{error-summary/error-summary.test.tsx → ErrorSummary/ErrorSummary.test.tsx} +13 -14
- package/src/components/{error-summary/error-summary.tsx → ErrorSummary/ErrorSummary.tsx} +1 -1
- package/src/components/FileDownload/FileDownload.test.tsx +167 -0
- package/src/components/FileDownload/FileDownload.tsx +67 -0
- package/src/components/{hide-this-page/hide-this-page.test.tsx → HideThisPage/HideThisPage.test.tsx} +4 -4
- package/src/components/{hide-this-page/hide-this-page.tsx → HideThisPage/HideThisPage.tsx} +3 -3
- package/src/components/{inset-text/inset-text.test.tsx → InsetText/InsetText.test.tsx} +1 -1
- package/src/components/{notification-banner/notification-banner.test.tsx → NotificationBanner/NotificationBanner.test.tsx} +4 -4
- package/src/components/{notification-banner/notification-banner.tsx → NotificationBanner/NotificationBanner.tsx} +1 -1
- package/src/components/{notification-panel/notification-panel.test.tsx → NotificationPanel/NotificationPanel.test.tsx} +24 -23
- package/src/components/{notification-panel/notification-panel.tsx → NotificationPanel/NotificationPanel.tsx} +3 -3
- package/src/components/{page-header/page-header.test.tsx → PageHeader/PageHeader.test.tsx} +9 -9
- package/src/components/{page-metadata/page-metadata.test.tsx → PageMetadata/PageMetadata.test.tsx} +9 -9
- package/src/components/{pagination/pagination.test.tsx → Pagination/Pagination.test.tsx} +56 -56
- package/src/components/{pagination/pagination.tsx → Pagination/Pagination.tsx} +1 -1
- package/src/components/{phase-banner/phase-banner.test.tsx → PhaseBanner/PhaseBanner.test.tsx} +9 -9
- package/src/components/{phase-banner/phase-banner.tsx → PhaseBanner/PhaseBanner.tsx} +1 -1
- package/src/components/{question/question.test.tsx → Question/Question.test.tsx} +10 -10
- package/src/components/{question/question.tsx → Question/Question.tsx} +3 -3
- package/src/components/{radio-button/radio-button.test.tsx → RadioButton/RadioButton.test.tsx} +23 -23
- package/src/components/{radio-button/radio-button.tsx → RadioButton/RadioButton.tsx} +1 -1
- package/src/components/{select/select.test.tsx → Select/Select.test.tsx} +67 -64
- package/src/components/{select/select.tsx → Select/Select.tsx} +2 -2
- package/src/components/{sequential-navigation/sequential-navigation.test.tsx → SequentialNavigation/SequentialNavigation.test.tsx} +18 -18
- package/src/components/{side-navigation/side-navigation.test.tsx → SideNavigation/SideNavigation.test.tsx} +8 -8
- package/src/components/{site-header/site-header.test.tsx → SiteHeader/SiteHeader.test.tsx} +25 -25
- package/src/components/{site-header/site-header.tsx → SiteHeader/SiteHeader.tsx} +4 -4
- package/src/components/{site-navigation/site-navigation.test.tsx → SiteNavigation/SiteNavigation.test.tsx} +8 -8
- package/src/components/{site-search/site-search.test.tsx → SiteSearch/SiteSearch.test.tsx} +16 -16
- package/src/components/{site-search/site-search.tsx → SiteSearch/SiteSearch.tsx} +1 -1
- package/src/components/{skip-links/skip-links.test.tsx → SkipLinks/SkipLinks.test.tsx} +15 -15
- package/src/components/{summary-card/summary-card.test.tsx → SummaryCard/SummaryCard.test.tsx} +28 -28
- package/src/components/{summary-card/summary-card.tsx → SummaryCard/SummaryCard.tsx} +4 -4
- package/src/components/{summary-list/summary-list.test.tsx → SummaryList/SummaryList.test.tsx} +55 -56
- package/src/components/{summary-list/summary-list.tsx → SummaryList/SummaryList.tsx} +2 -2
- package/src/components/{table/table.test.tsx → Table/Table.test.tsx} +4 -4
- package/src/components/{tabs/tabs.test.tsx → Tabs/Tabs.test.tsx} +22 -42
- package/src/components/{tabs/tabs.tsx → Tabs/Tabs.tsx} +3 -3
- package/src/components/{tag/tag.test.tsx → Tag/Tag.test.tsx} +10 -10
- package/src/components/{task-list/task-list.test.tsx → TaskList/TaskList.test.tsx} +109 -108
- package/src/components/{task-list/task-list.tsx → TaskList/TaskList.tsx} +4 -4
- package/src/components/{text-input/text-input.test.tsx → TextInput/TextInput.test.tsx} +92 -87
- package/src/components/{text-input/text-input.tsx → TextInput/TextInput.tsx} +4 -4
- package/src/components/{textarea/textarea.test.tsx → Textarea/Textarea.test.tsx} +71 -67
- package/src/components/{textarea/textarea.tsx → Textarea/Textarea.tsx} +3 -3
- package/src/components/{warning-text/warning-text.test.tsx → WarningText/WarningText.test.tsx} +1 -1
- package/src/images/documents/audio.tsx +34 -0
- package/src/images/documents/csv.tsx +39 -0
- package/src/images/documents/excel.tsx +39 -0
- package/src/images/documents/file.tsx +30 -0
- package/src/images/documents/generic.tsx +26 -0
- package/src/images/documents/geodata.tsx +29 -0
- package/src/images/documents/ical.tsx +30 -0
- package/src/images/documents/ico.tsx +30 -0
- package/src/images/documents/image.tsx +25 -0
- package/src/images/documents/index.ts +22 -0
- package/src/images/documents/odf.tsx +28 -0
- package/src/images/documents/odg.tsx +28 -0
- package/src/images/documents/odp.tsx +33 -0
- package/src/images/documents/ods.tsx +37 -0
- package/src/images/documents/odt.tsx +28 -0
- package/src/images/documents/pdf.tsx +30 -0
- package/src/images/documents/ppt.tsx +28 -0
- package/src/images/documents/rtf.tsx +30 -0
- package/src/images/documents/text.tsx +30 -0
- package/src/images/documents/video.tsx +34 -0
- package/src/images/documents/word.tsx +30 -0
- package/src/images/documents/xml.tsx +30 -0
- package/src/images/documents/zip.tsx +30 -0
- package/src/images/icons/index.ts +17 -0
- package/vite.config.ts +1 -1
- package/src/icons/index.ts +0 -17
- /package/src/common/{conditional-wrapper.tsx → ConditionalWrapper.tsx} +0 -0
- /package/src/common/{hint-text.tsx → HintText.tsx} +0 -0
- /package/src/common/{screen-reader-text.tsx → ScreenReaderText.tsx} +0 -0
- /package/src/common/{wrapper-tag.tsx → WrapperTag.tsx} +0 -0
- /package/src/components/{aspect-box/aspect-box.tsx → AspectBox/AspectBox.tsx} +0 -0
- /package/src/components/{breadcrumbs/breadcrumbs.tsx → Breadcrumbs/Breadcrumbs.tsx} +0 -0
- /package/src/components/{details/details.tsx → Details/Details.tsx} +0 -0
- /package/src/components/{error-message/error-message.tsx → ErrorMessage/ErrorMessage.tsx} +0 -0
- /package/src/components/{inset-text/inset-text.tsx → InsetText/InsetText.tsx} +0 -0
- /package/src/components/{page-header/page-header.tsx → PageHeader/PageHeader.tsx} +0 -0
- /package/src/components/{page-metadata/page-metadata.tsx → PageMetadata/PageMetadata.tsx} +0 -0
- /package/src/components/{sequential-navigation/sequential-navigation.tsx → SequentialNavigation/SequentialNavigation.tsx} +0 -0
- /package/src/components/{side-navigation/side-navigation.tsx → SideNavigation/SideNavigation.tsx} +0 -0
- /package/src/components/{site-navigation/site-navigation.tsx → SiteNavigation/SiteNavigation.tsx} +0 -0
- /package/src/components/{skip-links/skip-links.tsx → SkipLinks/SkipLinks.tsx} +0 -0
- /package/src/components/{table/table.tsx → Table/Table.tsx} +0 -0
- /package/src/components/{tag/tag.tsx → Tag/Tag.tsx} +0 -0
- /package/src/components/{warning-text/warning-text.tsx → WarningText/WarningText.tsx} +0 -0
- /package/src/{icons/ArrowUpward.tsx → images/icons/arrow_upward.tsx} +0 -0
- /package/src/{icons/CalendarToday.tsx → images/icons/calendar_today.tsx} +0 -0
- /package/src/{icons/Cancel.tsx → images/icons/cancel.tsx} +0 -0
- /package/src/{icons/CheckCircle.tsx → images/icons/check_circle.tsx} +0 -0
- /package/src/{icons/ChevronLeft.tsx → images/icons/chevron_left.tsx} +0 -0
- /package/src/{icons/ChevronRight.tsx → images/icons/chevron_right.tsx} +0 -0
- /package/src/{icons/Close.tsx → images/icons/close.tsx} +0 -0
- /package/src/{icons/Description.tsx → images/icons/description.tsx} +0 -0
- /package/src/{icons/DoubleChevronLeft.tsx → images/icons/double_chevron_left.tsx} +0 -0
- /package/src/{icons/DoubleChevronRight.tsx → images/icons/double_chevron_right.tsx} +0 -0
- /package/src/{icons/Error.tsx → images/icons/error.tsx} +0 -0
- /package/src/{icons/ExpandLess.tsx → images/icons/expand_less.tsx} +0 -0
- /package/src/{icons/ExpandMore.tsx → images/icons/expand_more.tsx} +0 -0
- /package/src/{icons/List.tsx → images/icons/list.tsx} +0 -0
- /package/src/{icons/Menu.tsx → images/icons/menu.tsx} +0 -0
- /package/src/{icons/PriorityHigh.tsx → images/icons/priority_high.tsx} +0 -0
- /package/src/{icons/Search.tsx → images/icons/search.tsx} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { test, expect } from 'vitest';
|
|
2
2
|
import { render, screen, within } from '@testing-library/react';
|
|
3
|
-
import Tabs from './
|
|
3
|
+
import Tabs from './Tabs';
|
|
4
4
|
import slugify from '../../utils/slugify';
|
|
5
5
|
|
|
6
6
|
test('tab container renders correctly', () => {
|
|
@@ -29,7 +29,7 @@ test('tab container renders correctly', () => {
|
|
|
29
29
|
expect(tabContainer.tagName).toEqual('DIV');
|
|
30
30
|
|
|
31
31
|
expect(tabHeading).toHaveClass('ds_tabs__title');
|
|
32
|
-
// default
|
|
32
|
+
// default heading level
|
|
33
33
|
expect(tabHeading.tagName).toEqual('H2');
|
|
34
34
|
expect(tabHeading.parentElement).toEqual(tabContainer);
|
|
35
35
|
// default ID-heading
|
|
@@ -83,10 +83,10 @@ test('non-bordered tabs', () => {
|
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
test('custom title', () => {
|
|
86
|
-
const
|
|
86
|
+
const TABS_TITLE = 'My title';
|
|
87
87
|
|
|
88
88
|
render(
|
|
89
|
-
<Tabs data-testid="tabcontainer" title={
|
|
89
|
+
<Tabs data-testid="tabcontainer" title={TABS_TITLE}>
|
|
90
90
|
<Tabs.Item tabLabel="Tab 1" data-testid="tabpanel1">
|
|
91
91
|
<div data-testid="tabpanel1content">Content one</div>
|
|
92
92
|
</Tabs.Item>
|
|
@@ -101,14 +101,14 @@ test('custom title', () => {
|
|
|
101
101
|
const tabHeading = within(tabContainer).getByRole('heading');
|
|
102
102
|
|
|
103
103
|
expect(tabList).toHaveAttribute('aria-labelledby', tabHeading.id);
|
|
104
|
-
expect(tabHeading.textContent).toEqual(
|
|
104
|
+
expect(tabHeading.textContent).toEqual(TABS_TITLE)
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
-
test('custom
|
|
108
|
-
const
|
|
107
|
+
test('custom heading level', () => {
|
|
108
|
+
const HEADING_LEVEL = 'h3';
|
|
109
109
|
|
|
110
110
|
render(
|
|
111
|
-
<Tabs data-testid="tabcontainer"
|
|
111
|
+
<Tabs data-testid="tabcontainer" headingLevel={HEADING_LEVEL}>
|
|
112
112
|
<Tabs.Item tabLabel="Tab 1" data-testid="tabpanel1">
|
|
113
113
|
<div data-testid="tabpanel1content">Content one</div>
|
|
114
114
|
</Tabs.Item>
|
|
@@ -121,34 +121,14 @@ test('custom base ID', () => {
|
|
|
121
121
|
const tabContainer = screen.getByTestId('tabcontainer');
|
|
122
122
|
const tabHeading = within(tabContainer).getByRole('heading');
|
|
123
123
|
|
|
124
|
-
expect(tabHeading).
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test('custom header level', () => {
|
|
128
|
-
const headerLevel = 'h3';
|
|
129
|
-
|
|
130
|
-
render(
|
|
131
|
-
<Tabs data-testid="tabcontainer" headerLevel={headerLevel}>
|
|
132
|
-
<Tabs.Item tabLabel="Tab 1" data-testid="tabpanel1">
|
|
133
|
-
<div data-testid="tabpanel1content">Content one</div>
|
|
134
|
-
</Tabs.Item>
|
|
135
|
-
<Tabs.Item tabLabel="Tab 2" data-testid="tabpanel2">
|
|
136
|
-
Content two
|
|
137
|
-
</Tabs.Item>
|
|
138
|
-
</Tabs>
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
const tabContainer = screen.getByTestId('tabcontainer');
|
|
142
|
-
const tabHeading = within(tabContainer).getByRole('heading');
|
|
143
|
-
|
|
144
|
-
expect(tabHeading.tagName).toEqual(headerLevel.toUpperCase());
|
|
124
|
+
expect(tabHeading.tagName).toEqual(HEADING_LEVEL.toUpperCase());
|
|
145
125
|
});
|
|
146
126
|
|
|
147
127
|
test('custom baseID', () => {
|
|
148
|
-
const
|
|
128
|
+
const BASE_ID = 'myId';
|
|
149
129
|
|
|
150
130
|
render(
|
|
151
|
-
<Tabs data-testid="tabcontainer" baseId={
|
|
131
|
+
<Tabs data-testid="tabcontainer" baseId={BASE_ID}>
|
|
152
132
|
<Tabs.Item tabLabel="Tab 1" data-testid="tabpanel1">
|
|
153
133
|
<div data-testid="tabpanel1content">Content one</div>
|
|
154
134
|
</Tabs.Item>
|
|
@@ -164,23 +144,23 @@ test('custom baseID', () => {
|
|
|
164
144
|
const tabPanelTwo = screen.getByTestId('tabpanel2');
|
|
165
145
|
|
|
166
146
|
// default title slugified to part of the ID
|
|
167
|
-
expect(tabHeading).toHaveAttribute('id', `${
|
|
147
|
+
expect(tabHeading).toHaveAttribute('id', `${BASE_ID}-heading`);
|
|
168
148
|
// generated IDs using the slug of the tab title
|
|
169
|
-
expect(tabPanelOne).toHaveAttribute('id', `${
|
|
170
|
-
expect(tabPanelTwo).toHaveAttribute('id', `${
|
|
149
|
+
expect(tabPanelOne).toHaveAttribute('id', `${BASE_ID}-tab-1`);
|
|
150
|
+
expect(tabPanelTwo).toHaveAttribute('id', `${BASE_ID}-tab-2`);
|
|
171
151
|
});
|
|
172
152
|
|
|
173
153
|
test('tab with and without specific ID attribute', () => {
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
const
|
|
154
|
+
const BASE_ID = 'foo'
|
|
155
|
+
const TAB_LABEL = 'Tab 1';
|
|
156
|
+
const TAB_ID = 'bar';
|
|
177
157
|
|
|
178
158
|
render(
|
|
179
|
-
<Tabs baseId={
|
|
180
|
-
<Tabs.Item tabLabel={
|
|
159
|
+
<Tabs baseId={BASE_ID}>
|
|
160
|
+
<Tabs.Item tabLabel={TAB_LABEL} data-testid="tabpanel1">
|
|
181
161
|
<div data-testid="tabpanel1content">Content one</div>
|
|
182
162
|
</Tabs.Item>
|
|
183
|
-
<Tabs.Item tabLabel="Tab 2" id={
|
|
163
|
+
<Tabs.Item tabLabel="Tab 2" id={TAB_ID} data-testid="tabpanel2">
|
|
184
164
|
<div data-testid="tabpanel1content">Content one</div>
|
|
185
165
|
</Tabs.Item>
|
|
186
166
|
</Tabs>
|
|
@@ -189,8 +169,8 @@ test('tab with and without specific ID attribute', () => {
|
|
|
189
169
|
const tabPanelOne = screen.getByTestId('tabpanel1');
|
|
190
170
|
const tabPanelTwo = screen.getByTestId('tabpanel2');
|
|
191
171
|
|
|
192
|
-
expect(tabPanelOne).toHaveAttribute('id', `${
|
|
193
|
-
expect(tabPanelTwo).toHaveAttribute('id',
|
|
172
|
+
expect(tabPanelOne).toHaveAttribute('id', `${BASE_ID}-${slugify(TAB_LABEL)}`);
|
|
173
|
+
expect(tabPanelTwo).toHaveAttribute('id', TAB_ID);
|
|
194
174
|
});
|
|
195
175
|
|
|
196
176
|
test('with manual activation', () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { isValidElement, Children, useEffect, useRef } from 'react';
|
|
2
|
-
import WrapperTag from '../../common/
|
|
2
|
+
import WrapperTag from '../../common/WrapperTag';
|
|
3
3
|
// @ts-ignore
|
|
4
4
|
import DSTabs from '@scottish-government/design-system/src/components/tabs/tabs';
|
|
5
5
|
import slugify from '../../utils/slugify';
|
|
@@ -44,7 +44,7 @@ const Tabs: React.FC<SGDS.Component.Tabs>
|
|
|
44
44
|
bordered = true,
|
|
45
45
|
children,
|
|
46
46
|
className,
|
|
47
|
-
|
|
47
|
+
headingLevel = 'h2',
|
|
48
48
|
manual = false,
|
|
49
49
|
title = 'Contents',
|
|
50
50
|
...props
|
|
@@ -89,7 +89,7 @@ const Tabs: React.FC<SGDS.Component.Tabs>
|
|
|
89
89
|
<WrapperTag
|
|
90
90
|
id={headingId}
|
|
91
91
|
className="ds_tabs__title"
|
|
92
|
-
tagName={
|
|
92
|
+
tagName={headingLevel}
|
|
93
93
|
>
|
|
94
94
|
{title}
|
|
95
95
|
</WrapperTag>
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { test, expect } from 'vitest';
|
|
2
2
|
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import Tag from './
|
|
3
|
+
import Tag from './Tag';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const TAG_TEXT = 'Beta';
|
|
6
6
|
|
|
7
7
|
test('tag renders correctly', () => {
|
|
8
8
|
render(
|
|
9
|
-
<Tag title={
|
|
9
|
+
<Tag title={TAG_TEXT}/>
|
|
10
10
|
);
|
|
11
11
|
|
|
12
|
-
const tag = screen.getByText(
|
|
12
|
+
const tag = screen.getByText(TAG_TEXT);
|
|
13
13
|
|
|
14
14
|
expect(tag).toHaveClass('ds_tag');
|
|
15
15
|
expect(tag.nodeName).toEqual('SPAN');
|
|
@@ -17,29 +17,29 @@ test('tag renders correctly', () => {
|
|
|
17
17
|
|
|
18
18
|
test('tag with custom colour', () => {
|
|
19
19
|
render(
|
|
20
|
-
<Tag colour="red" title={
|
|
20
|
+
<Tag colour="red" title={TAG_TEXT}/>
|
|
21
21
|
);
|
|
22
22
|
|
|
23
|
-
const tag = screen.getByText(
|
|
23
|
+
const tag = screen.getByText(TAG_TEXT);
|
|
24
24
|
|
|
25
25
|
expect(tag).toHaveClass('ds_tag--red');
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
test('passing additional props', () => {
|
|
29
29
|
render(
|
|
30
|
-
<Tag data-test="foo" title={
|
|
30
|
+
<Tag data-test="foo" title={TAG_TEXT}/>
|
|
31
31
|
);
|
|
32
32
|
|
|
33
|
-
const tag = screen.getByText(
|
|
33
|
+
const tag = screen.getByText(TAG_TEXT);
|
|
34
34
|
expect(tag?.dataset.test).toEqual('foo');
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
test('tag with additional CSS class', () => {
|
|
38
38
|
render(
|
|
39
|
-
<Tag className="foo" title={
|
|
39
|
+
<Tag className="foo" title={TAG_TEXT}/>
|
|
40
40
|
);
|
|
41
41
|
|
|
42
|
-
const tag = screen.getByText(
|
|
42
|
+
const tag = screen.getByText(TAG_TEXT);
|
|
43
43
|
|
|
44
44
|
expect(tag).toHaveClass('foo', 'ds_tag');
|
|
45
45
|
});
|