Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I use SVG in my DOM, there is no SVG’s icon in the exported picture #139

Open
1 task
cMing1997 opened this issue May 16, 2023 · 7 comments
Open
1 task

Comments

@cMing1997
Copy link

Use case: description, code

I use webpack4 packaging, using SVG's Symbol ID function
Component Definition:

<template>
	<div class="icon-wrapper" @click="onClick">
		<svg class="icon" aria-hidden="true">
			<use :xlink:href="iconName"></use>
		</svg>
	</div>
</template>

<script>
export default {
	name: "SvgIcon",
	props: {
		type: String,
	},
	computed: {
		iconName() {
			return `#${this.type}`;
		},
	},
    methods:{
        onClick(e) {
            this.$emit("click", e);
        },
    }
};
</script>

<style lang="less" scoped>
.icon-wrapper {
    display: inline-flex;
    align-items: center;
    overflow: hidden;
    width: 100%;
    height: 100%;
    font-style: normal;
    line-height: 0;
    text-align: center;
    text-transform: none;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;

    svg {
        display: inline-block;
        line-height: 1;
        width: 1em;
        height: 1em;
        fill: currentColor;

        &.sn-icon-spin {
            animation: loadingCircle 1s infinite linear;
        }
    }
}
</style>

Used:

<svg-icon class="icon" type="btn_behavior_downarrow"></svg-icon>

DOM display
image

Expected behavior

The exported picture is the same as the display on the page

Library version

3.1.6

Browsers

  • "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"
@cMing1997 cMing1997 changed the title Export when I use SVG in my DOM. The exported picture is not drawn in the shape of SVG When I use SVG in my DOM, there is no SVG’s icon in the exported picture May 16, 2023
@IDisposable
Copy link
Member

the href="#btn_behavior_downarrow" would be a ID reference to the current HTML page, which would never be a valid SVG. Please simplify to the static HTML+CSS that fails in a jsfiddle.

@cMing1997
Copy link
Author

the href="#btn_behavior_downarrow" would be a ID reference to the current HTML page, which would never be a valid SVG. Please simplify to the static HTML+CSS that fails in a jsfiddle.

Sorry, it's my mistake. This is the simplest link to show the problem. :https://jsfiddle.net/wuxintongxue22/1hn6cbr0/1/

@bliitzkrieg
Copy link

@cMing1997 I have the exact same issue, did you find a solution?

@cMing1997
Copy link
Author

@cMing1997 I have the exact same issue, did you find a solution?

No, I ended up with an actual rendered SVG and icon font instead

@fran7de
Copy link

fran7de commented Sep 6, 2023

I have the same issue. I have an Angular component that uses a use tag in an svg. In the browser I can see the image but not in the exported image.

@Maskys13
Copy link

@cMing1997 my svg'icon is the same issure, did you find a solution currently?

@cMing1997
Copy link
Author

@cMing1997 my svg'icon is the same issure, did you find a solution currently?

It's not the perfect solution. It's just avoiding it

The solution

  1. Use Font Icons instead of SVG
  2. Instead of using the attributes of the SVG Link, render the entire SVG directly into the Dom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants