Skip to content

Commit

Permalink
fix(material/stepper): two-way binding for selectedIndex
Browse files Browse the repository at this point in the history
adds two-way binding for selectedIndex, previously stepper had selectionChange which include selectedIndex & other properties in it

fixes angular#15627
  • Loading branch information
naaajii committed Jun 6, 2023
1 parent 2f992e9 commit 0765bc5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/cdk/stepper/stepper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy {
/** Event emitted when the selected step has changed. */
@Output() readonly selectionChange = new EventEmitter<StepperSelectionEvent>();

/** Output to support two-way binding on `[(selectedIndex)]` */
@Output() readonly selectedIndexChange: EventEmitter<number> = new EventEmitter<number>();

/** Used to track unique ID for each stepper component. */
_groupId: number;

Expand Down Expand Up @@ -526,6 +529,7 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy {
: this._keyManager.updateActiveItem(newIndex);

this._selectedIndex = newIndex;
this.selectedIndexChange.emit(this._selectedIndex);
this._stateChanged();
}

Expand Down
3 changes: 2 additions & 1 deletion tools/public_api_guard/cdk/stepper.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,14 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy {
set selected(step: CdkStep | undefined);
get selectedIndex(): number;
set selectedIndex(index: NumberInput);
readonly selectedIndexChange: EventEmitter<number>;
readonly selectionChange: EventEmitter<StepperSelectionEvent>;
_stateChanged(): void;
_stepHeader: QueryList<CdkStepHeader>;
readonly steps: QueryList<CdkStep>;
_steps: QueryList<CdkStep>;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<CdkStepper, "[cdkStepper]", ["cdkStepper"], { "linear": { "alias": "linear"; "required": false; }; "selectedIndex": { "alias": "selectedIndex"; "required": false; }; "selected": { "alias": "selected"; "required": false; }; "orientation": { "alias": "orientation"; "required": false; }; }, { "selectionChange": "selectionChange"; }, ["_steps", "_stepHeader"], never, false, never, false>;
static ɵdir: i0.ɵɵDirectiveDeclaration<CdkStepper, "[cdkStepper]", ["cdkStepper"], { "linear": { "alias": "linear"; "required": false; }; "selectedIndex": { "alias": "selectedIndex"; "required": false; }; "selected": { "alias": "selected"; "required": false; }; "orientation": { "alias": "orientation"; "required": false; }; }, { "selectionChange": "selectionChange"; "selectedIndexChange": "selectedIndexChange"; }, ["_steps", "_stepHeader"], never, false, never, false>;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<CdkStepper, [{ optional: true; }, null, null]>;
}
Expand Down

0 comments on commit 0765bc5

Please sign in to comment.