-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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(menu): add setSelectedIndex to set selected item in menu selection group #4620
Conversation
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.
Looks good overall. Added few more comments.
@@ -0,0 +1,165 @@ | |||
<!DOCTYPE html> | |||
<!-- | |||
Copyright 2018 Google Inc. |
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.
2019*
Codecov Report
@@ Coverage Diff @@
## develop #4620 +/- ##
==========================================
Coverage ? 98.95%
==========================================
Files ? 129
Lines ? 6297
Branches ? 820
==========================================
Hits ? 6231
Misses ? 65
Partials ? 1
Continue to review full report at Codecov.
|
…material-components/material-components-web into feat/menu/selected-item-selection-group t
🤖 Beep boop! Screenshot test report 🚦3 screenshots changed from Details |
🤖 Beep boop! Screenshot test report 🚦3 screenshots changed from Details |
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 🎉
Left few more comments mostly minor.
"requires": true, | ||
"lockfileVersion": 1, |
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.
Revert all package-lock.json changes
packages/mdc-menu/foundation.ts
Outdated
this.adapter_.removeAttributeFromElementAtIndex(selectedIndex, strings.ARIA_SELECTED_ATTR); | ||
this.adapter_.removeClassFromElementAtIndex(selectedIndex, cssClasses.MENU_SELECTED_LIST_ITEM); | ||
setSelectedIndex(index: number) { | ||
if (!this.isIndexInRange_(index)) { |
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.
Since this function is validating the index and throws error when index is invalid, let's call this validateIndex_
. The return statement will never be executed with current structure.
this.isIndexValid_(index);
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.
sorry i'm confused. Do you want to call it isIndexValid_
or validateIndex_
?
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'm suggesting, this.validateIndex_()
.
As per current implementation isIndexValid_()
does not always return boolean.
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.
Ah sorry I was confused...current implementation is isIndexInRange_
. I'll change to validateIndex and return boolean.
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.
Sorry for not being clearer. isIndexInRange_
seems perfectly fine if the function is just returning a boolean without any side-effects (i.e., throwing an error).
My earlier comment was that this if condition will never fail, because the method throws JS error instead of returning false
value. (I noticed this in coverage report).
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.
OH - I understood what you meant after I implemented this. I think I changed it correctly. I just need to update tests.
test/screenshot/spec/mdc-menu/classes/menu-selection-group.html
Outdated
Show resolved
Hide resolved
test/screenshot/spec/mdc-menu/classes/multiple-menu-selection-group.html
Outdated
Show resolved
Hide resolved
{times: 0}); | ||
td.verify(mockAdapter.addClassToElementAtIndex(0, cssClasses.MENU_SELECTED_LIST_ITEM), {times: 1}); | ||
try { | ||
foundation.setSelectedIndex(5); |
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'll need to use assertThrow here.
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, updated PR description with BREAKING CHANGE tag, make sure to add this line in your commit message when you hit on that Squash & Merge button. :)
🤖 Beep boop! Screenshot test report 🚦3 screenshots changed from Details |
🤖 Beep boop! Screenshot test report 🚦3 screenshots changed from Details |
This Pr requires #4679 to be merged first |
🤖 Beep boop! Screenshot test report 🚦3 screenshots changed from Details |
…on group (#4620) BREAKING CHANGE: Replaced adapter methods getParentElement, getSelectedElementIndex with getSelectedSiblingOfItemAtIndex, isSelectableItemAtIndex.
…on group (#4620) BREAKING CHANGE: Replaced adapter methods getParentElement, getSelectedElementIndex with getSelectedSiblingOfItemAtIndex, isSelectableItemAtIndex.
…on group (#4620) BREAKING CHANGE: Replaced adapter methods getParentElement, getSelectedElementIndex with getSelectedSiblingOfItemAtIndex, isSelectableItemAtIndex.
…on group (#4620) BREAKING CHANGE: Replaced adapter methods getParentElement, getSelectedElementIndex with getSelectedSiblingOfItemAtIndex, isSelectableItemAtIndex.
fixes #4525
BREAKING CHANGE: Replaced adapter methods
getParentElement
,getSelectedElementIndex
withgetSelectedSiblingOfItemAtIndex
,isSelectableItemAtIndex
.