Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions goldens/material/bottom-sheet/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class MatBottomSheetConfig<D = any> {
backdropClass?: string;
bindings?: Binding[];
closeOnNavigation?: boolean;
containerClass?: string | string[];
data?: D | null;
direction?: Direction;
disableClose?: boolean;
Expand Down
5 changes: 4 additions & 1 deletion src/material/bottom-sheet/bottom-sheet-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ export class MatBottomSheetConfig<D = any> {
*/
injector?: Injector;

/** Extra CSS classes to be added to the bottom sheet container. */
/** Extra CSS classes to be added to the bottom sheet pane. */
panelClass?: string | string[];

/** Extra CSS classes to be added to the bottom sheet container. */
containerClass?: string | string[];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary, users can get the same result by setting a panelClass and targeting the container under it. E.g. .my-panel-class mat-bottom-sheet-container.


/** Text layout direction for the bottom sheet. */
direction?: Direction;

Expand Down
10 changes: 10 additions & 0 deletions src/material/bottom-sheet/bottom-sheet-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import {
} from '@angular/core';
import {Subscription} from 'rxjs';
import {CdkPortalOutlet} from '@angular/cdk/portal';
import {coerceStringArray} from '@angular/cdk/coercion';
import {_animationsDisabled} from '../core';
import {MatBottomSheetConfig} from './bottom-sheet-config';

const ENTER_ANIMATION = '_mat-bottom-sheet-enter';
const EXIT_ANIMATION = '_mat-bottom-sheet-exit';
Expand Down Expand Up @@ -72,6 +74,14 @@ export class MatBottomSheetContainer extends CdkDialogContainer implements OnDes
super();

const breakpointObserver = inject(BreakpointObserver);
const bottomSheetConfig = this._config as MatBottomSheetConfig;

if (bottomSheetConfig.containerClass) {
const containerClasses = coerceStringArray(bottomSheetConfig.containerClass);
if (containerClasses.length) {
this._elementRef.nativeElement.classList.add(...containerClasses);
}
}

this._breakpointSubscription = breakpointObserver
.observe([Breakpoints.Medium, Breakpoints.Large, Breakpoints.XLarge])
Expand Down
17 changes: 17 additions & 0 deletions src/material/bottom-sheet/bottom-sheet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ describe('MatBottomSheet', () => {
expect(containerElement.getAttribute('aria-modal')).toBe('false');
});

it('should apply the specified container class', () => {
bottomSheet.open(PizzaMsg, {containerClass: 'custom-container-class'});
viewContainerFixture.detectChanges();

const containerElement = overlayContainerElement.querySelector('mat-bottom-sheet-container')!;
expect(containerElement.classList.contains('custom-container-class')).toBe(true);
});

it('should apply multiple container classes', () => {
bottomSheet.open(PizzaMsg, {containerClass: ['custom-class-1', 'custom-class-2']});
viewContainerFixture.detectChanges();

const containerElement = overlayContainerElement.querySelector('mat-bottom-sheet-container')!;
expect(containerElement.classList.contains('custom-class-1')).toBe(true);
expect(containerElement.classList.contains('custom-class-2')).toBe(true);
});

it('should be able to set aria-modal', () => {
bottomSheet.open(PizzaMsg, {
ariaModal: true,
Expand Down
Loading