Skip to content

Commit d031e79

Browse files
mhaertwiggithub-actions
authored andcommitted
fix(angular/dialog): return undefined when closing dialog via header button (#2629)
This is done to be consistent with the behavior when clicking `ESCAPE`. Before, an empty string was returned as a dialog result because attribute names alone have an empty string as implicit value. See https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML Closes #2496
1 parent 24144de commit d031e79

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/angular/dialog/dialog-content-directives.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export class _SbbDialogTitleBase implements OnInit, OnDestroy {
176176
<ng-content></ng-content>
177177
@if (_closeEnabled) {
178178
<button
179-
sbb-dialog-close
179+
[sbb-dialog-close]="undefined"
180180
class="sbb-dialog-title-close-button sbb-button-reset-frameless"
181181
[aria-label]="closeAriaLabel"
182182
>

src/angular/dialog/dialog.spec.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,25 @@ describe('SbbDialog', () => {
218218
expect(overlayContainerElement.querySelector('sbb-dialog-container')).toBeNull();
219219
}));
220220

221+
it('should close the dialog with undefined result when closed via header button', fakeAsync(() => {
222+
const dialogRef = dialog.open(ContentElementDialog, { viewContainerRef: testViewContainerRef });
223+
const afterCloseCallback = jasmine.createSpy('afterClose callback');
224+
225+
dialogRef.afterClosed().subscribe(afterCloseCallback);
226+
227+
viewContainerFixture.detectChanges();
228+
const closeButton = overlayContainerElement.querySelector(
229+
'.sbb-dialog-title-close-button',
230+
) as HTMLElement;
231+
closeButton.click();
232+
233+
viewContainerFixture.detectChanges();
234+
flush();
235+
236+
expect(afterCloseCallback).toHaveBeenCalledWith(undefined);
237+
expect(overlayContainerElement.querySelector('sbb-dialog-container')).toBeFalsy();
238+
}));
239+
221240
it('should dispose of dialog if view container is destroyed while animating', fakeAsync(() => {
222241
const dialogRef = dialog.open(PizzaMsg, { viewContainerRef: testViewContainerRef });
223242

@@ -1600,7 +1619,9 @@ describe('SbbDialog', () => {
16001619
}));
16011620

16021621
it('should set the "type" attribute of the close button if not set manually', () => {
1603-
const button = overlayContainerElement.querySelector('button[sbb-dialog-close]')!;
1622+
const button = overlayContainerElement.querySelector(
1623+
'button.sbb-dialog-title-close-button',
1624+
)!;
16041625

16051626
expect(button.getAttribute('type')).toBe('button');
16061627
});

0 commit comments

Comments
 (0)