Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cdk/stepper): allow for orientation to be changed #21940

Merged
merged 1 commit into from
Feb 23, 2021
Merged
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
21 changes: 21 additions & 0 deletions src/cdk/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,17 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy {
/** Used to track unique ID for each stepper component. */
_groupId: number;

// Note that this isn't an `Input` so it doesn't bleed into the Material stepper.
/** Orientation of the stepper. */
get orientation(): StepperOrientation { return this._orientation; }
set orientation(value: StepperOrientation) {
this._updateOrientation(value);
}

/**
* @deprecated To be turned into a private property. Use `orientation` instead.
* @breaking-change 13.0.0
*/
protected _orientation: StepperOrientation = 'horizontal';

constructor(
Expand Down Expand Up @@ -439,6 +450,16 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy {
this._getGuidelineLogic(step, isCurrentStep, state);
}

/** Updates the stepper orientation. */
protected _updateOrientation(value: StepperOrientation) {
// This is a protected method so that `MatSteppter` can hook into it.
this._orientation = value;

if (this._keyManager) {
this._keyManager.withVerticalOrientation(value === 'vertical');
}
}

private _getDefaultIndicatorLogic(step: CdkStep, isCurrentStep: boolean): StepState {
if (step._showError && step.hasError && !isCurrentStep) {
return STEP_STATE.ERROR;
Expand Down
1 change: 1 addition & 0 deletions src/material/stepper/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ng_module(
] + glob(["**/*.html"]),
module_name = "@angular/material/stepper",
deps = [
"//src:dev_mode_types",
"//src/cdk/a11y",
"//src/cdk/bidi",
"//src/cdk/portal",
Expand Down
8 changes: 8 additions & 0 deletions src/material/stepper/stepper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,14 @@ describe('MatStepper', () => {
.every(element => element.classList.contains('mat-focus-indicator'))).toBe(true);
});

it('should throw when trying to change the orientation of a stepper', () => {
const stepperComponent: MatStepper = fixture.debugElement
.query(By.css('mat-vertical-stepper'))!.componentInstance;

expect(() => stepperComponent.orientation = 'horizontal')
.toThrowError('Updating the orientation of a Material stepper is not supported.');
});

});

describe('basic stepper when attempting to set the selected step too early', () => {
Expand Down
6 changes: 6 additions & 0 deletions src/material/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ export class MatStepper extends CdkStepper implements AfterContentInit {
});
}

protected _updateOrientation() {
if ((typeof ngDevMode === 'undefined' || ngDevMode)) {
throw Error('Updating the orientation of a Material stepper is not supported.');
}
}

static ngAcceptInputType_editable: BooleanInput;
static ngAcceptInputType_optional: BooleanInput;
static ngAcceptInputType_completed: BooleanInput;
Expand Down
3 changes: 3 additions & 0 deletions tools/public_api_guard/cdk/stepper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export declare class CdkStepper implements AfterContentInit, AfterViewInit, OnDe
_steps: QueryList<CdkStep>;
get linear(): boolean;
set linear(value: boolean);
get orientation(): StepperOrientation;
set orientation(value: StepperOrientation);
get selected(): CdkStep;
set selected(step: CdkStep);
get selectedIndex(): number;
Expand All @@ -69,6 +71,7 @@ export declare class CdkStepper implements AfterContentInit, AfterViewInit, OnDe
_getStepLabelId(i: number): string;
_onKeydown(event: KeyboardEvent): void;
_stateChanged(): void;
protected _updateOrientation(value: StepperOrientation): void;
next(): void;
ngAfterContentInit(): void;
ngAfterViewInit(): void;
Expand Down
1 change: 1 addition & 0 deletions tools/public_api_guard/material/stepper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export declare class MatStepper extends CdkStepper implements AfterContentInit {
color: ThemePalette;
disableRipple: boolean;
readonly steps: QueryList<MatStep>;
protected _updateOrientation(): void;
ngAfterContentInit(): void;
static ngAcceptInputType_completed: BooleanInput;
static ngAcceptInputType_editable: BooleanInput;
Expand Down