1
0
mirror of https://github.com/tabler/tabler-icons.git synced 2025-08-31 17:42:15 +02:00

Add <title> to <svg> in Preact (#1157)

* Add <title> to <svg> in Preact

Needs to be tested.

* Uncomment title attribute

---------

Co-authored-by: Bartłomiej Gawęda <bgaweda@abis.krakow.pl>
This commit is contained in:
BG-Software
2024-06-13 22:11:45 +02:00
committed by GitHub
parent b6591cec2d
commit 4a8ba697b4
3 changed files with 15 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ const createPreactComponent = (
color = 'currentColor',
size = 24,
stroke = 2,
title,
children,
className = '',
style,
@@ -35,7 +36,10 @@ const createPreactComponent = (
style,
...[rest],
},
[...iconNode.map(([tag, attrs]) => h(tag, attrs)), ...toChildArray(children)],
[
title && h('title', {}, title),
...iconNode.map(([tag, attrs]) => h(tag, attrs)),
...toChildArray(children)],
);
Component.displayName = `${iconNamePascal}`;

View File

@@ -7,6 +7,7 @@ export interface IconProps
color?: string;
size?: string | number;
stroke?: string | number;
title?: string;
}
export type Icon = FunctionComponent<IconProps>;

View File

@@ -51,6 +51,15 @@ describe("Preact Icon component", () => {
expect(svg).toHaveStyle('color: rgb(255, 0, 0)')
})
it('should add a title element to the svg', () => {
const { container } = render(<IconAccessible title="Accessible Icon"/>)
const svg = container.getElementsByTagName("svg")[0]
const title = container.getElementsByTagName("title")[0]
expect(svg.getAttribute("title")).toBe("Accessible Icon");
expect(title).toHaveTextContent("Accessible Icon");
})
it("should match snapshot", () => {
const { container } = render(<IconAccessible/>)
expect(container.innerHTML).toMatchInlineSnapshot(`