Skip to content

Commit

Permalink
fix(mobile-first): ensure we always fall back to closest layout
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Mar 16, 2016
1 parent a4f4f7f commit 74109e3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
8 changes: 8 additions & 0 deletions addon/services/device/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default Service.extend({
});

bps.forEach((bp, i) => {

Ember.defineProperty(this, `is${capitalize(bp.name)}`, computed('width', function() {
let width = this.get('width');
let next = bps[i + 1];
Expand All @@ -70,6 +71,13 @@ export default Service.extend({
}
return width >= bp.begin;
}));

Ember.defineProperty(this, `isAtLeast${capitalize(bp.name)}`, computed('width', function() {
let width = this.get('width');

return width >= bp.begin;
}));

});
},

Expand Down
6 changes: 3 additions & 3 deletions lib/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var fs = require('fs');
var EOL = require('os').EOL;
var chalk = require('chalk');
var debug = false;
var debug = true;

module.exports = function compile(file, layouts, breakpoints) {
var inputs = [];
Expand Down Expand Up @@ -67,11 +67,11 @@ function orderedLayouts(layouts, breakpoints) {
}

function makeFirstTest(name) {
return '{{#if FlexiLayout.is' + capitalize(name) + '}}';
return '{{#if FlexiLayout.isAtLeast' + capitalize(name) + '}}';
}

function makeMiddleTest(name) {
return '{{else if FlexiLayout.is' + capitalize(name) + '}}';
return '{{else if FlexiLayout.isAtLeast' + capitalize(name) + '}}';
}

function capitalize(str) {
Expand Down
13 changes: 11 additions & 2 deletions tests/acceptance/mobile-first-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ moduleForAcceptance('Acceptance | mobile-first', {
}
});

test('visiting /tests/mobile-first', function(assert) {
visit('/tests/mobile-first');
test('Breakpoints fall back to the closest defined breakpoint', function(assert) {
let { deviceLayout } = assert;
let breakpoints = deviceLayout.get('breakpoints');
let bp = {};

breakpoints.forEach(function(point) {
bp[point.name] = point.begin + 5;
});

visit('/tests/mobile-first');

deviceLayout.set('width', bp.mobile);

andThen(function() {
Expand All @@ -43,6 +45,13 @@ test('visiting /tests/mobile-first', function(assert) {

andThen(() => {
assert.equal(find('h1.layout-test').text(), 'Desktop!', `The layout renders the desktop layout when width is ${bp.desktop}`);
run(() => {
deviceLayout.set('width', bp.huge);
});

andThen(() => {
assert.equal(find('h1.layout-test').text(), 'Desktop!', `The layout renders the desktop layout when width is ${bp.huge}`);
});

});
});
Expand Down

0 comments on commit 74109e3

Please sign in to comment.