-
Notifications
You must be signed in to change notification settings - Fork 109
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
Use CSS range syntax in media queries #1833
Use CSS range syntax in media queries #1833
Conversation
Here's a script you can use to update the snapshots once the #!/bin/bash
for actual in $( find . -name 'actual.html' ); do
expected=${actual/actual/expected};
echo "$actual => $expected"
mv "$actual" "$expected"
done There should probably be something like this added to |
Hello @westonruter I didn't get your above message. Is this for updating PHP unit tests ? |
Yes, the unit test failures are due to the HTML snapshots being out for date now that the media query is updated. So you need to move all the |
@@ -34,27 +34,27 @@ public function data_to_test_od_generate_media_query(): array { | |||
'mobile' => array( | |||
'min_width' => 0, | |||
'max_width' => 320, | |||
'expected' => '(max-width: 320px)', | |||
'expected' => null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this null? It should be unchanged.
), | ||
'mobile_alt' => array( | ||
'min_width' => null, | ||
'max_width' => 320, | ||
'expected' => '(max-width: 320px)', | ||
'expected' => null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same. This should be unchanged, right?
'expected' => '(min-width: 601px)', | ||
'expected' => null, | ||
), | ||
'desktop_alt' => array( | ||
'min_width' => 601, | ||
'max_width' => null, | ||
'expected' => '(min-width: 601px)', | ||
'expected' => null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
Co-authored-by: Weston Ruter <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## trunk #1833 +/- ##
==========================================
+ Coverage 65.82% 65.86% +0.03%
==========================================
Files 88 88
Lines 6865 6873 +8
==========================================
+ Hits 4519 4527 +8
Misses 2346 2346
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
I'm just realizing that this isn't going to solve the potential sub-pixel rendering issue. Look at this diff:
See correction below: #1833 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1833 (comment).
The od_generate_media_query()
function may need to have the semantics of its parameters changed, so that it is understood somehow the passed $minimum_viewport_width
is not inclusive meaning that the viewport can never exactly equal that minimum width but it can be greater than it. In contrast, the $maximum_viewport_width
is inclusive, in that the viewport width can exactly equal the max.
This may end up going down a rabbit hole because the URL Metric Groups have minimum and maximum viewport widths too, so then their semantics would probably need to change as well.
This will take some more thought.
if ( $has_min_width && $has_max_width ) { | ||
$media_attributes = sprintf( '( %dpx < width <= %dpx )', $minimum_viewport_width, $maximum_viewport_width ); | ||
} elseif ( $has_min_width ) { | ||
$media_attributes = sprintf( '(min-width: %dpx)', $minimum_viewport_width ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the new syntax be used?
} elseif ( $has_min_width ) { | ||
$media_attributes = sprintf( '(min-width: %dpx)', $minimum_viewport_width ); | ||
} elseif ( $has_max_width ) { | ||
$media_attributes = sprintf( '(max-width: %dpx)', $maximum_viewport_width ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
Correction: they aren't actually identical in behavior. In the |
Take a look at #1839. |
… feat/use-media-queries-in-range
$style_rules[] = sprintf( | ||
'@media %s { #%s { min-height: %dpx; } }', | ||
od_generate_media_query( $minimum['group']->get_minimum_viewport_width(), $minimum['group']->get_maximum_viewport_width() ), | ||
$style_rule = sprintf( | ||
'#%s { min-height: %dpx; }', | ||
$element_id, | ||
$minimum['height'] | ||
); | ||
|
||
$media_feature = od_generate_media_query( $minimum['group']->get_minimum_viewport_width(), $minimum['group']->get_maximum_viewport_width() ); | ||
if ( null !== $media_feature ) { | ||
$style_rule = sprintf( | ||
'@media %s { %s }', | ||
$media_feature, | ||
$style_rule | ||
); | ||
} | ||
$style_rules[] = $style_rule; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change fixes a bug I noticed which can happen when a site is configured to have zero breakpoints (which is very unlikely). In this case, the return value of od_generate_media_query()
is null
since the minimum is 0
and the maximum is null
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is working well in my testing!
@felixarntz Please take a look when you get a chance. |
Summary
Fixes #1696
Relevant technical choices
Using CSS range syntax helps eliminate frontend issues where windows are sized sub-pixel dimensions.
This converts media queries from
to
The above conversion results in eliminating sub-pixel dimension issues possible between 600px to 601px screen.