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

Commit f0e6de9

Browse files
committed
fix(dialog): don't clobber md-dialog id
1 parent cd82275 commit f0e6de9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/components/dialog/dialog.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,8 @@ function MdDialogProvider($$interimElementProvider) {
896896

897897
var role = (options.$type === 'alert') ? 'alertdialog' : 'dialog';
898898
var dialogContent = element.find('md-dialog-content');
899-
var dialogContentId = 'dialogContent_' + (element.attr('id') || $mdUtil.nextUid());
899+
var existingDialogId = element.attr('id');
900+
var dialogContentId = 'dialogContent_' + (existingDialogId || $mdUtil.nextUid());
900901

901902
element.attr({
902903
'role': role,
@@ -905,6 +906,10 @@ function MdDialogProvider($$interimElementProvider) {
905906

906907
if (dialogContent.length === 0) {
907908
dialogContent = element;
909+
// If the dialog element already had an ID, don't clobber it.
910+
if (existingDialogId) {
911+
dialogContentId = existingDialogId;
912+
}
908913
}
909914

910915
dialogContent.attr('id', dialogContentId);

src/components/dialog/dialog.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,27 @@ describe('$mdDialog', function() {
168168
expect(content.id).toBe('dialogContent_' + dialog[0].id);
169169
}));
170170

171+
it('should not clobber the id from `md-dialog` when there is no content', inject(function ($mdDialog, $rootScope, $document) {
172+
jasmine.mockElementFocus(this);
173+
174+
var parent = angular.element('<div>');
175+
176+
$mdDialog.show(
177+
$mdDialog.alert({
178+
template: '<md-dialog id="demoid">' +
179+
'<p>Muppets are the best</p>' +
180+
'</md-dialog>',
181+
parent: parent
182+
})
183+
);
184+
185+
runAnimation();
186+
187+
var dialog = parent.find('md-dialog');
188+
189+
expect(dialog[0].id).toBe('demoid');
190+
}));
191+
171192
it('should apply a prefixed id for `md-dialog-content`', inject(function ($mdDialog, $rootScope, $document) {
172193
jasmine.mockElementFocus(this);
173194

0 commit comments

Comments
 (0)