-
Notifications
You must be signed in to change notification settings - Fork 771
MediaObserver behaving incorrectly #1283
Comments
I can second this issue. This seems to be an issue whenever the media-query goes from "smaller" to "larger", i.e. xs->sm, sm->md, md->lg |
To add some info: I have been unable to recreate the issue with unit-tests, the following example works fine: it('can observe a size increase from xs to sm', fakeAsync(() => {
mediaController.useOverlaps = true;
let current: MediaChange = new MediaChange(true);
let subscription = mediaObserver.asObservable().subscribe((change: Array<MediaChange>) => {
current = change[0];
});
// Activate mediaQuery associated with 'xs' alias
activateQuery('xs');
expect(current.mediaQuery).toEqual(findMediaQuery('xs'));
activateQuery('sm');
expect(current.mediaQuery).toEqual(findMediaQuery('sm'));
// Un-subscribe
subscription.unsubscribe();
mediaController.clearAll();
})); |
For anyone who need a work-around, it could be something along the lines of: mediaObserver.asObservable()
.pipe(
map(changes => {
const breakpointChanges = changes.filter(change => ['xs', 'sm', 'md', 'lg', 'xl'].includes(change.mqAlias));
if (breakpointChanges.length > 1) {
const lastBreakpointChange = breakpointChanges[breakpointChanges.length - 1];
const lastBreakpointChangeIndex = changes.findIndex(change => change.mqAlias === lastBreakpointChange.mqAlias);
changes = changes.splice(lastBreakpointChangeIndex);
}
return changes;
})
) |
Ref: #1308 |
@lukaspj Can you check to see if the latest nightly version fixes this? |
Actually, I can't reproduce it at all, neither on new nor old version. Idk, but I checked my version of the code out from 19. July and tried to replicate it in Edge, Chrome and Firefox without luck.. Sorry! |
I could reproduce it 2 weeks ago. It was causing an issue when I was going from a full screen browser window to a smaller browser window (displaying as expected) and then back to a full screen window (not displaying at it should, behaving same as the smaller breakpoint activated previously) I may not have time to test today, but I can see if it fixes the issue without your workaround @lukaspj |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report
What is the expected behavior?
MediaObserver
should not returnmatches: true
for bothsm
andxs
at the same time. These are mutually exclusive.What is the current behavior?
MediaObserver
returnsmatches: true
for bothsm
andxs
at the same time.What are the steps to reproduce?
I am printing to the console the different matches. When dragging the screen from
xs
tosm
, you will see the match array contains bothxs
andsm
, also evidenced by it growing from 5 -> 7. Interestingly enough, when dragging the screen fromsm
toxs
, it works as expected.What is the use-case or motivation for changing an existing behavior?
The expected behavior should be the correct behavior.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular 10, Mac OS 10.14.6, Firefox 78.0.1
Is there anything else we should know?
The text was updated successfully, but these errors were encountered: