Skip to content

Commit 70bd495

Browse files
committed
fix(bottom-sheet): inject correct directionality in child components
Currently the `MatBottomSheetConfig.direction` property will add the `dir` attribute to the overlay, however that doesn't mean that child components that inject the `Directionality` will be able to pick it up (e.g. sliders, menus etc.). These changes add an extra injection token that'll expose the direction to child components.
1 parent 73bc948 commit 70bd495

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/lib/bottom-sheet/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ng_module(
1313
deps = [
1414
"//src/lib/core",
1515
"//src/cdk/a11y",
16+
"//src/cdk/bidi",
1617
"//src/cdk/overlay",
1718
"//src/cdk/portal",
1819
"//src/cdk/layout",

src/lib/bottom-sheet/bottom-sheet.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ describe('MatBottomSheet', () => {
208208
}));
209209

210210
it('should allow setting the layout direction', () => {
211-
bottomSheet.open(PizzaMsg, { direction: 'rtl' });
211+
bottomSheet.open(PizzaMsg, {direction: 'rtl'});
212212

213213
viewContainerFixture.detectChanges();
214214

@@ -217,6 +217,14 @@ describe('MatBottomSheet', () => {
217217
expect(overlayPane.getAttribute('dir')).toBe('rtl');
218218
});
219219

220+
it('should inject the correct direction in the instantiated component', () => {
221+
const bottomSheetRef = bottomSheet.open(PizzaMsg, {direction: 'rtl'});
222+
223+
viewContainerFixture.detectChanges();
224+
225+
expect(bottomSheetRef.instance.directionality.value).toBe('rtl');
226+
});
227+
220228
it('should be able to set a custom panel class', () => {
221229
bottomSheet.open(PizzaMsg, {
222230
panelClass: 'custom-panel-class',

src/lib/bottom-sheet/bottom-sheet.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {ComponentRef, TemplateRef, Injectable, Injector, Optional, SkipSelf} fro
1212
import {MatBottomSheetConfig, MAT_BOTTOM_SHEET_DATA} from './bottom-sheet-config';
1313
import {MatBottomSheetRef} from './bottom-sheet-ref';
1414
import {MatBottomSheetContainer} from './bottom-sheet-container';
15+
import {of as observableOf} from 'rxjs/observable/of';
16+
import {Directionality} from '@angular/cdk/bidi';
1517

1618
/**
1719
* Service to trigger Material Design bottom sheets.
@@ -144,6 +146,13 @@ export class MatBottomSheet {
144146
injectionTokens.set(MatBottomSheetRef, bottomSheetRef);
145147
injectionTokens.set(MAT_BOTTOM_SHEET_DATA, config.data);
146148

149+
if (!userInjector || !userInjector.get(Directionality, null)) {
150+
injectionTokens.set(Directionality, {
151+
value: config.direction,
152+
change: observableOf()
153+
});
154+
}
155+
147156
return new PortalInjector(userInjector || this._injector, injectionTokens);
148157
}
149158
}

0 commit comments

Comments
 (0)