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

notistack doesn't work well with createGenerateClassName in StylesProvider #389

Open
dhythm opened this issue May 22, 2021 · 6 comments
Open

Comments

@dhythm
Copy link

dhythm commented May 22, 2021

Hello, notistack is a great library. It helps us a lot.
Anyway, I found that notistack styles look broken if I use createGenerateClassName with Material-UI's StylesProvider.

output

margins are gone and the action button cannot be clicked.

Expected Behavior

snackbars have proper margins and enable to click the button.

Current Behavior

The snackbars cannot be clicked and shown closely with the prev/next stackbars.

Steps to Reproduce

  1. Put StylesProvider in Material-ui with generateClassName
  2. Put SnackbarProvider in notistack
  3. enqueue a snackbar
ReactDOM.render(
  <React.StrictMode>
    <StylesProvider
      generateClassName={createGenerateClassName({ seed: "my" })}
    >
      <SnackbarProvider>
        <MuiThemeProvider theme={theme}>
          <App />
        </MuiThemeProvider>
      </SnackbarProvider>
    </StylesProvider>
  </React.StrictMode>,
  document.getElementById("root")
);

Context

It worked well in v0.9.17.
And also it works well in v1.0.9 when I move SnackbarProvider to outside of StylesProvider.

ReactDOM.render(
  <React.StrictMode>
    <SnackbarProvider>
      <StylesProvider
        generateClassName={createGenerateClassName({ seed: "my" })}
      >
        <MuiThemeProvider theme={theme}>
          <App />
        </MuiThemeProvider>
      </StylesProvider>
   </SnackbarProvider>
  </React.StrictMode>,
  document.getElementById("root")
);

Your Environment

Tech Version
Notistack v1.0.9
React 17.0.2
Browser Google Chrome
etc.

Many thanks!

@michael-land
Copy link

michael-land commented May 24, 2021

I'm experiencing the same problem when pass custom jss instance to StyleProvider.

  const cache = React.useMemo(() => createCache({ key: 'BRAND', container: emotionRoot }), []);
  const jss = React.useMemo(() => create({ ...jssPreset(), insertionPoint: elementRoot }), []);

  return (
    <CacheProvider value={cache}>
      <StylesProvider jss={jss} injectFirst>
        <ThemeProvider theme={theme}>
          <SnackbarProvider style={{ pointerEvents: 'all' }}>
            <CssBaseline>
              <GlobalStyles styles={{ b: { fontWeight: 600 }, strong: { fontWeight: 600 } }} />
              <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
            </CssBaseline>
          </SnackbarProvider>
        </ThemeProvider>
      </StylesProvider>
    </CacheProvider>
  );

image

My use case is to render the whole react app under shadow root, i have to insert style tag inside the shadow-root instead of the head.

the trick move SnackbarProvider to outside of StylesProvider DOES NOT work in my case

@michael-land
Copy link

revert to 1.0.5 works. anything important changed between 1.0.5 and 1.09?

@dhythm
Copy link
Author

dhythm commented May 25, 2021

I found a temporary solution by using custom className.

const useCustomStyles = makeStyles((theme) => ({
  "my-MuiCollapse-container": {
    pointerEvents: "all",
    marginTop: "6px",
    marginBottom: "6px",
  }
})

and

    <SnackbarProvider
      ...
      className={`${useCustomStyles()["my-MuiCollapse-container"]}`}
    >
      {children}
    </SnackbarProvider>

The action button can be clicked and snackbars have 6px margin on the top and the bottom.
However, it seems hacky. So, I'm happy if anyone tells me another solutions 🙏

@Romcol
Copy link

Romcol commented Jun 9, 2021

Hello,

I have the same issue as you. I use createGenerateClassName as well.

Putting style={{ pointerEvents: 'all' }} on SnackbarProvider fixes the issue for me, or reverting back to 1.0.6 works as well.

I hope this can be fixed in a future version :)

@timonkbd
Copy link

We are experiencing the same issue. I guess it has something to do with the latest changes to src/SnackbarContainer.tsx (f188d2b). The deterministic class names from Material UI are now hardcoded into the source, so using custom class names via createGenerateClassName() lead to the described behavior:

const collapse = {
container: '& > .MuiCollapse-container',
wrapper: '& > .MuiCollapse-container > .MuiCollapse-wrapper',
};

@TrejGun
Copy link

TrejGun commented Jul 18, 2021

We have the same here

the code is pretty much

<ThemeProvider theme={createTheme()}>
    <SnackbarProvider>
        <CssBaseline />
        <div />
    </SnackbarProvider>
</ThemeProvider>

no createGenerateClassName no custom jss stuff

have to revert to 1.0.6 for now

iamhosseindhv added a commit that referenced this issue Mar 6, 2023
* Add goober

* Use goober for SnackbarContainer

* Use goober from SnackbarContent

* Convert Snackbar component to Typescript

* Add material design content

* Process props and pass to custom snackbar

* No spreading

* Reuse enqueueSnackbar type

* Add WIP migration guide

* Add tslib to devDep

* Remove duplicate eslintrc

