-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Don't crash dropdown menu when selectedIndex is less than 0 #480
Conversation
@@ -48,12 +48,14 @@ var DropDownMenu = React.createClass({ | |||
'mui-open': this.state.open | |||
}); | |||
|
|||
var selectedIndex = this.state.selectedIndex > -1 ? this.state.selectedIndex : 0; |
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 would rather right
var selectedIndex = this.state.selectedIndex;
selectedIndex = (selectedIndex > -1) ? selectedIndex : 0;
for a better optimisation with uglifyjs
Can you include a console warning when users pass a negative index? Negative indices are typically due to poorly written code or bugs. A warning will notify users of the potential error. I would also follow @oliviertassinari's suggestion. Please follow these examples when writing the warning. This PR will be good to go after those two changes are made. |
I've changed it according to your comments. I also moved the check to componentWillReceiveProps, which seems more appropriate than doing this in render. |
Be aware that componentWillReceiveProps is not called for the initial render. |
Fixed IE toString.call() issue.
when receiving props. It will warn when setting it to an invalid value
I've made a separate method that's called on mounting and when receiving props. Merged and pulled and rebased against master... let me know if this is fine :) |
Don't crash dropdown menu when selectedIndex is less than 0
Thanks @jeroencoumans! |
Fixes 'Uncaught TypeError: Cannot read property 'text' of undefined' when passing an index of -1.