diff --git a/src/components-examples/material/stepper/BUILD.bazel b/src/components-examples/material/stepper/BUILD.bazel index 9a4f5ee72a04..926a0992d9df 100644 --- a/src/components-examples/material/stepper/BUILD.bazel +++ b/src/components-examples/material/stepper/BUILD.bazel @@ -14,6 +14,7 @@ ng_module( ]), module_name = "@angular/components-examples/material/stepper", deps = [ + "//src/cdk/layout", "//src/cdk/stepper", "//src/cdk/testing", "//src/cdk/testing/testbed", @@ -22,6 +23,7 @@ ng_module( "//src/material/input", "//src/material/stepper", "//src/material/stepper/testing", + "@npm//@angular/common", "@npm//@angular/forms", "@npm//@angular/platform-browser", "@npm//@angular/platform-browser-dynamic", diff --git a/src/components-examples/material/stepper/index.ts b/src/components-examples/material/stepper/index.ts index a9017f0310ce..f8ccea00cd41 100644 --- a/src/components-examples/material/stepper/index.ts +++ b/src/components-examples/material/stepper/index.ts @@ -1,5 +1,6 @@ import {NgModule} from '@angular/core'; import {ReactiveFormsModule} from '@angular/forms'; +import {CommonModule} from '@angular/common'; import {MatButtonModule} from '@angular/material/button'; import {MatIconModule} from '@angular/material/icon'; import {MatInputModule} from '@angular/material/input'; @@ -15,6 +16,7 @@ import {StepperStatesExample} from './stepper-states/stepper-states-example'; import {StepperVerticalExample} from './stepper-vertical/stepper-vertical-example'; import {StepperHarnessExample} from './stepper-harness/stepper-harness-example'; import {StepperLazyContentExample} from './stepper-lazy-content/stepper-lazy-content-example'; +import {StepperResponsiveExample} from './stepper-responsive/stepper-responsive-example'; export { StepperEditableExample, @@ -26,6 +28,7 @@ export { StepperStatesExample, StepperVerticalExample, StepperLazyContentExample, + StepperResponsiveExample, }; const EXAMPLES = [ @@ -38,6 +41,7 @@ const EXAMPLES = [ StepperStatesExample, StepperVerticalExample, StepperLazyContentExample, + StepperResponsiveExample, ]; @NgModule({ @@ -47,6 +51,7 @@ const EXAMPLES = [ MatInputModule, MatStepperModule, ReactiveFormsModule, + CommonModule, ], declarations: EXAMPLES, exports: EXAMPLES, diff --git a/src/components-examples/material/stepper/stepper-responsive/stepper-responsive-example.css b/src/components-examples/material/stepper/stepper-responsive/stepper-responsive-example.css new file mode 100644 index 000000000000..03b0505d5346 --- /dev/null +++ b/src/components-examples/material/stepper/stepper-responsive/stepper-responsive-example.css @@ -0,0 +1,7 @@ +.example-stepper { + margin-top: 8px; +} + +.mat-form-field { + margin-top: 16px; +} diff --git a/src/components-examples/material/stepper/stepper-responsive/stepper-responsive-example.html b/src/components-examples/material/stepper/stepper-responsive/stepper-responsive-example.html new file mode 100644 index 000000000000..3db8423dcf64 --- /dev/null +++ b/src/components-examples/material/stepper/stepper-responsive/stepper-responsive-example.html @@ -0,0 +1,52 @@ + +
Make your screen smaller to see a vertical stepper
+
Make your screen larger to see a horizontal stepper
+
+ + + +
+ + Name + + +
+ +
+
+
+ +
+ + Address + + +
+ + +
+
+
+ +
+ + Phone number + + +
+ + +
+
+
+ + Done +

You are now done.

+
+ +
+
+
diff --git a/src/components-examples/material/stepper/stepper-responsive/stepper-responsive-example.ts b/src/components-examples/material/stepper/stepper-responsive/stepper-responsive-example.ts new file mode 100644 index 000000000000..33b6e21acc30 --- /dev/null +++ b/src/components-examples/material/stepper/stepper-responsive/stepper-responsive-example.ts @@ -0,0 +1,32 @@ +import {Component} from '@angular/core'; +import {FormBuilder, Validators} from '@angular/forms'; +import {BreakpointObserver} from '@angular/cdk/layout'; +import {StepperOrientation} from '@angular/material/stepper'; +import {Observable} from 'rxjs'; +import {map} from 'rxjs/operators'; + +/** + * @title Stepper responsive + */ +@Component({ + selector: 'stepper-responsive-example', + templateUrl: 'stepper-responsive-example.html', + styleUrls: ['stepper-responsive-example.css'], +}) +export class StepperResponsiveExample { + firstFormGroup = this._formBuilder.group({ + firstCtrl: ['', Validators.required] + }); + secondFormGroup = this._formBuilder.group({ + secondCtrl: ['', Validators.required] + }); + thirdFormGroup = this._formBuilder.group({ + thirdCtrl: ['', Validators.required] + }); + stepperOrientation: Observable; + + constructor(private _formBuilder: FormBuilder, breakpointObserver: BreakpointObserver) { + this.stepperOrientation = breakpointObserver.observe('(min-width: 800px)') + .pipe(map(({matches}) => matches ? 'horizontal' : 'vertical')); + } +} diff --git a/src/material/stepper/stepper.md b/src/material/stepper/stepper.md index 4e0cf06193a4..466221dc95e8 100644 --- a/src/material/stepper/stepper.md +++ b/src/material/stepper/stepper.md @@ -187,6 +187,13 @@ an `ng-template` with the `matStepContent` attribute. +### Responsive stepper +If your app supports a wide variety of screens and a stepper's layout doesn't fit a particular +screen size, you can control its `orientation` dynamically to change the layout based on the +viewport. + + + ### Keyboard interaction - LEFT_ARROW: Focuses the previous step header - RIGHT_ARROW: Focuses the next step header