This repository has been archived by the owner on Jul 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Research: prototype MediaQueryPropertyMixin #36
Comments
One use case that came up recently is vaadin/vaadin-app-layout#129 The problem
Static get mediaQueries()The Combine with custom CSS propertiesWhat if we introduce a "one time custom CSS property" concept? static get mediaQueries() {
return {
touchOptimized: window.getComputedStyle(document.documentElement)
.getPropertyValue('--vaadin-breakpoint-touch').trim() ||
'(max-width: 800px) and (min-height: 500px)';
};
} |
I've gone through all the components and collected media queries we use.
Note: we also use |
Alternative API suggestion by Yuriy: static get properties() {
return {
touchOptimized: {
type: Boolean,
media: '(max-width: 800px) and (min-height: 500px)'
}
};
} Need to check whether this would work with |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Problem
In certain components we apply CSS conditionally based on media queries.
We don't have a unified approach for it, so components handle it differently.
1. JS API
Example:
vaadin-date-picker
with_fullscreenMediaQuery
set from JS which toggles thefullscreen
state attribute onvaadin-date-picker-overlay
.When using this approach, we currently hardcode media query also in CSS (example) which makes overriding it more complex (as it needs to be done in multiple places).
2. CSS API
Example:
vaadin-app-layout
with following CSS custom properties:--vaadin-app-layout-touch-optimized
--vaadin-app-layout-drawer-overlay
Both of these are observed in window
resize
event handler (there is no platform way to observe changes to custom CSS properties so far, see also discussion aboutobservedStyles
).Then those
true
/false
are used to show / hide parts of the DOM and one of them is synced tooverlay
property (which reflects to attribute and is read-only).While this approach lets the user to write their CSS and override the defaults, it still requires boilerplate work for every component and that doesn't sound like a good DX.
Solution proposal
Let's assume we have a mixin with the following API:
Then we declare property with
noAccessor
flag:For each of the properties declared like this, the mixin does the following:
window.matchMedia
and add listener to themediaQueries[prop]
true
andfalse
depending on media querytouch-optimized
This approach (only allow to force the value that is not the default one) is inspired by the way how we handle
dir
attribute inDirMixin
when set by the user to a different value).The text was updated successfully, but these errors were encountered: