-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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(stepper): Support additional properties for step #6509
Conversation
I had to close and reopen the PR for additional properties of step b/c of rebase issues 😢 |
@@ -19,12 +19,12 @@ | |||
</div> | |||
</md-step> | |||
|
|||
<md-step formGroupName="1" [stepControl]="formArray.get([1])"> | |||
<md-step formGroupName="1" [stepControl]="formArray.get([1])" [optional]="true"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can just do optional="true"
also, can you add a optional horizontal step
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just optional
with no expression
src/cdk/stepper/stepper.ts
Outdated
private _optional = false; | ||
|
||
/** Return whether step is completed or not. */ | ||
get completed() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I wonder if this is something we want to give the user control of by making it an @Input()
?
@jelbourn WDYT of something like this:
@Input()
get completed() {
return this._customCompleted == null ? this._defaultCompleted : this._customCompleted;
}
set completed(value) {
this._customCompleted = value == null ? null : coerceBooleanProperty(value);
}
private _customCompleted: boolean | null = null;
private get _defaultCompleted() {
return this._stepControl ? this._stepControl.valid && this.interacted : this.interacted;
}
This way most users could use the default completeness behavior, but they could still override if they want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable, though _defaultCompleted
would be a function
src/cdk/stepper/stepper.ts
Outdated
@@ -211,7 +232,7 @@ export class CdkStepper { | |||
const stepsArray = this._steps.toArray(); | |||
stepsArray[this._selectedIndex].interacted = true; | |||
if (this._linear) { | |||
return stepsArray.slice(0, index).some(step => step.stepControl.invalid); | |||
return stepsArray.slice(0, index).some(step => step.stepControl.invalid && !step.optional); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense if you're thinking about the step being invalid due to a required field not being filled out, but it makes less sense if you consider invalid for other reasons (e.g. entering "1234" as your email).
Need to think more about what the right behavior for optional is...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmalerba Do you mean that if the step is optional but the field is invalid due to some other reason, the user shouldn't be able to move on? If it is optional, shouldn't the user be able to move on even if the input is not valid? The field will still fire an error, so the user will still be aware that the input is invalid as they move on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if its optional they should be able to skip it, not enter invalid input
{{i + 1}} | ||
</div> | ||
<div class="mat-stepper-index-interacted" *ngIf="step.completed && selectedIndex != i"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can simplify this a bit:
get _indicatorType(): 'number' | 'check' | 'edit' {...}
<div class="mat-step-indicator" [ngSwitch]="_indicatorType">
<span *ngSwitchCase="number">{{i + 1}}</span>
<md-icon *ngSwitchCase="check">done</md-icon>
<md-icon *ngSwitchCase="edit">create</md-icon>
</div>
|
||
<div class="mat-stepper-label"> | ||
<div [ngClass]="{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do these as separate [class.xxx]
bindings
src/cdk/stepper/stepper.ts
Outdated
private _optional = false; | ||
|
||
/** Return whether step is completed or not. */ | ||
get completed() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable, though _defaultCompleted
would be a function
@@ -19,12 +19,12 @@ | |||
</div> | |||
</md-step> | |||
|
|||
<md-step formGroupName="1" [stepControl]="formArray.get([1])"> | |||
<md-step formGroupName="1" [stepControl]="formArray.get([1])" [optional]="true"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just optional
with no expression
src/lib/stepper/stepper.spec.ts
Outdated
@@ -457,6 +485,57 @@ function checkStepHeaderBlur(stepHeaderEl: HTMLElement, fixture: ComponentFixtur | |||
expect(stepHeaderEl.blur).toHaveBeenCalled(); | |||
} | |||
|
|||
function checkEditableStep(stepperComponent: MdStepper, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need function descriptions. I'd also prefer to have the functions names start with assert
instead of check
, and potentially making the function names more specific about what they do
{{i + 1}} | ||
</div> | ||
<div class="mat-stepper-index-interacted" *ngIf="step.completed && selectedIndex != i"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we share this icon group between stepper vertical and stepper horizontal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kara Sorry, what do you mean by sharing the icon group? Do you mean like creating a separate icon group component with the template?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I meant an internal directive for the shared functionality. If they have a lot in common, would be easier to update together.
Ready for review again. I also left some follow-up comments 👍 |
Addressed comment regarding shared code between horizontal and vertical stepper. Ready for review 😃 |
src/cdk/stepper/step-icon.ts
Outdated
@Directive({ | ||
selector: 'cdkStepIcon' | ||
}) | ||
export class CdkStepIcon { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs a cdk version, the icon is a material design specific piece of UI
@Directive({ | ||
selector: 'cdkStepLabelContainer' | ||
}) | ||
export class CdkStepLabelContainer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also don't see a need for a cdk version of this
src/cdk/stepper/stepper.ts
Outdated
@@ -211,7 +232,7 @@ export class CdkStepper { | |||
const stepsArray = this._steps.toArray(); | |||
stepsArray[this._selectedIndex].interacted = true; | |||
if (this._linear) { | |||
return stepsArray.slice(0, index).some(step => step.stepControl.invalid); | |||
return stepsArray.slice(0, index).some(step => step.stepControl.invalid && !step.optional); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if its optional they should be able to skip it, not enter invalid input
<!-- It there is no label template, fall back to the text label. --> | ||
<div *ngIf="!step.stepLabel">{{step.label}}</div> | ||
</div> | ||
<md-step-icon [step]="step" [selected]="selectedIndex == i" [index]="i"></md-step-icon> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we not just combine these 2 internal components (and their parent div) into a single md-step-header
component?
Refactoring and optional step logic change done. Ready for review again 👍 |
ecad044
to
b8b5815
Compare
Changes made based on discussion. Ready for another review |
src/lib/stepper/step-header.ts
Outdated
|
||
/** Text label of the given step. */ | ||
@Input() | ||
get label() { return this._label; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just one @Input()
with type MdStepLabel | string
, internally you can then have getters to use in your template:
get _stringLabel(): string | null {
return this.label instanceof MdStepLabel ? null : this.label;
}
get _templateLabel(): MdStepLabel | null {
return this.label instanceof MdStepLabel ? this.label : null;
}
src/lib/stepper/step-header.ts
Outdated
export class MdStepHeader { | ||
/** Unique label ID of step header. */ | ||
@Input() | ||
labelId: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than having these as inputs you can just do it in the parent template:
<mat-step-header [id]="_getLabelId(i)" [attr.aria-controls]="_getContentId(i)" ...></mat-step-header>
<div *ngIf="!step.stepLabel">{{step.label}}</div> | ||
</div> | ||
|
||
<div class="mat-stepper-header" #stepperHeader (click)="step.select()" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can remove this div and get access to the md-step-header
element like this:
@ViewChildren(MdStepHeader, {read: ElementRef}) _stepHeaders;
(and same for horizontal)
.mat-step-text-label { | ||
text-overflow: ellipsis; | ||
overflow: hidden; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$mat-step-header-icon-size: 16px !default;
.mat-step-icon {
display: flex;
align-items: center;
justify-content: center;
}
.mat-step-icon .mat-icon {
font-size: $mat-step-header-icon-size;
height: $mat-step-header-icon-size;
width: $mat-step-header-icon-size;
}
Ready for review again 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a few nits
src/lib/stepper/step-header.ts
Outdated
|
||
/** Label of the given step. */ | ||
@Input() | ||
get label() { return this._label; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: don't need getter/setter for this now
[attr.aria-selected]="selectedIndex == i" | ||
[index]="i" | ||
[icon]="_getIndicatorType(i)" | ||
[label]="step.stepLabel ? step.stepLabel : step.label" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can shorten to step.stepLabel || step.label
[attr.aria-selected]="selectedIndex == i" | ||
[index]="i" | ||
[icon]="_getIndicatorType(i)" | ||
[label]="step.stepLabel ? step.stepLabel : step.label" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: step.stepLabel || step.label
* Additional properties for step * Unit tests * Code changes based on review + test name changes * Refactor code for shared functionality between vertical and horizontal stepper * Refactor md-step-header and md-step-content + optional step change * Simplify code based on review * Changes to step-header based on review * Minor changes
* Additional properties for step * Unit tests * Code changes based on review + test name changes * Refactor code for shared functionality between vertical and horizontal stepper * Refactor md-step-header and md-step-content + optional step change * Simplify code based on review * Changes to step-header based on review * Minor changes
* Additional properties for step * Unit tests * Code changes based on review + test name changes * Refactor code for shared functionality between vertical and horizontal stepper * Refactor md-step-header and md-step-content + optional step change * Simplify code based on review * Changes to step-header based on review * Minor changes
* Additional properties for step * Unit tests * Code changes based on review + test name changes * Refactor code for shared functionality between vertical and horizontal stepper * Refactor md-step-header and md-step-content + optional step change * Simplify code based on review * Changes to step-header based on review * Minor changes
…tepper branch. (#5742) * Prototyping * Further work * Further prototyping * Further prototyping * Further work * Adding event emitters * Adding "selectedIndex" attribute to stepper and working on TemplateOulet. * Prototyping * Further work * Further prototyping * Further prototyping * Further work * Adding event emitters * Template rendering and selectIndex control done. * Work in progress for accessibility * Added functionalities based on the tentative API doc. * Refactor code for cdk-stepper and cdk-step * Add support for templated label * Added support for keyboard events and focus changes for accessibility. * Updated vertical stepper + added comments * Fix package-lock.json * Fix indention * Changes made based on the review * Changes based on review - event properties, selectors, SPACE support, etc. + demo * Add select() for step component + refactor to avoid circular dependency + support cycling using arrow keys * API change based on review * Minor code clean up based on review. * Several name changes, etc based on review * Add to compatibility mode list and refactor to avoid circular dependency feat(stepper): Create stepper button directives to enable adding buttons to stepper (#5951) * Create stepper button directives to enable adding buttons to stepper * Changes made based on review * Minor changes with click handlers Build changes feat(stepper): Add initial styles to stepper based on Material guidelines (#6242) * Add initial styles to stepper based on Material guidelines * Fix flex-shrink and min-width * Changes made based on review * Fix alignment * Margin modifications feat(stepper): Add support for linear stepper (#6116) * Add form controls and custom error state matcher * Modify form controls for stepper-demo and add custom validator * Move custom step validation function so that users can simply import and use * Implement @input() stepControl for each step * Add linear attribute to stepper * Add enabling/disabling linear state of demo feat(stepper): Add animation to stepper (#6361) * Add animation * Implement Angular animation * Clean up unnecessary code * Generalize animation so that vertical and horizontal steppers can use the same function Rebase onto upstream/master feat(stepper): Add unit tests for stepper (#6428) * Add unit tests for stepper * Changes made based on review * More changes based on review feat(stepper): Add support for linear stepper #2 - each step as its own form. (#6117) * Add form control - consider each step as its own form group * Comment edits * Add 'valid' to MdStep for form validation * Add [stepControl] to each step based on merging * Changes based on review Fix focus logic and CSS changes (#6507) feat(stepper): Add documentation for stepper (#6533) * Documentation for stepper * Revision based on review + add accessibility section feat(stepper): Support additional properties for step (#6509) * Additional properties for step * Unit tests * Code changes based on review + test name changes * Refactor code for shared functionality between vertical and horizontal stepper * Refactor md-step-header and md-step-content + optional step change * Simplify code based on review * Changes to step-header based on review * Minor changes Fix host style and demo page (#6592) Revert package.json and package-lock.json Changes made along with BUILD changes in google3 Add typography mixin Changes to address aot compiler failures fix rtl bugs
…tepper branch. (angular#5742) * Prototyping * Further work * Further prototyping * Further prototyping * Further work * Adding event emitters * Adding "selectedIndex" attribute to stepper and working on TemplateOulet. * Prototyping * Further work * Further prototyping * Further prototyping * Further work * Adding event emitters * Template rendering and selectIndex control done. * Work in progress for accessibility * Added functionalities based on the tentative API doc. * Refactor code for cdk-stepper and cdk-step * Add support for templated label * Added support for keyboard events and focus changes for accessibility. * Updated vertical stepper + added comments * Fix package-lock.json * Fix indention * Changes made based on the review * Changes based on review - event properties, selectors, SPACE support, etc. + demo * Add select() for step component + refactor to avoid circular dependency + support cycling using arrow keys * API change based on review * Minor code clean up based on review. * Several name changes, etc based on review * Add to compatibility mode list and refactor to avoid circular dependency feat(stepper): Create stepper button directives to enable adding buttons to stepper (angular#5951) * Create stepper button directives to enable adding buttons to stepper * Changes made based on review * Minor changes with click handlers Build changes feat(stepper): Add initial styles to stepper based on Material guidelines (angular#6242) * Add initial styles to stepper based on Material guidelines * Fix flex-shrink and min-width * Changes made based on review * Fix alignment * Margin modifications feat(stepper): Add support for linear stepper (angular#6116) * Add form controls and custom error state matcher * Modify form controls for stepper-demo and add custom validator * Move custom step validation function so that users can simply import and use * Implement @input() stepControl for each step * Add linear attribute to stepper * Add enabling/disabling linear state of demo feat(stepper): Add animation to stepper (angular#6361) * Add animation * Implement Angular animation * Clean up unnecessary code * Generalize animation so that vertical and horizontal steppers can use the same function Rebase onto upstream/master feat(stepper): Add unit tests for stepper (angular#6428) * Add unit tests for stepper * Changes made based on review * More changes based on review feat(stepper): Add support for linear stepper angular#2 - each step as its own form. (angular#6117) * Add form control - consider each step as its own form group * Comment edits * Add 'valid' to MdStep for form validation * Add [stepControl] to each step based on merging * Changes based on review Fix focus logic and CSS changes (angular#6507) feat(stepper): Add documentation for stepper (angular#6533) * Documentation for stepper * Revision based on review + add accessibility section feat(stepper): Support additional properties for step (angular#6509) * Additional properties for step * Unit tests * Code changes based on review + test name changes * Refactor code for shared functionality between vertical and horizontal stepper * Refactor md-step-header and md-step-content + optional step change * Simplify code based on review * Changes to step-header based on review * Minor changes Fix host style and demo page (angular#6592) Revert package.json and package-lock.json Changes made along with BUILD changes in google3 Add typography mixin Changes to address aot compiler failures fix rtl bugs
…tepper branch. (angular#5742) * Prototyping * Further work * Further prototyping * Further prototyping * Further work * Adding event emitters * Adding "selectedIndex" attribute to stepper and working on TemplateOulet. * Prototyping * Further work * Further prototyping * Further prototyping * Further work * Adding event emitters * Template rendering and selectIndex control done. * Work in progress for accessibility * Added functionalities based on the tentative API doc. * Refactor code for cdk-stepper and cdk-step * Add support for templated label * Added support for keyboard events and focus changes for accessibility. * Updated vertical stepper + added comments * Fix package-lock.json * Fix indention * Changes made based on the review * Changes based on review - event properties, selectors, SPACE support, etc. + demo * Add select() for step component + refactor to avoid circular dependency + support cycling using arrow keys * API change based on review * Minor code clean up based on review. * Several name changes, etc based on review * Add to compatibility mode list and refactor to avoid circular dependency feat(stepper): Create stepper button directives to enable adding buttons to stepper (angular#5951) * Create stepper button directives to enable adding buttons to stepper * Changes made based on review * Minor changes with click handlers Build changes feat(stepper): Add initial styles to stepper based on Material guidelines (angular#6242) * Add initial styles to stepper based on Material guidelines * Fix flex-shrink and min-width * Changes made based on review * Fix alignment * Margin modifications feat(stepper): Add support for linear stepper (angular#6116) * Add form controls and custom error state matcher * Modify form controls for stepper-demo and add custom validator * Move custom step validation function so that users can simply import and use * Implement @input() stepControl for each step * Add linear attribute to stepper * Add enabling/disabling linear state of demo feat(stepper): Add animation to stepper (angular#6361) * Add animation * Implement Angular animation * Clean up unnecessary code * Generalize animation so that vertical and horizontal steppers can use the same function Rebase onto upstream/master feat(stepper): Add unit tests for stepper (angular#6428) * Add unit tests for stepper * Changes made based on review * More changes based on review feat(stepper): Add support for linear stepper angular#2 - each step as its own form. (angular#6117) * Add form control - consider each step as its own form group * Comment edits * Add 'valid' to MdStep for form validation * Add [stepControl] to each step based on merging * Changes based on review Fix focus logic and CSS changes (angular#6507) feat(stepper): Add documentation for stepper (angular#6533) * Documentation for stepper * Revision based on review + add accessibility section feat(stepper): Support additional properties for step (angular#6509) * Additional properties for step * Unit tests * Code changes based on review + test name changes * Refactor code for shared functionality between vertical and horizontal stepper * Refactor md-step-header and md-step-content + optional step change * Simplify code based on review * Changes to step-header based on review * Minor changes Fix host style and demo page (angular#6592) Revert package.json and package-lock.json Changes made along with BUILD changes in google3 Add typography mixin Changes to address aot compiler failures fix rtl bugs
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Add support for
editable
,optional
, andcompleted
properties of each step.