Skip to content

Commit 4f4c677

Browse files
authored
chore(component): remove unnecessary event in the post-closebutton (#6152)
## 📄 Description Remove the `postCLick` event since we con simply use `click`. This event is not yet released this I simply updated the related changeset file. --- ## 📝 Checklist - ✅ My code follows the style guidelines of this project - 🛠️ I have performed a self-review of my own code - 📄 I have made corresponding changes to the documentation - ⚠️ My changes generate no new warnings or errors - 🧪 I have added tests that prove my fix is effective or that my feature works - ✔️ New and existing unit tests pass locally with my changes
1 parent 80be71f commit 4f4c677

File tree

7 files changed

+21
-52
lines changed

7 files changed

+21
-52
lines changed

.changeset/spicy-radios-behave.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
'@swisspost/design-system-components': minor
2+
'@swisspost/design-system-components': patch
33
---
44

5-
Added a `postClick` event and accessibility checks to the `post-closebutton` component.
5+
Added accessibility checks to the `post-closebutton` component.

packages/components/eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export default [
9696
'semi': ['error', 'always'],
9797
'react/jsx-no-bind': 'off',
9898
'@stencil-community/strict-boolean-conditions': 'off',
99+
'@stencil-community/prefer-vdom-listener': 'off',
99100
'@stencil-community/required-prefix': ['error', ['post-']],
100101
'@stencil-community/class-pattern': [
101102
'error',

packages/components/src/components.d.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,6 @@ export interface PostCardControlCustomEvent<T> extends CustomEvent<T> {
532532
detail: T;
533533
target: HTMLPostCardControlElement;
534534
}
535-
export interface PostClosebuttonCustomEvent<T> extends CustomEvent<T> {
536-
detail: T;
537-
target: HTMLPostClosebuttonElement;
538-
}
539535
export interface PostCollapsibleCustomEvent<T> extends CustomEvent<T> {
540536
detail: T;
541537
target: HTMLPostCollapsibleElement;
@@ -639,18 +635,7 @@ declare global {
639635
prototype: HTMLPostCardControlElement;
640636
new (): HTMLPostCardControlElement;
641637
};
642-
interface HTMLPostClosebuttonElementEventMap {
643-
"postClick": void;
644-
}
645638
interface HTMLPostClosebuttonElement extends Components.PostClosebutton, HTMLStencilElement {
646-
addEventListener<K extends keyof HTMLPostClosebuttonElementEventMap>(type: K, listener: (this: HTMLPostClosebuttonElement, ev: PostClosebuttonCustomEvent<HTMLPostClosebuttonElementEventMap[K]>) => any, options?: boolean | AddEventListenerOptions): void;
647-
addEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
648-
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
649-
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
650-
removeEventListener<K extends keyof HTMLPostClosebuttonElementEventMap>(type: K, listener: (this: HTMLPostClosebuttonElement, ev: PostClosebuttonCustomEvent<HTMLPostClosebuttonElementEventMap[K]>) => any, options?: boolean | EventListenerOptions): void;
651-
removeEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
652-
removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
653-
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
654639
}
655640
var HTMLPostClosebuttonElement: {
656641
prototype: HTMLPostClosebuttonElement;
@@ -1060,10 +1045,6 @@ declare namespace LocalJSX {
10601045
"value"?: string;
10611046
}
10621047
interface PostClosebutton {
1063-
/**
1064-
* An event emitted when the close button is clicked. It has no payload.
1065-
*/
1066-
"onPostClick"?: (event: PostClosebuttonCustomEvent<void>) => void;
10671048
}
10681049
interface PostCollapsible {
10691050
/**

packages/components/src/components/post-banner/post-banner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class PostBanner {
7777
this.postDismissed.emit();
7878
}
7979

80-
@Listen('postClick')
80+
@Listen('click')
8181
@EventFrom('post-closebutton')
8282
onCloseButtonClick(): void {
8383
void this.dismiss();

packages/components/src/components/post-closebutton/post-closebutton.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Element, Event, EventEmitter, h, Host } from '@stencil/core';
1+
import { Component, Element, h, Host } from '@stencil/core';
22
import { version } from '@root/package.json';
33

44
/**
@@ -12,12 +12,6 @@ import { version } from '@root/package.json';
1212
export class PostClosebutton {
1313
@Element() host: HTMLPostClosebuttonElement;
1414

15-
/**
16-
* An event emitted when the close button is clicked.
17-
* It has no payload.
18-
*/
19-
@Event() postClick: EventEmitter<void>;
20-
2115
componentDidLoad() {
2216
this.checkHiddenLabel();
2317
}
@@ -31,7 +25,7 @@ export class PostClosebutton {
3125
render() {
3226
return (
3327
<Host data-version={version}>
34-
<button class="btn btn-icon-close" type="button" onClick={() => this.postClick.emit()}>
28+
<button class="btn btn-icon-close" type="button">
3529
<post-icon aria-hidden="true" name="closex"></post-icon>
3630
<span class="visually-hidden">
3731
<slot onSlotchange={() => this.checkHiddenLabel()}></slot>

packages/components/src/components/post-closebutton/readme.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
<!-- Auto Generated Below -->
66

77

8-
## Events
9-
10-
| Event | Description | Type |
11-
| ----------- | --------------------------------------------------------------------- | ------------------- |
12-
| `postClick` | An event emitted when the close button is clicked. It has no payload. | `CustomEvent<void>` |
13-
14-
158
## Slots
169

1710
| Slot | Description |

packages/components/src/utils/event-from.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
* @returns true if the event should be processed, false otherwise
88
*/
99
function shouldProcessEvent(
10-
event: CustomEvent,
10+
event: Event,
1111
tag: string,
1212
host: HTMLElement,
1313
ignoreNestedComponents: boolean
1414
): boolean {
15-
if (!(event instanceof CustomEvent && event.target instanceof HTMLElement)) return false;
15+
if (!(event instanceof Event && event.target instanceof HTMLElement)) return false;
1616

1717
const eventTarget = event.target;
18-
18+
1919
if (eventTarget.localName !== tag) return false;
20-
20+
2121
if (ignoreNestedComponents) {
2222
// Find the closest parent with the same tag as the host
2323
const closestParentWithSameTag = findClosestParentWithTag(eventTarget, host.localName);
@@ -34,7 +34,7 @@ function shouldProcessEvent(
3434
* @param option.ignoreNestedComponents - Whether to ignore events from nested components
3535
*/
3636
export function EventFrom(
37-
tag: string,
37+
tag: string,
3838
option: { ignoreNestedComponents: boolean } = { ignoreNestedComponents: true }
3939
) {
4040
return function (
@@ -44,19 +44,19 @@ export function EventFrom(
4444
) {
4545
if (descriptor) {
4646
const originalMethod = descriptor.value;
47-
48-
descriptor.value = function (event: CustomEvent) {
47+
48+
descriptor.value = function (event: Event) {
4949
if (!shouldProcessEvent(event, tag, this.host, option.ignoreNestedComponents)) {
5050
return;
5151
}
5252

5353
return originalMethod.call(this, event);
5454
};
5555
} else {
56-
// Creates a hidden storage property for the original method using a
56+
// Creates a hidden storage property for the original method using a
5757
// modified key format (__[property]_original) to avoid naming conflicts
5858
const privateKey = `__${propertyKey}_original`;
59-
59+
6060
// Create hidden storage for original method
6161
Object.defineProperty(target, privateKey, {
6262
writable: true,
@@ -71,10 +71,10 @@ export function EventFrom(
7171
},
7272

7373
// Setter wraps original method with extra code
74-
set(originalFunction: (event: CustomEvent) => void) {
74+
set(originalFunction: (event: Event) => void) {
7575
if (typeof originalFunction === 'function') {
7676
// Store original and add new behavior
77-
this[privateKey] = (event: CustomEvent) => {
77+
this[privateKey] = (event: Event) => {
7878
if (!shouldProcessEvent(event, tag, this.host, option.ignoreNestedComponents)) {
7979
return;
8080
}
@@ -101,7 +101,7 @@ export function EventFrom(
101101
*/
102102
function findClosestParentWithTag(element: Element, tagName: string): Element | null {
103103
let current: Element | null = element;
104-
104+
105105
while (current) {
106106
if (current.localName === tagName) {
107107
return current;
@@ -110,16 +110,16 @@ function findClosestParentWithTag(element: Element, tagName: string): Element |
110110
// Check regular parent first
111111
if (current.parentElement) {
112112
current = current.parentElement;
113-
}
113+
}
114114
// If no parentElement, check if we're in a shadow root
115115
else if (current.parentNode instanceof ShadowRoot) {
116116
current = current.parentNode.host;
117-
}
117+
}
118118
// No more parents to check
119119
else {
120120
current = null;
121121
}
122122
}
123-
123+
124124
return null;
125125
}

0 commit comments

Comments
 (0)