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

Commit

Permalink
fix(dialog): don't clobber md-dialog id
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn committed Apr 27, 2016
1 parent cd82275 commit f0e6de9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/dialog/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,8 @@ function MdDialogProvider($$interimElementProvider) {

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

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

if (dialogContent.length === 0) {
dialogContent = element;
// If the dialog element already had an ID, don't clobber it.
if (existingDialogId) {
dialogContentId = existingDialogId;
}
}

dialogContent.attr('id', dialogContentId);
Expand Down
21 changes: 21 additions & 0 deletions src/components/dialog/dialog.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,27 @@ describe('$mdDialog', function() {
expect(content.id).toBe('dialogContent_' + dialog[0].id);
}));

it('should not clobber the id from `md-dialog` when there is no content', inject(function ($mdDialog, $rootScope, $document) {
jasmine.mockElementFocus(this);

var parent = angular.element('<div>');

$mdDialog.show(
$mdDialog.alert({
template: '<md-dialog id="demoid">' +
'<p>Muppets are the best</p>' +
'</md-dialog>',
parent: parent
})
);

runAnimation();

var dialog = parent.find('md-dialog');

expect(dialog[0].id).toBe('demoid');
}));

it('should apply a prefixed id for `md-dialog-content`', inject(function ($mdDialog, $rootScope, $document) {
jasmine.mockElementFocus(this);

Expand Down

0 comments on commit f0e6de9

Please sign in to comment.