Skip to content

IE11 getComputedStyle does not report custom properties correctly #2

Description

@kaiyote

This library uses window.getComputedStyle(document.documentElement).getPropertyValue('--custom-prop') to find the value to replace the var(--custom-prop) with.

Unfortunately, this doesn't work in IE11 (as I just found out). So we fixed the plugin running in IE11 with #1, but unfortunately it still can't figure out the correct value. It does grab the fallback value in the form of var(--prop, fallback) correctly. It just cannot find the real value.

I know that css-vars-ponyfill has its own css parser, which is how it gets around IE11's limitation. Unless I'm doing something wrong (a definite possibility), this is gonna be an issue.....

Minimal demo:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>IE computedStyle test</title>
  <style>
    :root {
      --test: red;
    }
  </style>
</head>
<body>
  <script>
    document.addEventListener('DOMContentLoaded', function () {
      let computed = getComputedStyle(document.documentElement).getPropertyValue('--test')
      console.log('value of `--test`: "' + computed +  '"')
    })
  </script>
</body>
</html>

Chrome Output: value of '--test': " red"
IE11 Output: value of '--test': ""

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions