Skip to content

chore(components): review and update prop validation across component library #4891

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

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6ff7c58
chore(components): review prop validation
myrta2302 Mar 3, 2025
4603baf
chore(components): prop validation update and 'warning' option
myrta2302 Mar 6, 2025
d4fe216
clean up
myrta2302 Mar 6, 2025
b141fba
test error
myrta2302 Mar 6, 2025
d079234
add changeset
myrta2302 Mar 6, 2025
0ca253d
Merge branch 'main' into 4651-review-prop-validation-across-component…
myrta2302 Mar 6, 2025
c49834e
minor updates
myrta2302 Mar 27, 2025
7e32b28
decision update
myrta2302 Apr 7, 2025
9332122
minor
myrta2302 Apr 7, 2025
2b2c5af
Merge branch 'main' into 4651-review-prop-validation-across-component…
myrta2302 Apr 7, 2025
9375967
remove warnings
myrta2302 Apr 7, 2025
e02c81d
adjust components
myrta2302 Apr 7, 2025
988bb34
prop and validation updates
myrta2302 Apr 8, 2025
87f9530
prop validation update
myrta2302 Apr 9, 2025
44193a7
for merge
myrta2302 Apr 9, 2025
90722e3
Merge branch 'main' into 4651-review-prop-validation-across-component…
myrta2302 Apr 9, 2025
3139ce7
update card control
myrta2302 Apr 9, 2025
68387c9
update card control
myrta2302 Apr 9, 2025
62fdab2
update rating and popover missing prop
myrta2302 Apr 9, 2025
3ae156e
update checkType for numbers
myrta2302 Apr 9, 2025
398bd6d
update post tag
myrta2302 Apr 9, 2025
138115e
minor
myrta2302 Apr 10, 2025
cd97429
tag colors update
myrta2302 Apr 10, 2025
ffd8d8a
update test
myrta2302 Apr 10, 2025
c834df0
update tests
myrta2302 Apr 10, 2025
5652e43
tests update
myrta2302 Apr 10, 2025
f3b5800
test update
myrta2302 Apr 10, 2025
d17f849
test updates
myrta2302 Apr 14, 2025
f6f5d71
Merge branch 'main' into 4651-review-prop-validation-across-component…
myrta2302 Apr 14, 2025
6e4acc4
revert card-control test
myrta2302 Apr 14, 2025
35dcf26
card control tests
myrta2302 Apr 14, 2025
00839c6
uncomment test
myrta2302 Apr 14, 2025
3f61906
Merge branch 'main' into 4651-review-prop-validation-across-component…
myrta2302 Apr 14, 2025
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
6 changes: 6 additions & 0 deletions .changeset/chatty-paws-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@swisspost/design-system-documentation': patch
'@swisspost/design-system-components': patch
---

Aligned prop validation across the component library and replaced thrown errors with console errors.
20 changes: 11 additions & 9 deletions packages/components/cypress/e2e/back-to-top.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ describe('Back-to-top', () => {
cy.get('post-back-to-top').should('exist');
});

