Skip to content

Commit 267f271

Browse files
authored
[icons] fix: invalid DOM attribute warning for transform-origin (#6594)
1 parent 1d12bcd commit 267f271

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

packages/icons/scripts/iconComponent.tsx.hbs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export const {{pascalCase iconName}}: React.FC<SVGIconProps> = React.forwardRef<
2727
<path
2828
d={isLarge ? "{{icon20pxPath}}" : "{{icon16pxPath}}"}
2929
fillRule="evenodd"
30-
transform-origin="center"
3130
transform={`scale({{pathScaleFactor}}, -{{pathScaleFactor}}) translate(${translation}, ${translation})`}
3231
/>
3332
</SVGIconContainer>

packages/icons/src/blueprint-icons.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,17 @@ Licensed under the Apache License, Version 2.0.
55

66
@import "generated/16px/blueprint-icons-16";
77
@import "generated/20px/blueprint-icons-20";
8+
9+
/* stylelint-disable-next-line @blueprintjs/no-prefix-literal -- we don't have access to core variables in this file */
10+
.bp5-icon-svg {
11+
// Despite being added to added as a supported SVG attribute to React in 2023, the `transformOrigin` JSX attribute
12+
// is still difficult to use in our statically-generated icon components (`<AddClip>`, `<Calendar>`, etc.)
13+
// which rely on a centered scale `transform="..."` to display their `<path>` elements correctly. To work around
14+
// this, we apply the necessary style in CSS instead. Note that this needs to apply directly to the `<path>` element
15+
// and not the container `<svg>`. See:
16+
// - https://github.com/facebook/react/pull/26130
17+
// - https://github.com/palantir/blueprint/issues/6591
18+
path {
19+
transform-origin: center;
20+
}
21+
}

packages/icons/src/classes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515

1616
const NS = "bp5";
1717
export const ICON = `${NS}-icon`;
18+
export const ICON_SVG = `${ICON}-svg`;

packages/icons/src/svgIconContainer.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ export const SVGIconContainer: SVGIconContainerComponent = React.forwardRef(func
6767
const pixelGridSize = isLarge ? IconSize.LARGE : IconSize.STANDARD;
6868
const viewBox = `0 0 ${pixelGridSize} ${pixelGridSize}`;
6969
const titleId = uniqueId("iconTitle");
70-
const sharedSvgProps = {
71-
"data-icon": iconName,
70+
const sharedSvgProps: React.SVGProps<SVGSVGElement> = {
7271
fill: color,
7372
height: size,
7473
role: "img",
@@ -81,9 +80,11 @@ export const SVGIconContainer: SVGIconContainerComponent = React.forwardRef(func
8180
return (
8281
<svg
8382
aria-labelledby={title ? titleId : undefined}
83+
data-icon={iconName}
8484
ref={ref as React.Ref<SVGSVGElement>}
8585
{...sharedSvgProps}
8686
{...htmlProps}
87+
className={classNames(Classes.ICON_SVG, className, svgProps?.className)}
8788
>
8889
{title && <title id={titleId}>{title}</title>}
8990
{children}
@@ -99,7 +100,7 @@ export const SVGIconContainer: SVGIconContainerComponent = React.forwardRef(func
99100
ref,
100101
title: htmlTitle,
101102
},
102-
<svg {...sharedSvgProps}>
103+
<svg data-icon={iconName} {...sharedSvgProps} className={classNames(Classes.ICON_SVG, svgProps?.className)}>
103104
{title && <title>{title}</title>}
104105
{children}
105106
</svg>,

0 commit comments

Comments
 (0)