simple-login / browser-extension

SimpleLogin Chrome/ Firefox extension
MIT License
185 stars 34 forks source link

Fix "sl-button" CSS class name conflicting with certain websites #179

Closed D-Bao closed 1 year ago

D-Bao commented 1 year ago

The CSS used by the SimpleLogin button in email input fields could create a conflict with the CSS on certain websites using the same CSS class names. I gave unique class names for the SimpleLogin button.

edvincandon commented 1 year ago

maybe you could define a constant somewhere and expose that ?

const CSS_CLASS_PREFIX = "simplelogin-extension"
const slButton = InputTools.newDiv(`${CSS_CLASS_PREFIX}--button`);

/* or even a classname creator ? */
const prefixClassName = (classname) => `${CSS_CLASS_PREFIX}--${classname}`;
const slButton = InputTools.newDiv(prefixClassName("button"));

You can then maybe add a build-step to the css webpack pipeline to prefix classes automatically using that constant ? A combination of postcss-loader & postcss-prefixer could do the trick, it could be nice to setup maybe :

{
    loader: 'postcss-loader',
    options: {
        plugins: [
        require('postcss-prefixer')({
            prefix: 'simplelogin-extension--'
          })
        ]
    }
}

Just a suggestion - I don't know the full-scope of the problem ;)

acasajus commented 1 year ago

@edvincandon's suggestion is really good if we can make it work. This way we can have a really hard prefix to avoid colliions in the web pages but keep a readable code in the extension.

D-Bao commented 1 year ago

Thanks for the suggestion Edvin! However after trying to include postcss into the webpack build step, I decided to not use it for the following reason:

My suggestion would be to use the simple but not so elegant solution of hard coding the css prefix class name for now.

D-Bao commented 1 year ago

(I reverted my previous commit because I think it could be confusing to define a constant in the JS but not the CSS, if we can't automatically have a constant in both the JS and CSS then it's better to have no constant in either file.)