question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stepper (selectionChange) vs (selectionChanged) and [selectedIndex]

See original GitHub issue

Bug, feature request, or proposal:

    <mat-horizontal-stepper [linear]="false" #stepper 
        [selectedIndex]="this.selectedIndex" 
        (selectionChange)="selectionChange($event)">
      <mat-step [completed]="false" label="First">
        <button mat-button (click)="goto(1)">Next</button>
      </mat-step>
      <mat-step [completed]="false" label="Second">
        <button mat-button (click)="goto(0)">Previous (cancelled)</button>
      </mat-step>
    </mat-horizontal-stepper>

In the stepper control the (selectionChange) event cannot be used together with [selectedIndex], because changing the [selectedIndex] also triggers (selectionChange), so there is no way of cancelling the selection programatically, or implement other logic ‘before’ the change is executed.

Expected it to work as a standard html select control where:

  • when changing the .selectedIndex the (change) event doesn’t get automatically triggered
  • the (change) event is triggered ‘before’ the change is finished, so it can be cancelled with event.preventDefault()

What is the expected behaviour?

  • The current event should be renamed (selectionChanged) = ‘after’ the step has changed.
  • Emit a new event (selectionChange) = ‘before’ the step has changed, with option to cancel the action, which doesn’t get automatically triggered when selectedIndex changes.

What is the current behavior?

selectionChange = ‘after’ the step has changed, naming is confusing, gets triggered automatically with [selectedIndex]

What are the steps to reproduce?

screen shot 2018-02-01 at 12 54 07

  1. Select step 2
  2. Press Previous button (the action is cancelled programatically) - ok
  3. Press step 1 header (step 1 is still selected, the action cannot be cancelled, selectedIndex remains on step 2)

StackBlitz: https://stackblitz.com/edit/angular-material2-issue-9lskal

What is the use-case or motivation for changing an existing behavior?

Be able to programatically enable/disable certain steps

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Material 5.1.0

Is there anything else we should know?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:25
  • Comments:23 (1 by maintainers)

github_iconTop GitHub Comments

18reactions
CarlosBustos1commented, May 5, 2019

Is there any progress on the event ‘beforeSelectionChanged’ ? It would be very usefull

8reactions
ghostcommented, Oct 8, 2020

Any solution for before selection change? I am having same requirement

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Stepper (selectionChange) vs ...
selectedIndex the (change) event doesn't get automatically triggered ; the (change) event is triggered 'before' the change is finished, so it can ...
Read more >
Angular Material selectionChanged returning previous step ...
I have a page consisting of two columns. One contains a vertical stepper and the other one should contain a description ...
Read more >
Angular Mat Stepper Demo With Selection Change - StackBlitz
Starter project for Angular apps that exports to the Angular CLI.
Read more >
Stepper - Angular Material
API reference for Angular Material stepper ... Whether user has seen the expanded step content or not. stepLabel: MatStepLabel ... selectedIndex: number.
Read more >
Switch between vertical and horizontal stepper material ...
you might want to create two separate steppers and use *ngIf to switch ... (selectionChange)="selectionChanged($event)"> <mat-step *ngFor="let step of steps ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found