How to target phones and tablets on a Lightning component using media queries only?
I've been experimenting with media queries on lightning components and I was surprised with the results. Somehow on Iphones, Ipads and Galaxy phones, it always return the width as 980px making it impossible to target separately phones and tablets.
As an example, if you use the following style for your component, the only way to see your text blue would be re-sizing the browser window on a laptop or desktop but never on a phone or tablet.
.THIS {
color:red;
}
@media screen and (max-width: 979px){
.THIS {
color:blue;
}
}
The framework provides the $Browser global value and the device can be checked. To do that I assume I would have a method on my controller like:
({
checkBrowser: function(component) {
var device = $A.get("$Browser.formFactor");
component.set("v.compClass", device);
}
})
And an attribute named compClass, type String on my component to catch the value.
<ltng:require afterScriptsLoaded = "{!c.checkBrowser}" />
<aura:attribute name="compClass" type="String"/>
<div class="{!v.compClass}"></div>
The problem with the controller approach is that unless I have an event been fired on re-size, it wouldn't change the attribute value when you re-size the computer browser screen.
Anyway, back to my question, how to target phones and tablets on lightning components using media queries only?