it('should throw an error if the label is missing', () => {
cy.on('uncaught:exception', err => {
expect(err.message).to.include(
'The label property of the Back to Top component is required for accessibility purposes. Please ensure it is set.',
);
return false;
it('should log a message if the label is removed', () => {
cy.window().then(win => {
cy.spy(win.console, 'error').as('consoleError');
});
cy.document().then(doc => {
const element = doc.createElement('post-back-to-top');
doc.body.appendChild(element);

cy.get('post-back-to-top').then($el => {
$el[0].removeAttribute('label');
});

cy.get('@consoleError').should(
'be.calledWith',
'The prop `label` of the `post-back-to-top` component is not defined.',
);
});

it('should hide the label visually', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/components/cypress/e2e/card-control.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ describe('Card-Control', () => {
cy.get('@consoleError')
.invoke('getCalls')
.then(calls => {
expect(calls[0].args[0].message).to.eq(
'The prop `label` of the `post-card-control` component is required.',
expect(calls[0].args[0]).to.eq(
'The prop `label` of the `post-card-control` component is not defined.',
);
});
});
Expand Down Expand Up @@ -92,8 +92,8 @@ describe('Card-Control', () => {
cy.get('@consoleError')
.invoke('getCalls')
.then(calls => {
expect(calls[0].args[0].message).to.eq(
'The prop `type` of the `post-card-control` component must be one of the following values: checkbox, radio.',
expect(calls[0].args[0]).to.eq(
'The prop `type` of the `post-card-control` component is not defined.',
);
});
});
Expand Down
18 changes: 10 additions & 8 deletions packages/components/cypress/e2e/list.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ describe('PostList Component', { baseUrl: null, includeShadowDom: false }, () =>
});
});

it('should throw an error if the title is missing', () => {
// Check for the mandatory title accessibility error if no title is provided
cy.on('uncaught:exception', err => {
expect(err.message).to.include(
'Please provide a title to the list component. Title is mandatory for accessibility purposes.',
);
return false;
it('should log an error if the title is missing', () => {
cy.window().then(win => {
cy.spy(win.console, 'error').as('consoleError');
});

cy.get('post-list').within(() => {
cy.get('[slot="post-list-item"]').first().invoke('remove');
cy.get(':first-child').invoke('remove');
});

cy.get('@consoleError').should(
'be.calledWith',
'Please provide a title to the list component. Title is mandatory for accessibility purposes.',
);
});

it('should hide the title when title-hidden is set', () => {
Expand Down
12 changes: 0 additions & 12 deletions packages/components/cypress/fixtures/post-back-to-top.test.html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should probably not be deleted.

This file was deleted.

72 changes: 36 additions & 36 deletions packages/components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ export namespace Components {
/**
* The label to use for the close button of a dismissible banner.
*/
"dismissLabel": string;
"dismissLabel"?: string;
/**
* If `true`, a close button (×) is displayed and the banner can be dismissed by the user.
*/
"dismissible": boolean;
/**
* The icon to display in the banner. By default, the icon depends on the banner type. If `none`, no icon is displayed.
*/
"icon": string;
"icon"?: string;
/**
* The type of the banner.
*/
Expand Down Expand Up @@ -126,7 +126,7 @@ export namespace Components {
/**
* Defines the description in the control-label.
*/
"description": string;
"description"?: string;
/**
* Defines the `disabled` attribute of the control. If `true`, the user can not interact with the control and the controls value will not be included in the forms' data.
*/
Expand All @@ -138,15 +138,15 @@ export namespace Components {
/**
* Defines the icon `name` inside the card. <span className="banner banner-sm banner-info">If not set the icon will not show up.</span>
*/
"icon": string;
"icon"?: string;
/**
* Defines the text in the control-label.
*/
"label": string;
/**
* Defines the `name` attribute of the control. <span className="mb-4 banner banner-sm banner-info">This is a required property, when the control should participate in a native `form`. If not specified, a native `form` will never contain this controls value.</span> <span className="banner banner-sm banner-info">This is a required property, when the control is used with type `radio`.</span>
*/
"name": string;
"name"?: string;
/**
* A public method to reset the controls `checked` and `validity` state. The validity state is set to `null`, so it's neither valid nor invalid.
*/
Expand All @@ -158,11 +158,11 @@ export namespace Components {
/**
* Defines the validation `validity` of the control. To reset validity to an undefined state, simply remove the attribute from the control.
*/
"validity": null | 'true' | 'false';
"validity"?: 'true' | 'false';
/**
* Defines the `value` attribute of the control. <span className="banner banner-sm banner-info">This is a required property, when the control is used with type `radio`.</span>
*/
"value": string;
"value"?: string;
}
interface PostClosebutton {
}
Expand Down Expand Up @@ -205,11 +205,11 @@ export namespace Components {
/**
* The name of the animation.
*/
"animation"?: Animation | null;
"animation"?: Animation;
/**
* The base path, where the icons are located (must be a public url).<br/>Leave this field empty to use the default cdn url.
*/
"base"?: string | null;
"base"?: string;
/**
* When set to `true`, the icon will be flipped horizontally.
*/
Expand All @@ -225,37 +225,37 @@ export namespace Components {
/**
* The number of degree for the css rotate transformation.
*/
"rotate"?: number | null;
"rotate"?: number;
/**
* The number for the css scale transformation.
*/
"scale"?: number | null;
"scale"?: number;
}
interface PostLanguageOption {
/**
* If set to `true`, the language option is considered the current language for the page.
*/
"active": boolean;
"active"?: boolean;
/**
* The ISO 639 language code, formatted according to [RFC 5646 (also known as BCP 47)](https://datatracker.ietf.org/doc/html/rfc5646). For example, "de".
*/
"code": string;
/**
* The full name of the language. For example, "Deutsch".
*/
"name": string;
"name"?: string;
/**
* Selects the language option programmatically.
*/
"select": () => Promise<void>;
/**
* The URL used for the href attribute of the internal anchor. This field is optional; if not provided, a button will be used internally instead of an anchor.
*/
"url": string;
"url"?: string;
/**
* To communicate the variant prop from the parent (post-language-switch) component to the child (post-language-option) component. See parent docs for a description about the property itself.
*/
"variant"?: SwitchVariant | null;
"variant"?: SwitchVariant;
}
interface PostLanguageSwitch {
/**
Expand Down Expand Up @@ -289,7 +289,7 @@ export namespace Components {
/**
* The URL to which the user is redirected upon clicking the logo.
*/
"url": string | URL;
"url"?: string | URL;
}
interface PostMainnavigation {
}
Expand Down Expand Up @@ -444,7 +444,7 @@ export namespace Components {
/**
* The name of the panel that is initially shown. If not specified, it defaults to the panel associated with the first tab. **Changing this value after initialization has no effect.**
*/
"activePanel": HTMLPostTabPanelElement['name'];
"activePanel"?: HTMLPostTabPanelElement['name'];
/**
* Shows the panel with the given name and selects its associated tab. Any other panel that was previously shown becomes hidden and its associated tab is unselected.
*/
Expand All @@ -454,15 +454,15 @@ export namespace Components {
/**
* Defines the icon `name` inside of the component. <span className="banner banner-sm banner-info">If not set the icon will not show up.</span> To learn which icons are available, please visit our <a href="/?path=/docs/5704bdc4-c5b5-45e6-b123-c54d01fce2f1--docs">icon library</a>.
*/
"icon": null | string;
"icon": string;
/**
* Defines the size of the component.
*/
"size": null | 'sm';
"size"?: 'sm';
/**
* Defines the color variant of the component.
*/
"variant": 'white' | 'info' | 'success' | 'error' | 'warning' | 'yellow';
"variant"?: 'white' | 'info' | 'success' | 'error' | 'warning' | 'yellow';
}
interface PostTogglebutton {
/**
Expand All @@ -472,7 +472,7 @@ export namespace Components {
}
interface PostTooltip {
/**
* Wheter or not to display a little pointer arrow
* Whether or not to display a little pointer arrow
*/
"arrow"?: boolean;
/**
Expand Down Expand Up @@ -985,7 +985,7 @@ declare namespace LocalJSX {
/**
* The URL for the home breadcrumb item.
*/
"homeUrl"?: string;
"homeUrl": string;
}
interface PostBreadcrumbItem {
/**
Expand Down Expand Up @@ -1036,7 +1036,7 @@ declare namespace LocalJSX {
/**
* Defines the validation `validity` of the control. To reset validity to an undefined state, simply remove the attribute from the control.
*/
"validity"?: null | 'true' | 'false';
"validity"?: 'true' | 'false';
/**
* Defines the `value` attribute of the control. <span className="banner banner-sm banner-info">This is a required property, when the control is used with type `radio`.</span>
*/
Expand All @@ -1058,7 +1058,7 @@ declare namespace LocalJSX {
/**
* Link the trigger to a post-collapsible with this id
*/
"for"?: string;
"for": string;
}
interface PostFooter {
/**
Expand All @@ -1079,11 +1079,11 @@ declare namespace LocalJSX {
/**
* The name of the animation.
*/
"animation"?: Animation | null;
"animation"?: Animation;
/**
* The base path, where the icons are located (must be a public url).<br/>Leave this field empty to use the default cdn url.
*/
"base"?: string | null;
"base"?: string;
/**
* When set to `true`, the icon will be flipped horizontally.
*/
Expand All @@ -1099,11 +1099,11 @@ declare namespace LocalJSX {
/**
* The number of degree for the css rotate transformation.
*/
"rotate"?: number | null;
"rotate"?: number;
/**
* The number for the css scale transformation.
*/
"scale"?: number | null;
"scale"?: number;
}
interface PostLanguageOption {
/**
Expand Down Expand Up @@ -1133,17 +1133,17 @@ declare namespace LocalJSX {
/**
* To communicate the variant prop from the parent (post-language-switch) component to the child (post-language-option) component. See parent docs for a description about the property itself.
*/
"variant"?: SwitchVariant | null;
"variant"?: SwitchVariant;
}
interface PostLanguageSwitch {
/**
* A title for the list of language options
*/
"caption"?: string;
"caption": string;
/**
* A descriptive text for the list of language options
*/
"description"?: string;
"description": string;
/**
* Whether the component is rendered as a list or a menu
*/
Expand Down Expand Up @@ -1271,13 +1271,13 @@ declare namespace LocalJSX {
/**
* The name of the panel controlled by the tab header.
*/
"panel"?: HTMLPostTabPanelElement['name'];
"panel": HTMLPostTabPanelElement['name'];
}
interface PostTabPanel {
/**
* The name of the panel, used to associate it with a tab header.
*/
"name"?: string;
"name": string;
}
interface PostTabs {
/**
Expand All @@ -1293,11 +1293,11 @@ declare namespace LocalJSX {
/**
* Defines the icon `name` inside of the component. <span className="banner banner-sm banner-info">If not set the icon will not show up.</span> To learn which icons are available, please visit our <a href="/?path=/docs/5704bdc4-c5b5-45e6-b123-c54d01fce2f1--docs">icon library</a>.
*/
"icon"?: null | string;
"icon"?: string;
/**
* Defines the size of the component.
*/
"size"?: null | 'sm';
"size"?: 'sm';
/**
* Defines the color variant of the component.
*/
Expand All @@ -1311,7 +1311,7 @@ declare namespace LocalJSX {
}
interface PostTooltip {
/**
* Wheter or not to display a little pointer arrow
* Whether or not to display a little pointer arrow
*/
"arrow"?: boolean;
/**
Expand Down
Loading