* Render SnackbarContainer children

* Default content should forwardRef

* Fix bug with collapse classes

* Don't drop support for `content` prop just yet

* Remove duplicate className

* Use useSnackbar in the basic example

* Update Migration md

* Add links to the right section

* No memo for SnackbarContent

* Bump version to v2

* 2.0.1-alpha.0

* Update typedoc.json

* No imports from outside in index.d.ts

* 2.0.1-alpha.1

* Update typedoc.json

* Ensure CustomSnackbarProps type is accurate

* Use Generics for Variant

* 2.0.1-alpha.2

* Minor

* Add more strict types

* 2.0.1-alpha.3

* Get message from options only

* Move minWidth to snackbar for easier customisation

* Add MIGRATION to npmignore

* Make intellisense happy

* Apply Collapse customisation in SnackbarContainer

* Fix various issues with Container component

* Add default background color

* Add ComponentClasses

* Update typedoc.json

* 2.0.1-alpha.4

* [alpha] Add .bind(this) to method stored in provider state (#397)

* Fix easy linting issues

* Import types from types.ts file

* Fix bind.this

* Fix collapse selectors

* Update package-lock

* 2.0.1-alpha.5

* Fix ts-ignore

* v3.0.0-alpha.1

* Use clickaway component

* Add useForkRef

* Rename class keys

* Use internal svg icon

* Use internal transition components

* Fixes #396 #389 - Do not use css selectors for Collapse component

* Add useCallbackNormaliser

* Update SnackbarProvider types

* Use internal Collapse component

* Add transition utils

* Rename close reason

* Update types

* Remove MUI dependency

* Move transitions into their directory

* Improve transition import paths

* Add react-transition-group types

* Update import paths for ui components

* Add index export

* Move useForkRef

* Move SnackbarContainer

* Update path to SnackbarProvider

* Update possible transition components

* Default to MaterialDesignContent in SnackbarItem

* Move util functions to the relevant file

* Move warning messages to the relevant file

* Remove CloseReason constant

* Improve merge helper function

* Move merger into its own file

* Rename file and update import paths

* Update docs

* Add np as publisher

* Update published main path

* Copy files to dist folder

* Add np

* No github drafter

* Add npm scripts

* Add custom component example

* Update indentation from 4 to 2 spaces

* Add readme

* Add readme with codesandbox button

* Remove react-transition-group dep

* Add internal transition component

* Fix bug with warning logger

* SnackbarItem don't add snackbarid as arg to transition callbacks

* Minor

* Simplify transition logic by removing useCallbackNormaliser

* Update migration guide

* Add `id` to transition props

* Update typedoc

* 3.0.0-alpha.2

* Minor change

* Update link codesandbox example

* Export transitions

* Remove fontFamily stylings

* Update variant types

* Regenerate doc defs

* Move types in one file

* Regenerate docs

* Ignore prettier config

* enforce node engine

* Support react 18

* Remove yolo

* Update np version

* Update docs

* Copy package.json before packing

* Rename lifecycle script

* Add postversion script

* Fix typo

* v3.0.0-alpha.3

* Minor

* Update links to notistack website

* Minor

* Add second custom example

* Add report complete example

* Update report complete example

* Update alpha engine versions (#497)

Co-authored-by: Antti Ahti <[email protected]>

* Update jsdocs

* v3.0.0-alpha.4

* Fixes #495 - FIx all snackbars closing at the same time (#498)

* v3.0.0-alpha.5

* Use a more simple Collapse

* Remove getAutoHeightDuration as a file

* Update eslint config

* Run eslint fix

* Remove ClickAway listener

* Minor

* Convert transition component to TS

* Move TransitionStatus type

* Remove transitions

* Export Transition component

* Update types to export Transition component

* Address ts errors

* Move cp commands to package.json

* Update scripts

* Add test script

* Update np config

* v3.0.0-alpha.6

* Update banner image to be served from docs website

* Add support for displaying Snackbars outside of the component (#499)

* Add support for displaying snackbars outside of the component

* Update README instructions

* Update MIGRATION.md

* Remove withSnackbar HOC (#500)

* Convert JS files to TS

* v3.0.0-alpha.7

* Closes #501 - Remove clickaway from docs

* Fixes #513 - Ensure MUI transitions continue to work (#518)

* Update transition types

* Ensure MUI transitions continue to work

* Update typedocs

* v3.0.0-alpha.8

* Add render function SnackbarProvider

* v3.0.0-alpha.9

* Update typedocs

* v3.0.0-alpha.10

* Closes #521 - Update SnackbarContent to accept ref type

* v3.0.0-alpha.11

* Allow overriding styles of Material Snackbar (#545)

* Pass className down to snackbar content

* Add MuiContent-variant classname

* Export MaterialDesignContent component

* Update typedocs

* Minor

* v3.0.0-alpha.12

* v3.0.0-alpha.13

* Update CHANGELOG.md

* Update README.md

---------

Co-authored-by: Anthony Raymond <[email protected]>
Co-authored-by: Antti Ahti <[email protected]>
Co-authored-by: Antti Ahti <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants