diff --git a/packages/components/scripts/post-build/components.js b/packages/components/scripts/post-build/components.js index 0ed6999a044a..81090bc10066 100644 --- a/packages/components/scripts/post-build/components.js +++ b/packages/components/scripts/post-build/components.js @@ -15,6 +15,9 @@ * angular?: { * controlValueAccessor?: string, * directives?: {name:string, ngContentName?:string}[] + * }, + * react?: { + * propsPassingFilter?: string[]; * } * } * }]} @@ -50,7 +53,8 @@ const getComponents = () => [ angular: { controlValueAccessor: 'value' } - },overwrites: { + }, + overwrites: { angular: [ { from: '', @@ -90,6 +94,11 @@ const getComponents = () => [ name: 'drawer', overwrites: { webComponents: [{ from: '__prev.find', to: '!!__prev.find' }] + }, + config: { + react: { + propsPassingFilter: ['onClose'] + } } }, diff --git a/packages/components/scripts/post-build/react.js b/packages/components/scripts/post-build/react.js index b3be1ea3adc7..61d445e65b0d 100644 --- a/packages/components/scripts/post-build/react.js +++ b/packages/components/scripts/post-build/react.js @@ -80,7 +80,11 @@ module.exports = (tmp) => { }, { from: 'ref={ref}', - to: 'ref={ref}\n' + '{...filterPassingProps(props)}' + to: + 'ref={ref}\n' + + `{...filterPassingProps(props,${JSON.stringify( + component?.config?.react?.propsPassingFilter ?? [] + )})}` } ]; diff --git a/packages/components/src/shared/model.ts b/packages/components/src/shared/model.ts index 2888a9c8d51a..af33985bfc9b 100644 --- a/packages/components/src/shared/model.ts +++ b/packages/components/src/shared/model.ts @@ -314,7 +314,7 @@ export type ToggleEventProps = { }; export type ToggleEventState = { - toggle?: (event: ClickEvent) => void; + toggle?: (event?: ClickEvent) => void; }; export type CloseEventProps = { diff --git a/packages/components/src/utils/index.ts b/packages/components/src/utils/index.ts index 6d7fa878fd43..c2d2e41798a6 100644 --- a/packages/components/src/utils/index.ts +++ b/packages/components/src/utils/index.ts @@ -60,15 +60,19 @@ export const getMessageIcon = ( : undefined; }; -export const filterPassingProps = (props: any): any => +export const filterPassingProps = ( + props: any, + propsPassingFilter: string[] +): any => Object.keys(props) .filter( (key) => - key.startsWith('data-') || - key.startsWith('aria-') || - key.startsWith('default') || - key.startsWith('auto') || - key.startsWith('on') + (key.startsWith('data-') || + key.startsWith('aria-') || + key.startsWith('default') || + key.startsWith('auto') || + key.startsWith('on')) && + !propsPassingFilter.includes(key) ) .reduce((obj: any, key: string) => { obj[key] = props[key];