Skip to content

SnackBarOrigin naming and optional modifier #12072

@kobelobster

Description

@kobelobster
  • This is a v1.x issue (v0.x is no longer maintained).
  • I have searched the issues of this repository and believe that this is not a duplicate.

First of all, I would rename SnackBarOrigin to SnackbarOrigin, so it's in line with all other Snackbar namings.

Secondly, SnackBarOrigin is defined like this

export type SnackBarOrigin = {
  horizontal?: 'left' | 'center' | 'right' | number;
  vertical?: 'top' | 'center' | 'bottom' | number;
};

which indicates that you can define either of them, right? But when you only define horizontal for example, function capitalize(string) { will be called for both horizontal and vertical. Since vertical hasn't been defined, it's undefined, ergo not a string and the error Material-UI: capitalize(string) expects a string argument. is thrown. To fix this, you have to pass both horizontal and vertical as an option.

My suggestion (in addition to the naming) would be to make both of them mandatory, e.g. define it like this

export type SnackBarOrigin = {
  horizontal: 'left' | 'center' | 'right' | number;
  vertical: 'top' | 'center' | 'bottom' | number;
};

or don't call capitzlize for undefined strings.

Your Environment

Tech Version
Material-UI v1.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGreat for first contributions. Enable to learn the contribution process.scope: toastChanges related to the toast.typescript

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions