From f041c1fe10981ea554da91aa06548ed1d9a043a4 Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Thu, 9 Oct 2025 15:50:53 +0200 Subject: [PATCH] ui: extract data-* attributes Signed-off-by: Vincenzo Scamporlino --- packages/ui/src/utils/extractProps.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/ui/src/utils/extractProps.ts b/packages/ui/src/utils/extractProps.ts index 1668117909..3914072ff4 100644 --- a/packages/ui/src/utils/extractProps.ts +++ b/packages/ui/src/utils/extractProps.ts @@ -86,16 +86,25 @@ export function extractProps( } // Ensure keys from props that are defined in propDefs are removed - const cleanedProps = Object.keys(props).reduce((acc, key) => { - if (!propDefs.hasOwnProperty(key)) { - acc[key] = props[key]; - } - return acc; - }, {} as { [key: string]: any }); + const { cleanedProps, dataProps } = Object.keys(props).reduce( + (acc, key) => { + if (key.startsWith('data-')) { + acc.dataProps[key] = props[key]; + } + if (!propDefs.hasOwnProperty(key)) { + acc.cleanedProps[key] = props[key]; + } + return acc; + }, + { dataProps: {}, cleanedProps: {} } as { + dataProps: { [key: string]: any }; + cleanedProps: { [key: string]: any }; + }, + ); const newClassNames = className .filter(name => name && name.trim() !== '') .join(' '); - return { ...cleanedProps, className: newClassNames, style }; + return { ...cleanedProps, className: newClassNames, style, dataProps }; }