From a05d1700c9aad259b076faa696107d303823bec5 Mon Sep 17 00:00:00 2001 From: Dami Oyeniyi Date: Mon, 30 Nov 2026 16:50:43 +0100 Subject: [PATCH] fix(lucide-solid|@lucide/solid): render Icon children in solid and lucide-solid (#5259) * fix(packages): render Icon children in solid and lucide-solid * fix(solid): avoid extra marker nodes when Icon has no children * Fix solid render * Format code --------- Co-authored-by: grzdev Co-authored-by: Eric --- packages/lucide-solid/src/Icon.tsx | 28 ++++++++--------- packages/lucide-solid/tests/Icon.spec.tsx | 30 ++++++++++++++++-- .../lucide-solid/tests/lucide-solid.spec.tsx | 15 +++++++++ packages/solid/src/Icon.tsx | 28 ++++++++--------- packages/solid/tests/Icon.spec.tsx | 31 +++++++++++++++++-- packages/solid/tests/lucide-solid.spec.tsx | 15 +++++++++ 6 files changed, 115 insertions(+), 32 deletions(-) diff --git a/packages/lucide-solid/src/Icon.tsx b/packages/lucide-solid/src/Icon.tsx index 087fc8fd9..72f91f68d 100644 --- a/packages/lucide-solid/src/Icon.tsx +++ b/packages/lucide-solid/src/Icon.tsx @@ -49,25 +49,25 @@ const Icon = (props: LucideProps & IconProps) => { absoluteStrokeWidth: localProps.absoluteStrokeWidth ?? globalProps.absoluteStrokeWidth, nonScalingStroke: localProps.nonScalingStroke ?? globalProps.nonScalingStroke, className: mergeClasses('lucide-icon', globalProps.class, localProps.class), - hasA11yProp: Boolean(localProps.children) || hasA11yProp(rest), + hasA11yProp: hasA11yProp(rest), attributes: rest, }), ); - return ( - - - {([elementName, attrs]) => { - return ( - - ); - }} - - + const paths = ( + + {([elementName, attrs]) => { + return ( + + ); + }} + ); + + return {[paths, localProps.children]}; }; export default Icon; diff --git a/packages/lucide-solid/tests/Icon.spec.tsx b/packages/lucide-solid/tests/Icon.spec.tsx index cf69de5d4..d84125b84 100644 --- a/packages/lucide-solid/tests/Icon.spec.tsx +++ b/packages/lucide-solid/tests/Icon.spec.tsx @@ -122,19 +122,45 @@ describe('Icon Component Accessibility', () => { expect(container.firstChild).not.toHaveAttribute('aria-hidden'); }); - it('should not have aria-hidden prop when there are children that could be a element', async () => { + it('should render a labelled title child and not have aria-hidden prop', async () => { const { container } = render(() => ( <Icon iconNode={airVent} size={48} stroke="red" absoluteStrokeWidth + role="img" + aria-labelledby="warn-title" > - <title>Some title + Warning: Action cannot be undone )); expect(container.firstChild).not.toHaveAttribute('aria-hidden'); + expect(container.firstChild).toHaveAttribute('role', 'img'); + expect(container.firstChild).toHaveAttribute('aria-labelledby', 'warn-title'); + expect(container.querySelector('title#warn-title')).toHaveTextContent( + 'Warning: Action cannot be undone', + ); + }); + + it('should update reactive children', async () => { + const [showTitle, setShowTitle] = createSignal(false); + const { container } = render(() => ( + + {showTitle() && Dynamic title} + + )); + + expect(container.querySelector('title')).toBeNull(); + + setShowTitle(true); + + expect(container.querySelector('title#dynamic-title')).toHaveTextContent('Dynamic title'); }); it('should never override aria-hidden prop', async () => { diff --git a/packages/lucide-solid/tests/lucide-solid.spec.tsx b/packages/lucide-solid/tests/lucide-solid.spec.tsx index 1421dd034..2caf934d9 100644 --- a/packages/lucide-solid/tests/lucide-solid.spec.tsx +++ b/packages/lucide-solid/tests/lucide-solid.spec.tsx @@ -87,4 +87,19 @@ describe('Using lucide icon components', () => { expect(container.firstChild).toHaveClass('lucide'); expect(container.firstChild).toHaveClass('lucide-droplet'); }); + + it('should render child elements inside icon components', () => { + const { container } = render(() => ( + + Water droplet + + )); + + expect(container.firstChild).not.toHaveAttribute('aria-hidden'); + expect(container.firstChild).toHaveAttribute('aria-labelledby', 'droplet-title'); + expect(container.querySelector('title#droplet-title')).toHaveTextContent('Water droplet'); + }); }); diff --git a/packages/solid/src/Icon.tsx b/packages/solid/src/Icon.tsx index dd4019c69..c15308054 100644 --- a/packages/solid/src/Icon.tsx +++ b/packages/solid/src/Icon.tsx @@ -51,25 +51,25 @@ const Icon = (props: LucideProps & IconProps) => { absoluteStrokeWidth: props.absoluteStrokeWidth ?? globalProps.absoluteStrokeWidth, nonScalingStroke: props.nonScalingStroke ?? globalProps.nonScalingStroke, className: mergeClasses('lucide-icon', globalProps.class, props.class), - hasA11yProp: Boolean(props.children) || hasA11yProp(rest()), + hasA11yProp: hasA11yProp(rest()), attributes: rest(), }), ); - return ( - - - {([elementName, attrs]) => { - return ( - - ); - }} - - + const paths = ( + + {([elementName, attrs]) => { + return ( + + ); + }} + ); + + return {[paths, props.children]}; }; export default Icon; diff --git a/packages/solid/tests/Icon.spec.tsx b/packages/solid/tests/Icon.spec.tsx index 500bcff23..9eaa4c36e 100644 --- a/packages/solid/tests/Icon.spec.tsx +++ b/packages/solid/tests/Icon.spec.tsx @@ -123,19 +123,46 @@ describe('Icon Component Accessibility', () => { expect(container.firstChild).not.toHaveAttribute('aria-hidden'); }); - it('should not have aria-hidden prop when there are children that could be a element', async () => { + it('should render a labelled title child and not have aria-hidden prop', async () => { const { container } = render(() => ( <Icon iconNode={airVent} size={48} stroke="red" absoluteStrokeWidth + role="img" + aria-labelledby="warn-title" > - <title>Some title + Warning: Action cannot be undone )); expect(container.firstChild).not.toHaveAttribute('aria-hidden'); + expect(container.firstChild).toHaveAttribute('role', 'img'); + expect(container.firstChild).toHaveAttribute('aria-labelledby', 'warn-title'); + expect(container.querySelector('title#warn-title')).toHaveTextContent( + 'Warning: Action cannot be undone', + ); + }); + + it('should update reactive children', async () => { + const [showTitle, setShowTitle] = createSignal(false); + const { container } = render(() => ( + + {showTitle() && Dynamic title} + + )); + + expect(container.querySelector('title')).toBeNull(); + + setShowTitle(true); + flush(); + + expect(container.querySelector('title#dynamic-title')).toHaveTextContent('Dynamic title'); }); it('should never override aria-hidden prop', async () => { diff --git a/packages/solid/tests/lucide-solid.spec.tsx b/packages/solid/tests/lucide-solid.spec.tsx index 1421dd034..2caf934d9 100644 --- a/packages/solid/tests/lucide-solid.spec.tsx +++ b/packages/solid/tests/lucide-solid.spec.tsx @@ -87,4 +87,19 @@ describe('Using lucide icon components', () => { expect(container.firstChild).toHaveClass('lucide'); expect(container.firstChild).toHaveClass('lucide-droplet'); }); + + it('should render child elements inside icon components', () => { + const { container } = render(() => ( + + Water droplet + + )); + + expect(container.firstChild).not.toHaveAttribute('aria-hidden'); + expect(container.firstChild).toHaveAttribute('aria-labelledby', 'droplet-title'); + expect(container.querySelector('title#droplet-title')).toHaveTextContent('Water droplet'); + }); });