Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(snack-bar): set snack bar to be responsive #7485

Merged
merged 1 commit into from
Oct 6, 2017

Conversation

josephperrott
Copy link
Member

Fixes #3939

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 3, 2017
@@ -33,6 +33,12 @@ $mat-snack-bar-spacing-margin: 24px !default;
transform: translateY(-100%);
}

&.mobile {
Copy link
Member

@crisbeto crisbeto Oct 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few notes:

  • .mobile seems like something that could clash with user styles. What about calling it mat-snackbar-mobile?
  • Renaming the class will let you avoid the nesting.
  • Is there a particular reason for going with viewport units rather than percent? I have a vague memory about 100vw causing content to go behind the scrollbar on Windows.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, definitely forgot to rename the class after I got it working.

Because the overlay container does not establish itself as the entire width of the viewport, width: 100% turns into the width of the child based on content, so we use 100vw .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. That seems to go behind the scrollbar though. Here's a position: fixed div with a width of 100vw:

https://i.imgur.com/NJUaPFA.png

You might be able to work around it by adding a class to the overlay panel via the panelClass and styling it from there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue that we run into with changing the width of the overlay container, is that the snackbar will always stay in its most expanded state (as limited by max-width)

I will have to continue to investigate

@josephperrott josephperrott force-pushed the snackbar branch 5 times, most recently from 9e75237 to 3ff026c Compare October 6, 2017 00:00
@josephperrott
Copy link
Member Author

@crisbeto Comments addresed. I moved the observation to MatSnackbar, modifying a class in the overlay element with the class effecting styling in both the overlay element and the snackbar container

Feel free to take a look when you have a chance.

@@ -145,6 +148,18 @@ export class MatSnackBar {
// We can't pass this via the injector, because the injector is created earlier.
snackBarRef.instance = contentRef.instance;

// Subscribe to the breakpoint observer and attacg the mat-snack-bar-handset class as
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo :)

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM, some minor feedback.

// appropriate. This class is applied to the overlay element because the overlay must expand to
// fill the width of the screen for full width snackbars.
const isHandset = this._breakpointObserver.observe(Breakpoints.Handset).subscribe(state => {
overlayRef.overlayElement.classList.toggle('mat-snack-bar-handset', state.matches);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second param for classList.toggle doesn't work on IE11. This should use add/remove instead.

});
// Unsubscribe from the isHandset subscription when the overlay is detached from the view.
const overlayDetach = overlayRef.detachments().subscribe(() => {
overlayDetach.unsubscribe();
Copy link
Member

@crisbeto crisbeto Oct 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A cleaner approach could be to use takeUntil. E.g.

this._breakpointObserver.observe(Breakpoints.Handset)
  .takeUntil(overlayRef.detachments().first())
  .subscribe(() => ...);

This way you don't have to keep track of subscriptions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// appropriate. This class is applied to the overlay element because the overlay must expand to
// fill the width of the screen for full width snackbars.
RxChain.from(this._breakpointObserver.observe(Breakpoints.Handset))
.call(takeUntil, RxChain.from(overlayRef.detachments()).call(first).result())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a single operator you don't really need the RxChain, you can just .call it directly. E.g. first.call(overlayRef.detachments()).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did find that frustrating to have it in RxChain again, not sure why I didn't think to look at calling it this way.

@crisbeto crisbeto added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Oct 6, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
@josephperrott josephperrott deleted the snackbar branch March 20, 2020 22:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Material Snackbar Does Not Expand to Width of Viewport on Mobile Devices
5 participants