-
-
Notifications
You must be signed in to change notification settings - Fork 827
Open
Labels
Bug: ValidatedThis PR or Issue is verified to be a bug within StencilThis PR or Issue is verified to be a bug within StencilHas WorkaroundThis PR or Issue has a work around detailed within it.This PR or Issue has a work around detailed within it.
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Stencil Version
v2.x
Current Behavior
foreignObject with attributes in SVG cannot be rendered.
Stencil expect the foreignObject to be provided as foreign-object in order to be able to render attributes but, the browser expect the foreignObject to be provided as <foreignObject/> and not <foreign-object/>.
It seems Stencil has an issue only with a subset of SVGAttributes respectively width, height, x and y.
Expected Behavior
Being able to use <foreignObject/> with attributes withing svg in Stencil render functions.
Steps to Reproduce
import { Component, h } from '@stencil/core';
@Component({
tag: 'my-component',
styleUrl: 'my-component.css',
shadow: true,
})
export class MyComponent {
render() {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 300" x="0" y="0" height="300" width="300">
<circle r="142" cx="150" cy="150" fill="none" stroke="#000000" stroke-width="2" />
<foreignObject x={0} y={0} width="200" height="200">
<p>Hello World</p>
</foreignObject>
</svg>
);
}
}
Code Reproduction URL
https://github.com/peterpeterparker/stencil-svg-foreignobject
Additional Information
Notes
a fixed issue regarding foreign object has been opened in the past, see #1733
Screenshots
Workaround
import {Component, h, ComponentInterface} from '@stencil/core';
@Component({
tag: 'deckgo-social-img',
styleUrl: 'social-img.scss',
shadow: true
})
export class SocialImg implements ComponentInterface {
private foreignObjectRef!: SVGForeignObjectElement;
componentDidLoad() {
this.setForeignObjectAttributes();
}
private setForeignObjectAttributes() {
this.foreignObjectRef?.setAttribute('x', '0');
this.foreignObjectRef?.setAttribute('y', '0');
this.foreignObjectRef?.setAttribute('width', '200');
this.foreignObjectRef?.setAttribute('height', '100');
}
render() {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 300" x="0" y="0" height="300" width="300">
<circle r="142" cx="150" cy="150" fill="none" stroke="#000000" stroke-width="2" />
<foreignObject ref={(el) => (this.foreignObjectRef = el as SVGForeignObjectElement)}>
<p>Hello World</p>
</foreignObject>
</svg>
);
}
}
Metadata
Metadata
Assignees
Labels
Bug: ValidatedThis PR or Issue is verified to be a bug within StencilThis PR or Issue is verified to be a bug within StencilHas WorkaroundThis PR or Issue has a work around detailed within it.This PR or Issue has a work around detailed within it.

