Skip to content

Commit 25542fe

Browse files
committed
Document FastBoot fallback
1 parent 9b921a4 commit 25542fe

File tree

1 file changed

+44
-7
lines changed

1 file changed

+44
-7
lines changed

README.md

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ For example, if you put a responsive component into a tight sidebar, it will ali
2727
- [Using multiple modifiers on the same element](#using-multiple-modifiers-on-the-same-element)
2828
- [Using both width and height on the Element Query component](#using-both-width-and-height-on-the-element-query-component)
2929
- [Disabling](#disabling)
30+
- [FastBoot fallback](#fastboot-fallback)
3031
- [Browser support](#browser-support)
3132
- [Alternatives](#alternatives)
3233
- [Comparison](#comparison)
@@ -129,19 +130,16 @@ Concept of sizes
129130

130131
The default sizes scale is:
131132

132-
```
133133
Breakpoints: 0 200px 400px 600px 800px 1000px 1200px 1400px
134134
├─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────>
135135
Sizes: · xxs · xs · s · m · l · xl · xxl · xxxl
136-
```
137136

138137
The left limit of each size range is inclusive, the right limit is non-inclusive.
139138

140139
For example, an element is considered to be of size `m` when its width is `>= 600px` and `< 800px`.
141140

142141
Here's an explicit sizes chart:
143142

144-
```
145143
Breakpoints: 0 200px 400px 600px 800px 1000px 1200px 1400px
146144
├─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────>
147145
Sizes: · xxs · xs · s · m · l · xl · xxl · xxxl
@@ -169,7 +167,6 @@ Here's an explicit sizes chart:
169167
· · · · · · · ·
170168
xxxl ├─────────────────────────────────────────────────────────────────────┤
171169
1400+ ├──────────────────────────────────────────────────────────────────────────>
172-
```
173170

174171

175172

@@ -479,21 +476,61 @@ You can also pass `true` to `@sizesHeight`, which will enable default sizes. The
479476

480477
### Disabling
481478

482-
Pass a truthy value into `isDisabled` (modifier) or `@isDisabled` (component) to disable element query functionality:
479+
Pass a truthy value into `isDisabled` to disable element query functionality:
483480

484-
```
481+
```html
485482
<img
486483
{{element-query @isDisabled=true}}
487484
>
488485
```
489486

490-
```
487+
```html
491488
<ElementQuery
492489
@isDisabled={{true}}
493490
>
494491
</ElementQuery>
495492
```
496493

494+
⚠ This property is intended for debugging purposes or disabling element queries entirely. If you change `isDisabled` to `true` dynamically, element query attributes will freeze in their current state, there is no cleanup.
495+
496+
497+
498+
### FastBoot fallback
499+
500+
Unfortunately, FastBoot does not have information about user's screen size. When a user vistis a FastBoot-driven website, they initially see a page without any `ember-element-query` attributes. When FastBoot rehydrates, element queries kick in. As a result, page layout may suddenly change after the user has already started reading and scrolling, causing frustration.
501+
502+
One workaround is to use [ember-useragent](https://github.com/willviles/ember-useragent). Its `isMobile`, `isTablet` and `isDesktop` boolean properties let you apply defaults. The result is very crude but better than nothing.
503+
504+
Since reusable components can be used in different contexts, it is recommended that you apply the fallback on parent level.
505+
506+
Responsive component:
507+
508+
```html
509+
<div
510+
class="my-component"
511+
{{element-querysizes=(hash small=0 medium=350 large=700)}}
512+
...attributes
513+
>
514+
</div>
515+
```
516+
517+
```css
518+
.my-component { /* */}
519+
.my-component[from-medium] { /* */ }
520+
.my-component[from-large] { /* */ }
521+
```
522+
523+
Parent:
524+
525+
```html
526+
<MyComponent
527+
from-medium={{and this.fastboot.isFastBoot (or this.userAgent.device.isTablet this.userAgent.device.isDesktop)}}
528+
from-large-={{and this.fastboot.isFastBoot this.userAgent.device.isDeskto)}}
529+
/>
530+
```
531+
532+
Unfortunately, this requires the parent to know which attributes are used in component's CSS, since providing all possible attributes would be quite tedious, especially for default sizes, which are numerous.
533+
497534

498535

499536
Browser support

0 commit comments

Comments
 (0)