fix(stepper): action label not updated
π Issue
Stepper tab can have custom label for the main action button:
<ht-stepper>
<ht-stepper-tab label="My Tab" actionButtonLabel="Cool Button">
<div> CONTENT </div>
</ht-stepper-tab>
</ht-stepper>
But if we try to update the actionButtonLabel at a later point based on some condition:
<ht-stepper>
<ht-stepper-tab label="My Tab" [actionButtonLabel]="condition ? 'Cool Button' : 'Cancel'">
<div> CONTENT </div>
</ht-stepper-tab>
</ht-stepper>
The change is not getting reflected in the stepper because of the current implementation of the logic which gets the label for the button:
<ht-button [label]="this.getActionButtonLabel | htMemoize : stepper.selectedIndex : steps"></ht-button>
Since we use htMemoize the steps value doesn't change.
βοΈ Fix
Stepper Tab component exposes a refresh$ observable which emits when any input changes. The new logic for getting label for action button is:
// Know when input changed
const stepsInputChange$ = this.steps$.pipe(
switchMap(steps => merge(...steps.map(tab => tab.refresh$))),
startWith(undefined)
);
// Stepper index change
const stepperSelectionChange$ = this.selectionChange.asObservable().pipe(
map(event => event.selectedIndex),
startWith(0)
);
this.actionButtonLabel$ = combineLatest([stepperSelectionChange$, this.steps$, stepsInputChange$]).pipe(
map(([selectedIndex, steps]) => this.getActionButtonLabel(selectedIndex, steps))
);
Unit Test Results
βββββββ4 filesβ Β±0βββββ304 suitesβ Β±0βββ24m 11s :stopwatch: + 1m 34s 1β090 tests Β±0ββ1β090 :heavy_check_mark: Β±0ββ0 :zzz: Β±0ββ0 :x: Β±0β 1β098 runsβ Β±0ββ1β098 :heavy_check_mark: Β±0ββ0 :zzz: Β±0ββ0 :x: Β±0β
Results for commit 6b620f45.βΒ± Comparison against base commit 7313bbe6.