Snackbar throws error when anchorOrigin value is number #12283
Labels
bug 🐛
Something doesn't work
component: snackbar
This is the name of the generic UI component, not the React module!
good first issue
Great for first contributions. Enable to learn the contribution process.
Expected Behavior
According to the Snackbar docs docs, The
<Snackbar/>
component should be able to accept a number foranchorOrigin.vertical
andanchorOrigin.horizontal
. It should work like the<Popover/>
component.Current Behavior
MUI throws a runtime error if you pass a number:
It's because of this line:
https://github.com/mui-org/material-ui/blob/master/packages/material-ui/src/Snackbar/Snackbar.js#L243
Steps to Reproduce
In this CodeSandbox example, it'll throw a runtime error when you try to open the snackbar.
Here is a similar (working) CodeSandbox example for a popover.
Context
I don't see this issue as a major blocker since consumers of
<Snackbar/>
can always customize the positioning usingclasses
. Also, you can pass a numeric string (e.g."10"
or"10px"
) toanchorOrigin.vertical
andanchorOrigin.horizontal
.I think the most important thing right now is that the docs and the TypeScript definitions should be consistent with the runtime behavior.
Should we update the docs and the TS definitions to indicate that numbers can't be used? If so, I'll definitely submit a PR. Or should we actually implement support for passing numbers to
anchorOrigin
?The text was updated successfully, but these errors were encountered: