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

Snackbar show method should not require message parameter #2628

Closed
memestageceo opened this issue Apr 23, 2018 · 5 comments · Fixed by #4166
Closed

Snackbar show method should not require message parameter #2628

memestageceo opened this issue Apr 23, 2018 · 5 comments · Fixed by #4166
Assignees
Labels

Comments

@memestageceo
Copy link

I am trying to use the snackbar that ships with MDC for web with connect-flash of express. If i simply add the snackbar element like this, it dosn't seem to work

block messages
      if locals.flashes
        - const categories = Object.keys(locals.flashes)
        each category in categories
          each message in flashes[category]
            #mdc-js-snackbar
              .mdc-snackbar(aria-live="assertive", aria-atomic="true" aria-hidden="true")
                .mdc-snackbar__text!= message
                .mdc-snackbar__action-wrapper
                  button.mdc-snackbar__action-button Ok

Also, i've added the JS

import * as mdc from "material-components-web";

function initSnackbars() {
  [].forEach.call(document.querySelectorAll('.mdc-snackbar'), bar => {
    snackbar.MDCSnackbar.attachTo(bar);
    const data = { timeout: 2750 };
    bar.show(data)
  });
}

export default initSnackbars;

The main problem seems to be the message attribute that has to be provided via data obj to snackbar.show(data).
Please, can you give me an example of how I can use mdc-snackbar with connect-flash.

@williamernest
Copy link
Contributor

@aadtyaraj01 Can you give an example of the rendered html? At a glance, it looks like you're missing the message property on your data object. The docs indicate this is required.

@memestageceo
Copy link
Author

@williamernest I cannot figure out how to get that message from express connect-flash to mdc snackbar. I want to use it like the alert in bootstrap to display small notifications like

  • Image Uploaded
  • Comment Added
  • Signed in

@williamernest
Copy link
Contributor

williamernest commented Apr 23, 2018

If you have to store the message in the html you can query the mdc-snackbar__text selector for it.

function initSnackbars() {
  [].forEach.call(document.querySelectorAll('.mdc-snackbar'), barEle => {
    var bar = new snackbar.MDCSnackbar(barEle);
    const data = { timeout: 2750, message: barEle.querySelector('.mdc-snackbar__text').innerText };
    bar.show(data);
  });
}

@memestageceo
Copy link
Author

Thnx...worked like a charm! 😄

@williamernest williamernest reopened this Apr 30, 2018
@williamernest williamernest changed the title MDC web with connect-flash express.js Snackbar show method should not require message parameter Apr 30, 2018
@williamernest
Copy link
Contributor

Re-opening this issue so we can fix the underlying problem, even though the user has a workaround.

The MDCSnackbar requires developers to pass an object into the show method that contains a message parameter. This prevents the user from simply rendering the html with the message parameter already set and just showing the user what is already in the DOM. When the MDCSnackbar.show() method is called without an object, or with an object without a message property, it should show the snackbar to the user.

acdvorak added a commit that referenced this issue Dec 13, 2018
### Issues fixed

* Fixes #4005 (via new `mdc-snackbar-viewport-margin()` mixin)
* Fixes #3981
* Fixes #2916 (via new `MDCSnackbar:closing` and `MDCSnackbar:closed` events)
* Fixes #2628
* Fixes #1466 (via new `close()` method)
* Fixes #1398
* Fixes #1258
* Fixes #11 (the label now expands indefinitely to fit the text)
* Refs #2813

### Screenshots

![Baseline without action button](https://user-images.githubusercontent.com/409245/49956261-a080ca80-feb9-11e8-8287-b7e805344115.png)

![Baseline with action button](https://user-images.githubusercontent.com/409245/49956109-4a138c00-feb9-11e8-9213-3241fa86a1b8.png)

![Stacked layout](https://user-images.githubusercontent.com/409245/49956173-6a434b00-feb9-11e8-8a03-2e58ccc8f763.png)

BREAKING CHANGE: Snackbar's DOM and APIs have changed to match the latest design guidelines. See the Snackbar documentation for more information.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants