Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 84e811b

Browse files
authored
fix(core): allow for breakpoints with periods in them (#921)
Fixes #776
1 parent 232fc6e commit 84e811b

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

src/lib/core/base/base2.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export abstract class BaseDirective2 implements OnChanges, OnDestroy {
5151
ngOnChanges(changes: SimpleChanges) {
5252
Object.keys(changes).forEach(key => {
5353
if (this.inputs.indexOf(key) !== -1) {
54-
const bp = key.split('.')[1] || '';
54+
const bp = key.split('.').slice(1).join('.');
5555
const val = changes[key].currentValue;
5656
this.setValue(val, bp);
5757
}

src/lib/extended/show-hide/show-hide.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class ShowHideDirective extends BaseDirective2 implements AfterViewInit,
117117
Object.keys(changes).forEach(key => {
118118
if (this.inputs.indexOf(key) !== -1) {
119119
const inputKey = key.split('.');
120-
const bp = inputKey[1] || '';
120+
const bp = inputKey.slice(1).join('.');
121121
const inputValue = changes[key].currentValue;
122122
let shouldShow = inputValue !== '' ?
123123
inputValue !== 0 ? coerceBooleanProperty(inputValue) : false

src/lib/extended/show-hide/show.spec.ts

+21-9
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,20 @@ describe('show directive', () => {
301301
CommonModule,
302302
FlexLayoutModule.withConfig({
303303
serverLoaded: true,
304-
}, {
305-
alias: 'sm-md',
306-
suffix: 'SmMd',
307-
mediaQuery: 'screen and (min-width: 720px) and (max-width: 839px)',
308-
overlapping: false
309-
}),
304+
}, [
305+
{
306+
alias: 'sm-md',
307+
suffix: 'SmMd',
308+
mediaQuery: 'screen and (min-width: 720px) and (max-width: 839px)',
309+
overlapping: false
310+
},
311+
{
312+
alias: 'sm.lg',
313+
suffix: 'SmLg',
314+
mediaQuery: 'screen and (min-width: 840px) and (max-width: 1000px)',
315+
overlapping: false
316+
}
317+
]),
310318
],
311319
declarations: [FxShowHideDirective],
312320
providers: [
@@ -317,7 +325,7 @@ describe('show directive', () => {
317325

318326
it('should respond to custom breakpoint', async(() => {
319327
createTestComponent(`
320-
<p fxFlex="100%" fxHide="true" fxShow.sm-md="true"></p>
328+
<p fxFlex="100%" fxHide="true" fxShow.sm-md="true" fxShow.sm.lg="true"></p>
321329
`);
322330

323331
expectNativeEl(fixture).toHaveStyle({'display': 'none'}, styler);
@@ -329,13 +337,17 @@ describe('show directive', () => {
329337
matchMedia.activate('sm');
330338

331339
expectNativeEl(fixture).toHaveStyle({'display': 'none'}, styler);
340+
341+
matchMedia.activate('sm.lg');
342+
343+
expectNativeEl(fixture).not.toHaveStyle({'display': 'none'}, styler);
332344
}));
333345
});
334346

335347
});
336348

337-
const inputs = ['fxShow.sm-md', 'fxHide.sm-md'];
338-
const selector = `[fxShow.sm-md], [fxHide.sm-md]`;
349+
const inputs = ['fxShow.sm-md', 'fxHide.sm-md', 'fxShow.sm.lg', 'fxHide.sm.lg'];
350+
const selector = `[fxShow.sm-md], [fxHide.sm-md], [fxShow.sm.lg], [fxHide.sm.lg]`;
339351

340352
// Used to test custom breakpoint functionality
341353
@Directive({inputs, selector})

0 commit comments

Comments
 (0)