Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(toast): improve position handling to better align with docs
Browse files Browse the repository at this point in the history
- position of "" uses documented default positioning
  - "bottom left"
- position of "left" or "right" uses default vertical positioning: "bottom"
- improve JSDoc

Closes #11843.

BREAKING CHANGE: `$mdToast.show()`'s position behavior has been updated to be consistent with the documentation. If you relied on the previously undocumented behavior where it defaulted to `top left` instead of `bottom left`, you will need to update your app.

Change your code from this:

```js
    $mdToast.show(
      $mdToast.simple()
      .textContent('Simple Toast!'))
    .then(...
```

To this:

```js
    $mdToast.show(
      $mdToast.simple()
      .textContent('Simple Toast!')
      .position('top left'))
    .then(...
```
  • Loading branch information
Splaktar committed Jun 29, 2020
1 parent e24d09c commit 96ec741
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
30 changes: 27 additions & 3 deletions src/components/toast/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ function MdToastProvider($$interimElementProvider) {
}
};

/**
* @param {{toast: {actionKey: string=}}=} scope
* @param {JQLite} element
* @param {Object.<string, string>} options
* @return {*}
*/
function onShow(scope, element, options) {
// support deprecated #content method
// TODO remove support for content in 1.2.
Expand Down Expand Up @@ -504,9 +510,24 @@ function MdToastProvider($$interimElementProvider) {
scope.toast.actionKey : undefined);

element.on(SWIPE_EVENTS, options.onSwipe);
element.addClass(isSmScreen ? 'md-bottom' : options.position.split(' ').map(function(pos) {
return 'md-' + pos;
}).join(' '));

var verticalPositionDefined = false;
var positionClasses = options.position.split(' ').map(function (position) {
if (position) {
var className = 'md-' + position;
if (className === 'md-top' || className === 'md-bottom') {
verticalPositionDefined = true;
}
return className;
}
return 'md-bottom';
});
// If only "right" or "left" are defined, default to a vertical position of "bottom"
// as documented.
if (!verticalPositionDefined) {
positionClasses.push('md-bottom');
}
element.addClass(isSmScreen ? 'md-bottom' : positionClasses.join(' '));

if (options.parent) {
options.parent.addClass('md-toast-animating');
Expand Down Expand Up @@ -551,6 +572,9 @@ function MdToastProvider($$interimElementProvider) {
return 'md-toast-open-' + (position.indexOf('top') > -1 ? 'top' : 'bottom');
}

/**
* @param {string} actionKey
*/
function setupActionKeyListener(actionKey) {
/**
* @param {KeyboardEvent} event
Expand Down
2 changes: 1 addition & 1 deletion src/core/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
* Functional equivalent for $element.filter(‘md-bottom-sheet’)
* useful with interimElements where the element and its container are important...
*
* @param {angular.JQLite} element to scan
* @param {JQLite} element to scan
* @param {string} nodeName of node to find (e.g. 'md-dialog')
* @param {boolean=} scanDeep optional flag to allow deep scans; defaults to 'false'.
* @param {boolean=} warnNotFound optional flag to enable log warnings; defaults to false
Expand Down

0 comments on commit 96ec741

Please sign in to comment.