fix aria-hidden="true" in @lucide/svelte (#4234)

This commit is contained in:
blt-r
2026-04-03 16:43:35 +04:00
committed by GitHub
parent 5faceb5495
commit 51e37e2e2c
3 changed files with 25 additions and 11 deletions

View File

@@ -36,8 +36,6 @@ const iconNode: IconNode = ${JSON.stringify(children)};
*/
</script>
<Icon name="${iconName}" {...props} iconNode={iconNode}>
{@render props.children?.()}
</Icon>
<Icon name="${iconName}" {...props} iconNode={iconNode} />
`;
});

View File

@@ -2,6 +2,7 @@
exports[`Using lucide icon components > should add a class to the element 1`] = `
<svg
aria-hidden="true"
class="lucide-icon lucide lucide-smile my-icon"
fill="none"
height="24"
@@ -51,14 +52,13 @@ exports[`Using lucide icon components > should add a class to the element 1`] =
<!---->
<!---->
<!---->
</svg>
`;
exports[`Using lucide icon components > should adjust the size, stroke color and stroke width 1`] = `
<div>
<svg
aria-hidden="true"
class="lucide-icon lucide lucide-smile"
fill="none"
height="48"
@@ -108,8 +108,6 @@ exports[`Using lucide icon components > should adjust the size, stroke color and
<!---->
<!---->
<!---->
</svg>
@@ -126,6 +124,7 @@ exports[`Using lucide icon components > should not scale the strokeWidth when ab
stroke-width="1"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
class="lucide-icon lucide lucide-smile"
>
<circle cx="12"
@@ -153,6 +152,7 @@ exports[`Using lucide icon components > should not scale the strokeWidth when ab
exports[`Using lucide icon components > should render an component 1`] = `
<div>
<svg
aria-hidden="true"
class="lucide-icon lucide lucide-smile"
fill="none"
height="24"
@@ -202,8 +202,6 @@ exports[`Using lucide icon components > should render an component 1`] = `
<!---->
<!---->
<!---->
</svg>
@@ -260,12 +258,10 @@ exports[`Using lucide icon components > should render an icon slot 1`] = `
</line>
<!---->
<!---->
<text>
Test
</text>
<!---->
</svg>

View File

@@ -94,3 +94,23 @@ describe('Using lucide icon components', () => {
expect(IconComponent).toHaveAttribute('stroke-width', '1');
});
});
describe('Icon Component Accessibility', () => {
it('should have aria-hidden prop when no aria prop or children are present', async () => {
const { container } = render(Smile, {
props: {
size: 48,
color: 'red',
absoluteStrokeWidth: true,
},
});
expect(container.firstChild).toHaveAttribute('aria-hidden', 'true');
});
it('should not have aria-hidden prop when there are children that could be a <title> element', async () => {
const { container } = render(TestSlots);
expect(container.firstChild).not.toHaveAttribute('aria-hidden');
});
});