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 <grzdev@users.noreply.github.com>
Co-authored-by: Eric <eric.fennis@gmail.com>
This commit is contained in:
Dami Oyeniyi
2026-11-30 16:50:43 +01:00
committed by GitHub
co-authored by grzdev Eric
parent cd12948ef6
commit a05d1700c9
6 changed files with 115 additions and 32 deletions
+14 -14
View File
@@ -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 (
<svg {...builtIcon()[1]}>
<For each={builtIcon()[2] ?? []}>
{([elementName, attrs]) => {
return (
<Dynamic
component={elementName}
{...attrs}
/>
);
}}
</For>
</svg>
const paths = (
<For each={builtIcon()[2] ?? []}>
{([elementName, attrs]) => {
return (
<Dynamic
component={elementName}
{...attrs}
/>
);
}}
</For>
);
return <svg {...builtIcon()[1]}>{[paths, localProps.children]}</svg>;
};
export default Icon;
+28 -2
View File
@@ -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 <title> 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</title>
<title id="warn-title">Warning: Action cannot be undone</title>
</Icon>
));
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(() => (
<Icon
iconNode={airVent}
role="img"
aria-labelledby="dynamic-title"
>
{showTitle() && <title id="dynamic-title">Dynamic title</title>}
</Icon>
));
expect(container.querySelector('title')).toBeNull();
setShowTitle(true);
expect(container.querySelector('title#dynamic-title')).toHaveTextContent('Dynamic title');
});
it('should never override aria-hidden prop', async () => {
@@ -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(() => (
<Droplet
role="img"
aria-labelledby="droplet-title"
>
<title id="droplet-title">Water droplet</title>
</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');
});
});
+14 -14
View File
@@ -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 (
<svg {...builtIcon()[1]}>
<For each={builtIcon()[2] ?? []}>
{([elementName, attrs]) => {
return (
<Dynamic
component={elementName}
{...attrs}
/>
);
}}
</For>
</svg>
const paths = (
<For each={builtIcon()[2] ?? []}>
{([elementName, attrs]) => {
return (
<Dynamic
component={elementName}
{...attrs}
/>
);
}}
</For>
);
return <svg {...builtIcon()[1]}>{[paths, props.children]}</svg>;
};
export default Icon;
+29 -2
View File
@@ -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 <title> 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</title>
<title id="warn-title">Warning: Action cannot be undone</title>
</Icon>
));
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(() => (
<Icon
iconNode={airVent}
role="img"
aria-labelledby="dynamic-title"
>
{showTitle() && <title id="dynamic-title">Dynamic title</title>}
</Icon>
));
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 () => {
@@ -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(() => (
<Droplet
role="img"
aria-labelledby="droplet-title"
>
<title id="droplet-title">Water droplet</title>
</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');
});
});