This repository was archived by the owner on Jan 6, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed
src/lib/core/media-marshaller Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ describe('media-marshaller', () => {
22
22
providers : [ MockMatchMediaProvider ]
23
23
} ) ;
24
24
spyOn ( MediaMarshaller . prototype , 'activate' ) . and . callThrough ( ) ;
25
+ spyOn ( MediaMarshaller . prototype , 'updateStyles' ) . and . callThrough ( ) ;
25
26
} ) ;
26
27
27
28
// Single async inject to save references; which are used in all tests below
@@ -39,6 +40,12 @@ describe('media-marshaller', () => {
39
40
expect ( mediaMarshaller . activate ) . toHaveBeenCalled ( ) ;
40
41
} ) ;
41
42
43
+ it ( 'doesn\'t activate when match-media activates the same breakpoint twice' , ( ) => {
44
+ matchMedia . activate ( 'xs' ) ;
45
+ matchMedia . activate ( 'xs' ) ;
46
+ expect ( mediaMarshaller . updateStyles ) . toHaveBeenCalledTimes ( 1 ) ;
47
+ } ) ;
48
+
42
49
it ( 'should set correct activated breakpoint' , ( ) => {
43
50
matchMedia . activate ( 'lg' ) ;
44
51
expect ( mediaMarshaller . activatedBreakpoint ) . toBe ( 'lg' ) ;
Original file line number Diff line number Diff line change @@ -65,14 +65,17 @@ export class MediaMarshaller {
65
65
*/
66
66
activate ( mc : MediaChange ) {
67
67
const bp : BreakPoint | null = this . findByQuery ( mc . mediaQuery ) ;
68
- if ( mc . matches && bp ) {
69
- this . activatedBreakpoints . push ( bp ) ;
70
- this . activatedBreakpoints . sort ( prioritySort ) ;
71
- } else if ( ! mc . matches && bp ) {
72
- // Remove the breakpoint when it's deactivated
73
- this . activatedBreakpoints . splice ( this . activatedBreakpoints . indexOf ( bp ) , 1 ) ;
68
+ if ( bp ) {
69
+ if ( mc . matches && this . activatedBreakpoints . indexOf ( bp ) === - 1 ) {
70
+ this . activatedBreakpoints . push ( bp ) ;
71
+ this . activatedBreakpoints . sort ( prioritySort ) ;
72
+ this . updateStyles ( ) ;
73
+ } else if ( ! mc . matches && this . activatedBreakpoints . indexOf ( bp ) !== - 1 ) {
74
+ // Remove the breakpoint when it's deactivated
75
+ this . activatedBreakpoints . splice ( this . activatedBreakpoints . indexOf ( bp ) , 1 ) ;
76
+ this . updateStyles ( ) ;
77
+ }
74
78
}
75
- this . updateStyles ( ) ;
76
79
}
77
80
78
81
/**
You can’t perform that action at this time.
0 commit comments