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

CSS Selectors with direction rtl falsely marked as unused #2950

Closed
benjazehr opened this issue Jun 4, 2019 · 3 comments
Closed

CSS Selectors with direction rtl falsely marked as unused #2950

benjazehr opened this issue Jun 4, 2019 · 3 comments

Comments

@benjazehr
Copy link

https://svelte.dev/repl/7c9308930e8e4a3c817a1ba232acae31?version=3.4.4

I want to make my app right-to-left compatible. For this reason I need to add rtl-specific styling, but svelte marks my selectors as unused and removes them:

h1 {
	color: blue;
}
h1[dir="rtl"] {
	color: red;
}

becomes:

h1.svelte-r7z1mq{color:blue}

@sidalidev
Copy link

sidalidev commented Jun 4, 2019

Hi,
Shouldn't you add an rtl like so:

<h1 dir="rtl">Hello {name}!</h1>

To obtain this:

body{direction:rtl}
h1.svelte-r7z1mq{color:blue}
h1[dir="rtl"].svelte-r7z1mq{color:red}

@Conduitry
Copy link
Member

Is dir="rtl" a standard attribute that could be added to any element at any time, without any action on Svelte's part? If so, scoped styles are not the right place for this, as these are intended for styles that Svelte can determine at compile time where they might be applicable. You could wrap your h1 in another element and then for example use the selector .other-element > :global(h1[dir=rtl]) and this will match all instances of h1[dir=rtl] (unscope) directly within (scoped) instances of .other-element.

Or, if the dir attribute is something that you can declaratively control from within Svelte, you can just add a dynamic attribute dir={something} and Svelte will leave in (and scope) the h1[dir=rtl] selector.

@benjazehr
Copy link
Author

benjazehr commented Jun 4, 2019

You were right, sorry for not seeing this. When I add dir="rtl" to the <h1> it works perfectly.

The following selector solved my problems:

:global(html[dir="rtl"] h1) {
    color: red;
}

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

3 participants