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(stepper): Address previous comments + add directionality support #6775

Merged
merged 3 commits into from
Sep 6, 2017

Conversation

g1shin
Copy link

@g1shin g1shin commented Aug 31, 2017

Comments that were not addressed in the merging of first stepper PR into master branch are addressed in this PR.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 31, 2017
@mmalerba mmalerba requested a review from crisbeto August 31, 2017 23:00
@mmalerba
Copy link
Contributor

added @crisbeto since many of the comments were his

});
this._selectedIndex = newIndex;
}

_onKeydown(event: KeyboardEvent) {
switch (event.keyCode) {
case RIGHT_ARROW:
if (this._dir && this._dir.value === 'rtl') {
if (this._layoutDirection() === 'rtl') {
this._focusStep((this._focusIndex + this._steps.length - 1) % this._steps.length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since these previous and next expressions are repeated and kind of intimidating it might be nice for readability to create _focusNextStep and _focusPreviousStep methods

@@ -167,6 +169,10 @@ export class CdkStepper {
this._groupId = nextId++;
}

ngAfterContentInit() {
this._stepsArray = this._steps.toArray();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't do this since _steps may update, e.g. when an ngIf changes from true to false

@@ -13,11 +13,12 @@
background-color: mat-color($background, hover);
}

.mat-step-label-active {
.mat-step-label.mat-step-label-active {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I like to put the more specific ones after

@@ -364,30 +421,47 @@ function assertPreviousStepperButtonClick(stepperComponent: MdStepper,
}

/** Asserts that step position is correct for animation. */
function assertCorrectStepPosition(stepperComponent: MdStepper, fixture: ComponentFixture<any>) {
function assertCorrectStepPosition(stepperComponent: MdStepper,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to assertCorrectStepAnimationDirection? I'm not really sure what "position" refers to. Also we can determine the stepper automatically given the fixture and take in a optional direction ('ltr' or 'rtl') rather than a boolean so that we aren't always passing dir === 'rtl'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about automatically getting the stepper from the fixture (in this method and others)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmalerba stepper is obtained from fixture by css query (e.g fixture.debugElement.query(By.css('md-horizontal-stepper')).componentInstance). Since these test functions are used commonly for both horizontal and vertical stepper, the stepper would need to be obtained first based on different test cases and then passed to the function for testing.

It could be possible to pass in a variable that checks to see if it's supposed to be horizontal or vertical stepper component then get the stepper from the fixture accordingly, but I'm not sure if that would be cleaner than how it's currently done.

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM after @mmalerba's feedback is addressed.

@@ -150,7 +152,7 @@ export class CdkStepper {
@Input()
get selected() { return this._steps[this.selectedIndex]; }
set selected(step: CdkStep) {
let index = this._steps.toArray().indexOf(step);
let index = this._stepsArray.indexOf(step);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can inline this assignment: this.selectedIndex = this._stepsArray.indexOf(step).

if (this._linear) {
return stepsArray.slice(0, index).some(step => step.stepControl.invalid);
return this._stepsArray.slice(0, index).some(step => step.stepControl.invalid);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The index here may end up being a negative number (it corresponds to the selectedIndex which is a part of the public API) which will result in the some skipping the last N items of the array (e.g. [1, 2, 3, 4].slice(0, -1) is [1, 2, 3]).

@g1shin
Copy link
Author

g1shin commented Sep 1, 2017

Comments have been addressed. Ready for review again 👍

@g1shin
Copy link
Author

g1shin commented Sep 1, 2017

Modified test functions in stepper.spec.ts. Ready for review now

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mmalerba mmalerba added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Sep 1, 2017
@kara kara removed their assignment Sep 5, 2017
@tinayuangao tinayuangao merged commit c396596 into angular:master Sep 6, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants