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

fix(useElementSize): fix incorrect element size on SVG #2661

Merged
merged 3 commits into from Jan 29, 2023

Conversation

Lionad-Morotar
Copy link
Contributor

Description

fix #2084

fix incorrect size on SVG element, due to https://www.w3.org/TR/resize-observer/#calculate-box-size

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

Copy link
Member

@wheatjs wheatjs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me unless anyone thinks this will introduce some breaking changes, but I can't see any obvious ones.

@antfu antfu merged commit 902b3cc into vueuse:main Jan 29, 2023
@Lionad-Morotar
Copy link
Contributor Author

const isSVG = computed(() => unrefElement(target)?.namespaceURI?.includes('svg'))

Method isSVG check only svg tag. What about the g tag?
Ex: I am building inside svg -> d chart and want to center align using translate (svg width 100%)

It seems works fine with "g" tag:

image

g、path 等标签也支持。不过,我觉得 getComputedStyle 这个方法也许换成 getBoundingRect 会更好一些?

@MstrVLT
Copy link

MstrVLT commented Mar 15, 2023

getComputedStyle

that was the problem - thx!

@Lionad-Morotar Lionad-Morotar deleted the patch-2 branch March 15, 2023 10:16
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

Successfully merging this pull request may close these issues.

useElementSize returns wrong size for SVG element
4 participants