Skip to content

fix(stepper): throw when out-of-bounds value is assigned to selectedIndex #9127

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

Merged
merged 1 commit into from
Jan 26, 2018

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Dec 26, 2017

Throws better error when an out-of-bounds value is assigned to the selectedIndex.

@crisbeto crisbeto requested a review from mmalerba as a code owner December 26, 2017 08:59
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 26, 2017
@mmalerba
Copy link
Contributor

Shouldn't we actually throw an error in this case? That way the user knows what they're doing wrong rather than trying to track down strange behavior. Maybe just throw a custom error instead of whatever is thrown now that explains better?

@crisbeto
Copy link
Member Author

That also makes sense, but I went with this approach, because it’s consistent with what we do in the tabs.

@mmalerba mmalerba requested a review from andrewseguin January 8, 2018 18:15
@mmalerba
Copy link
Contributor

mmalerba commented Jan 8, 2018

@andrewseguin do you think the tabs behavior should change or this should match what tabs currently does?

@andrewseguin
Copy link
Contributor

As a developer I'd probably want to see an error rather than the component fixing itself. I think though that this fix is in favor of the end-user who runs across an edge case where the developer made a mistake.

I vote for changing both tabs and this to throw an error and be clear to the developer that their logic isn't right

@crisbeto crisbeto force-pushed the stepper-out-of-bounds-index branch from 797366a to 38db85b Compare January 19, 2018 20:34
@crisbeto crisbeto changed the title fix(stepper): handle out-of-bounds value being assigned to the selectedIndex fix(stepper): throw when out-of-bounds value is assigned to selectedIndex Jan 19, 2018
@crisbeto
Copy link
Member Author

Switched it to throw an error @mmalerba @andrewseguin.

…ndex

Throws better error when an out-of-bounds value is assigned to the `selectedIndex`.
@crisbeto crisbeto force-pushed the stepper-out-of-bounds-index branch from 38db85b to ef9c8f4 Compare January 19, 2018 21:05
@crisbeto
Copy link
Member Author

@andrewseguin I'm looking at adding similar changes to the tabs and there's a case that we didn't consider: the tabs/steps could be added asynchronously in which case the consumer starts getting into race conditions instead of having the component default to zero.

@andrewseguin
Copy link
Contributor

Hmm that's an interesting point, so we expect that the selected index stays as out of bounds in case the steps/tabs are updated later?

@crisbeto
Copy link
Member Author

crisbeto commented Jan 23, 2018

No, it's more like we set it to zero when it's out of bounds, rather than throw an error, because we can't know whether any new elements are going to come in. @andrewseguin

@andrewseguin
Copy link
Contributor

In that case, should we expect the developer to still be accurate and change the selectedIndex when the async call is complete, and otherwise keep it at 0?

@crisbeto
Copy link
Member Author

I suppose, but that ends up being a lot more inconvenient.

@andrewseguin andrewseguin added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Jan 26, 2018
@andrewseguin
Copy link
Contributor

Probably needs more discussion but this is fine if you want this behavior for now

@jelbourn jelbourn merged commit f54377c into angular:master Jan 26, 2018
@jelbourn jelbourn added the target: patch This PR is targeted for the next patch release label Jan 29, 2018
@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 8, 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 target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants