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

Commit f72c781

Browse files
EladBezalelThomasBurleson
authored andcommitted
feat(toast): added toastClass property
- toastClass sets a given class on the `md-toast` element fixes #2878 Closes #8951
1 parent aea5437 commit f72c781

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/components/toast/toast.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ function MdToastDirective($mdToast) {
155155
* <td>`.theme(string)`</td>
156156
* <td>Sets the theme on the toast to the requested theme. Default is `$mdThemingProvider`'s default.</td>
157157
* </tr>
158+
* <tr>
159+
* <td>`.toastClass(string)`</td>
160+
* <td>Sets a class on the toast element</td>
161+
* </tr>
158162
* </tbody>
159163
* </table>
160164
*
@@ -206,6 +210,7 @@ function MdToastDirective($mdToast) {
206210
* Available: any combination of `'bottom'`, `'left'`, `'top'`, `'right'`, `'end'` and `'start'`.
207211
* The properties `'end'` and `'start'` are dynamic and can be used for RTL support.<br/>
208212
* Default combination: `'bottom left'`.
213+
* - `toastClass` - `{string=}`: A class to set on the toast element.
209214
* - `controller` - `{string=}`: The controller to associate with this toast.
210215
* The controller will be injected the local `$mdToast.hide( )`, which is a function
211216
* used to hide the toast.
@@ -267,7 +272,7 @@ function MdToastProvider($$interimElementProvider) {
267272
var activeToastContent;
268273
var $mdToast = $$interimElementProvider('$mdToast')
269274
.setDefaults({
270-
methods: ['position', 'hideDelay', 'capsule', 'parent', 'position' ],
275+
methods: ['position', 'hideDelay', 'capsule', 'parent', 'position', 'toastClass'],
271276
options: toastDefaultOptions
272277
})
273278
.addPreset('simple', {
@@ -326,6 +331,7 @@ function MdToastProvider($$interimElementProvider) {
326331
return {
327332
onShow: onShow,
328333
onRemove: onRemove,
334+
toastClass: '',
329335
position: 'bottom left',
330336
themable: true,
331337
hideDelay: 3000,
@@ -388,10 +394,12 @@ function MdToastProvider($$interimElementProvider) {
388394
}
389395

390396
element.addClass('_md-' + swipe);
397+
391398
$mdUtil.nextTick($mdToast.cancel);
392399
};
393400
options.openClass = toastOpenClass(options.position);
394401

402+
element.addClass(options.toastClass);
395403

396404
// 'top left' -> 'md-top md-left'
397405
options.parent.addClass(options.openClass);

src/components/toast/toast.spec.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('$mdToast service', function() {
2626

2727
describe('simple()', function() {
2828

29-
hasConfigMethods(['content', 'action', 'capsule', 'highlightAction', 'theme']);
29+
hasConfigMethods(['content', 'action', 'capsule', 'highlightAction', 'theme', 'toastClass']);
3030

3131
it('should have `._md` class indicator', inject(function($mdToast, $material) {
3232
var parent = angular.element('<div>');
@@ -121,6 +121,19 @@ describe('$mdToast service', function() {
121121
expect(button).toHaveClass('md-warn');
122122
}));
123123

124+
it('adds the specified class to md-toast when using toastClass', inject(function($mdToast, $material) {
125+
var parent = angular.element('<div>');
126+
127+
$mdToast.show(
128+
$mdToast.simple()
129+
.parent(parent)
130+
.toastClass('test')
131+
);
132+
$material.flushOutstandingAnimations();
133+
134+
expect(parent.find('md-toast').hasClass('test')).toBe(true);
135+
}));
136+
124137
describe('when using custom interpolation symbols', function() {
125138
beforeEach(module(function($interpolateProvider) {
126139
$interpolateProvider.startSymbol('[[').endSymbol(']]');

0 commit comments

Comments
 (0)