From ad40a85260afbd417175d52adcfcf6cf899baba1 Mon Sep 17 00:00:00 2001 From: ffriedl89 Date: Tue, 6 Apr 2021 16:09:06 +0000 Subject: [PATCH] fix(context-dialog): Fixes an issue that the default behavior of the context dialog changed to not have a maxWidth assigned anymore. Fixes APM-294683 --- .../context-dialog/README.md | 10 ++++ .../context-dialog/src/context-dialog.spec.ts | 55 ++++++++++++++++++- .../context-dialog/src/context-dialog.ts | 8 ++- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/libs/barista-components/context-dialog/README.md b/libs/barista-components/context-dialog/README.md index 28192a461b..a177943965 100644 --- a/libs/barista-components/context-dialog/README.md +++ b/libs/barista-components/context-dialog/README.md @@ -57,6 +57,16 @@ your own maxWidth, it can be configured using the `DT_CONTEXT_DIALOG_CONFIG` injection token. Only the settings you provide will be overwritten, the others will fall back to the default configuration. +In order to have a context-dialog that has no max-width set please provide a the +`DT_CONTEXT_DIALOG_CONFIG` with the maxWidth property specifically set to +`undefined`. This is necessary to have a defaultValue but still be able to +override it in cases where the user does not want to have a maxWidth assigned to +the overlay. + +```js +[{ provide: DT_CONTEXT_DIALOG_CONFIG, useValue: { maxWidth: undefined } }]; +``` + ## Accessibility Context dialogs should be given a meaningful label via `aria-label` for the open diff --git a/libs/barista-components/context-dialog/src/context-dialog.spec.ts b/libs/barista-components/context-dialog/src/context-dialog.spec.ts index 0608667266..606b26bbda 100644 --- a/libs/barista-components/context-dialog/src/context-dialog.spec.ts +++ b/libs/barista-components/context-dialog/src/context-dialog.spec.ts @@ -47,7 +47,10 @@ import { DT_UI_TEST_CONFIG, DtUiTestConfiguration, } from '@dynatrace/barista-components/core'; -import { DT_CONTEXT_DIALOG_CONFIG } from './context-dialog'; +import { + DT_CONTEXT_DIALOG_CONFIG, + _DT_CONTEXT_DIALOG_DEFAULT_MAX_WIDTH, +} from './context-dialog'; describe('DtContextDialog', () => { let overlayContainer: OverlayContainer; @@ -64,7 +67,10 @@ describe('DtContextDialog', () => { }; // tslint:disable-next-line:no-any - function configureDtContextDialogTestingModule(declarations: any[]): void { + function configureDtContextDialogTestingModule( + declarations: any[], + providers: any[] = [], + ): void { TestBed.configureTestingModule({ imports: [ DtContextDialogModule, @@ -75,6 +81,7 @@ describe('DtContextDialog', () => { providers: [ { provide: DT_UI_TEST_CONFIG, useValue: overlayConfig }, { provide: DT_CONTEXT_DIALOG_CONFIG, useValue: overlayCustomConfig }, + ...providers, ], }).compileComponents(); @@ -396,6 +403,50 @@ describe('DtContextDialog', () => { })); }); }); + + describe('config', () => { + it( + 'should have no maxWidth set if it is explicitly removed from the config', + waitForAsync(() => { + configureDtContextDialogTestingModule( + [BasicContextDialog], + [ + { + provide: DT_CONTEXT_DIALOG_CONFIG, + useValue: { maxWidth: undefined }, + }, + ], + ); + + const fixture = createComponent(BasicContextDialog); + fixture.componentInstance.contextDialog.open(); + fixture.detectChanges(); + const cdkOverlayPane = overlayContainer + .getContainerElement() + .querySelector('.cdk-overlay-pane'); + expect(cdkOverlayPane?.getAttribute('style')).not.toContain( + `max-width: ${_DT_CONTEXT_DIALOG_DEFAULT_MAX_WIDTH}px`, + ); + }), + ); + + it( + 'should have no maxWidth set if it is explicitly removed from the config', + waitForAsync(() => { + configureDtContextDialogTestingModule([BasicContextDialog]); + + const fixture = createComponent(BasicContextDialog); + fixture.componentInstance.contextDialog.open(); + fixture.detectChanges(); + const cdkOverlayPane = overlayContainer + .getContainerElement() + .querySelector('.cdk-overlay-pane'); + expect(cdkOverlayPane?.getAttribute('style')).toContain( + `max-width: ${_DT_CONTEXT_DIALOG_DEFAULT_MAX_WIDTH}px`, + ); + }), + ); + }); }); // ################################### diff --git a/libs/barista-components/context-dialog/src/context-dialog.ts b/libs/barista-components/context-dialog/src/context-dialog.ts index 3571bf454f..5a410c84f2 100644 --- a/libs/barista-components/context-dialog/src/context-dialog.ts +++ b/libs/barista-components/context-dialog/src/context-dialog.ts @@ -111,6 +111,9 @@ export const DT_CONTEXT_DIALOG_CONFIG = new InjectionToken( 'dt-context-dialog-config', ); +/** The default max-width for the context dialogs overlay */ +export const _DT_CONTEXT_DIALOG_DEFAULT_MAX_WIDTH = 328; + @Component({ selector: 'dt-context-dialog', templateUrl: 'context-dialog.html', @@ -308,6 +311,7 @@ export class DtContextDialog scrollStrategy: this._overlay.scrollStrategies.block(), backdropClass: 'cdk-overlay-transparent-backdrop', hasBackdrop: true, + maxWidth: _DT_CONTEXT_DIALOG_DEFAULT_MAX_WIDTH, }; const overlayConfig = this._userConfig @@ -315,8 +319,8 @@ export class DtContextDialog : defaultConfig; const hasFlexibleDimensions = - this._userConfig?.maxWidth === undefined && - this._userConfig?.maxHeight === undefined; + overlayConfig?.maxWidth === undefined && + overlayConfig?.maxHeight === undefined; const positionStrategy = this._overlay .position()