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

Map with breakpoint values that are not in ascending order leads to false negatives in JavaScript #13

Open
polarbirke opened this issue Apr 2, 2021 · 0 comments · May be fixed by #14

Comments

@polarbirke
Copy link
Collaborator

Working as expected:

Given a Sass map like include-media's default

$breakpoints: (
  'phone': 320px,
  'tablet': 768px,
  'desktop': 1024px
);

the correct active state of each CSS breakpoint will be correctly exposed for the current viewport via the content property of the configured element's (default: body) ::after-pseudo-element.

Not working as expected:

Given a more complex Sass map that has breakpoints without a strictly ascending order of values, the active state will not always be exposed correctly to JavaScript.

$breakpoints: (
  'phone': 320px,
  'tablet': 768px,
  'desktop': 1024px,
  'wide-screen': 1440px;
  'hero-switcharound': 1200px 
);

This export plugin generates CSS by looping through the map, so in this case the last generated media query will be @media (min-width: 1200px) { … }. Due to the way the CSS cascade works, the content of the pseudo-element is always set by the last matching media query.

So for viewports bigger than 1200px, content will always contain the JSON string generated for the hero-switcharound breakpoint and the exposed breakpoint active state will always be false for wide-screen – even for viewports bigger than 1440px.

polarbirke added a commit to polarbirke/include-media-export that referenced this issue Apr 2, 2021
Add a map-sort helper and sort breakpoints before exporting JSON
strings in CSS media queries. This default behaviour can be opted-out
from by setting $im-dangerously-use-unsorted-breakpoints.

Add tests for functions and mixins. Split plugin into different files
that can be imported and tested individually. Add a build step to
publish the concatenated plugin file.

Fixes eduardoboucas#13
@polarbirke polarbirke linked a pull request Apr 2, 2021 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant