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

Trouble with Media Queries #6

Closed
sansarip opened this issue Sep 17, 2019 · 5 comments
Closed

Trouble with Media Queries #6

sansarip opened this issue Sep 17, 2019 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@sansarip
Copy link

I'm not sure if I'm doing something wrong or if there's a bug with the media query implementation.

Here's what I tried:

(defclass test-class []
          (at-media {:min-width "200px"}
                    {:margin-left "10em"})
          {:background-color "blue"
           :margin-left "1em"
           :width "4em"
           :height "4em"})

(defcard
  test
  "Testing media queries"
  (fn []
    (sab/html
      [:div {:class (test-class)}])))

Here's what it results in:

devcard

The classes work perfectly except for media queries. I've tried all manner of things to get media queries to work, but nothing seems to take effect.

Please advise, thanks!

@dhleong
Copy link
Owner

dhleong commented Sep 17, 2019 via email

@sansarip
Copy link
Author

Hey, thanks for the speedy reply!

So as you suggested I reordered the arguments as follows:

(defclass test-class []
          {:background-color "blue"
           :margin-left "1em"
           :width "4em"
           :height "4em"}
          (at-media {:min-width "200px"}
                    {:margin-left "10em"}))

Unfortunately, that did not affect anything visually on the page.

Looking at the generated css it makes sense as to why nothing happened - the media query isn't selecting anything to apply the margin-left attribute to:

.my-website-cards-home-test-class {
  background-color: blue;
  margin-left: 1em;
  width: 4em;
  height: 4em;
}

@media (min-width: 200px) {

  margin-left: 10em;

}

I tried giving the media-query the generated class name:

(defclass test-class []
          {:background-color "blue"
           :margin-left "1em"
           :width "4em"
           :height "4em"}
          (at-media {:min-width "200px"}
                    [".my-website-cards-home-test-class"
                     {:margin-left "10em"}]))

But that resulted in unexpected css - you can see that the class gets selected twice:

.my-website-cards-home-test-class {
  background-color: blue;
  margin-left: 1em;
  width: 4em;
  height: 4em;
}

@media (min-width: 200px) {

  .my-website-cards-home-test-class .my-website-cards-home-test-class {
    margin-left: 10em;
  }

}

If I manually remove one of the duplicate .my-website-cards-home-test-class selectors from the media query via the browser debugger, then it works as expected.

I must be going about this the wrong way or something 😖 ! Please advise.

@dhleong
Copy link
Owner

dhleong commented Sep 17, 2019

Huh. Okay you're right there's definitely a bug. I just fired up the demo and it looks like you should be able to put at-media at the beginning (it does already get ordered after in the generated CSS) but the generated media query is always missing the class name.

Here's a workaround for now:

(defclass test-class []
  (at-media {:min-width "200px"}
     [:& {:margin-left "10em"}])
  {:background-color "blue"
   :margin-left "1em"
   :width "4em"
   :height "4em"})

Thanks for the report by the way!

@dhleong dhleong added the bug Something isn't working label Sep 17, 2019
@dhleong dhleong self-assigned this Sep 17, 2019
@dhleong
Copy link
Owner

dhleong commented Sep 18, 2019

Okay after looking into this, it appears that garden doesn't actually support nesting media queries inside classes just yet. See noprompt/garden#171 for the relevant issue. I may be able to fake it for now by just automatically wrapping the body of an at-media in that [:&] syntax however. I'll play with it a bit

@dhleong
Copy link
Owner

dhleong commented Sep 18, 2019

Released v1.0.2 that fixes this issue. Thanks again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants