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

Commit 8390c22

Browse files
committed
fix(dialog): don't clobber md-dialog id
1 parent 7abfddf commit 8390c22

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
@@ -894,7 +894,8 @@ function MdDialogProvider($$interimElementProvider) {
894894

895895
var role = (options.$type === 'alert') ? 'alertdialog' : 'dialog';
896896
var dialogContent = element.find('md-dialog-content');
897-
var dialogContentId = 'dialogContent_' + (element.attr('id') || $mdUtil.nextUid());
897+
var existingDialogId = element.attr('id');
898+
var dialogContentId = 'dialogContent_' + (existingDialogId || $mdUtil.nextUid());
898899

899900
element.attr({
900901
'role': role,
@@ -903,6 +904,10 @@ function MdDialogProvider($$interimElementProvider) {
903904

904905
if (dialogContent.length === 0) {
905906
dialogContent = element;
907+
// If the dialog element already had an ID, don't clobber it.
908+
if (existingDialogId) {
909+
dialogContentId = existingDialogId;
910+
}
906911
}
907912

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

src/components/dialog/dialog.spec.js

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

164+
it('should not clobber the id from `md-dialog` when there is no content', inject(function ($mdDialog, $rootScope, $document) {
165+
jasmine.mockElementFocus(this);
166+
167+
var parent = angular.element('<div>');
168+
169+
$mdDialog.show(
170+
$mdDialog.alert({
171+
template: '<md-dialog id="demoid">' +
172+
'<p>Muppets are the best</p>' +
173+
'</md-dialog>',
174+
parent: parent
175+
})
176+
);
177+
178+
runAnimation();
179+
180+
var dialog = parent.find('md-dialog');
181+
182+
expect(dialog[0].id).toBe('demoid');
183+
}));
184+
164185
it('should apply a prefixed id for `md-dialog-content`', inject(function ($mdDialog, $rootScope, $document) {
165186
jasmine.mockElementFocus(this);
166187

0 commit comments

Comments
 (0)