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

properties order are not respected #105

Closed
Gastonite opened this issue Aug 5, 2023 · 2 comments
Closed

properties order are not respected #105

Gastonite opened this issue Aug 5, 2023 · 2 comments

Comments

@Gastonite
Copy link

Gastonite commented Aug 5, 2023

First of all, thank you for this very useful library =)

I'm looking to apply CSS rules in a certain order, but it seems that the properties are alphabetically ordered, resulting in CSS whose properties don't follow the expected order.

For example, if I set the 'borderColor' property first, and then the 'borderBottomColor' property, I was expecting the most specific property to be set last, so as to override the most generic one.

Since the properties are ordered alphabetically, this does not produce the expected result:

var insertCss = require("insert-css");
var FreeStyle = require("free-style");

var Style = FreeStyle.create();

var buttonStyle = Style.registerStyle({
  $displayName: "button",
  borderStyle: "solid",
  borderColor: "transparent",
  borderBottomColor: "black",
  borderTopColor: "black"
});

function app(targetEl) {
  var btnEl = document.createElement("button");
  btnEl.textContent = "Click me!";
  btnEl.className = buttonStyle;
  targetEl.appendChild(btnEl);
}

insertCss(Style.getStyles());

app(document.body);

I have created a Codesandbox example, where I was expecting the bottom border to be black, but it is not

@blakeembrey
Copy link
Owner

Thanks for the report, it's a good call, I didn't think about this possibility when I first wrote it. I'd be happy to accept a PR that removes sorting of properties. It'd slightly affect CSS output size, but I think that's a reasonable trade-off when most of the time the property order is probably hard-coded anyway.

@blakeembrey
Copy link
Owner

Changed in the latest major release.

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

2 participants