diff --git a/packages/lucide/src/replaceElement.js b/packages/lucide/src/replaceElement.js index 12f656e77..ccfd0681d 100644 --- a/packages/lucide/src/replaceElement.js +++ b/packages/lucide/src/replaceElement.js @@ -71,6 +71,7 @@ export default (element, { nameAttr, icons, attrs }) => { ...iconAttributes, 'icon-name': iconName, ...attrs, + ...elementAttrs, }; const classNames = combineClassNames(['lucide', `lucide-${iconName}`, elementAttrs, attrs]); diff --git a/packages/lucide/tests/lucide.spec.js b/packages/lucide/tests/lucide.spec.js index 60a55b1e1..b0587e7bf 100644 --- a/packages/lucide/tests/lucide.spec.js +++ b/packages/lucide/tests/lucide.spec.js @@ -64,4 +64,25 @@ describe('createIcons', () => { expect(attributesAndValues).toEqual(expect.objectContaining(attrs)); }); + + it('should inherit elements attributes', () => { + document.body.innerHTML = ``; + + const attrs = { + 'data-theme-switcher':'light', + }; + + createIcons({ icons }); + + const element = document.querySelector('svg'); + const attributes = element.getAttributeNames(); + + const attributesAndValues = attributes.reduce((acc, item) => { + acc[item] = element.getAttribute(item); + + return acc; + },{}) + + expect(attributesAndValues).toEqual(expect.objectContaining(attrs)); + }); });