Skip to content
This repository was archived by the owner on Feb 18, 2022. It is now read-only.
This repository was archived by the owner on Feb 18, 2022. It is now read-only.

Custom Property as Fallback for Custom Property #208

Open

Description

@matthiaskomarek

Hello,
thanks for the awesome package and the great work.
I have found an issue when you have a Custom Property defined as Fallback of a Custom Property.

Given the following example:

:root {
    --my-background: #fff;
}
.three {
  background-color: var(--my-var, var(--my-background, pink));
}

Expected output should be:

:root {
    --my-background: #fff;
}
.three {
  background-color: #fff;
}

The Current output if --my-background is defined is like this:

:root {
    --my-background: #fff;
}
.three {
  background-color: var(--my-background, pink);
}

In my opinion the current output is wrong and i would like to make a PR for this if you agree.
Thanks

Activity

  1. Semigradsky commented on Feb 20, 2020

    @Semigradsky
    Member

    Feel free to send PR! :)

  2. Semigradsky commented on Feb 20, 2020

    @Semigradsky
    Member

    I think expected output for

    :root {
        --my-background: #fff;
    }
    .three {
      background-color: var(--my-var, var(--my-background, pink));
    }

    should be:

    :root {
        --my-background: #fff;
    }
    .three {
      background-color: var(--my-var, #fff);
    }

    What do you think?

  3. matthiaskomarek commented on Feb 21, 2020

    @matthiaskomarek
    Author

    Hey @Semigradsky, thanks for the fast reply.

    Your suggestion would break browsers which doesn't support custom properties. Or am i wrong?

  4. Semigradsky commented on Feb 21, 2020

    @Semigradsky
    Member

    But

    .three {
      background-color: #fff;
    }

    will break current browsers. What if we have defined --my-var? Or we want define it via javascript.

  5. evanminto commented on Jul 14, 2020

    @evanminto

    I agree that you can’t replace the entire declaration, but it would be useful to be able to provide a fallback value when preserve is set to true. In my project I’m using this plugin to provide fallback values for older browsers. They’re overwritten by the var() versions in newer browsers. I’d want @matthiaskomarek’s code to turn into:

    .three {
      background-color: #fff;
      background-color: var(--my-var, var(--my-background, pink));
    }

    The fallback value represents the value I want to use when --my-var isn't set. So it makes sense that I’d want to use that same value for browsers that don't support custom properties at all (since that's also a situation where --my-var isn't set).

  6. calebdwilliams commented on Mar 26, 2021

    @calebdwilliams
    Contributor

    This is addressed by #240.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions