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(menu): add setSelectedIndex to set selected item in menu selection group #4620

Merged
merged 24 commits into from
May 6, 2019

Conversation

moog16
Copy link
Contributor

@moog16 moog16 commented Apr 17, 2019

fixes #4525

BREAKING CHANGE: Replaced adapter methods getParentElement, getSelectedElementIndex with getSelectedSiblingOfItemAtIndex, isSelectableItemAtIndex.

packages/mdc-menu/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-menu/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-menu/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-menu/foundation.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@abhiomkar abhiomkar left a 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.

packages/mdc-menu/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-menu/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-menu/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-menu/component.ts Outdated Show resolved Hide resolved
packages/mdc-menu/component.ts Show resolved Hide resolved
packages/mdc-menu/component.ts Outdated Show resolved Hide resolved
packages/mdc-menu/foundation.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,165 @@
<!DOCTYPE html>
<!--
Copyright 2018 Google Inc.
Copy link
Collaborator

Choose a reason for hiding this comment

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

2019*

packages/mdc-menu/README.md Outdated Show resolved Hide resolved
packages/mdc-menu/adapter.ts Outdated Show resolved Hide resolved
packages/mdc-menu/component.ts Show resolved Hide resolved
packages/mdc-menu/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-menu/foundation.ts Outdated Show resolved Hide resolved
packages/mdc-menu/foundation.ts Outdated Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Apr 23, 2019

Codecov Report

❗ No coverage uploaded for pull request base (develop@6de4115). Click here to learn what that means.
The diff coverage is 96.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##             develop    #4620   +/-   ##
==========================================
  Coverage           ?   98.95%           
==========================================
  Files              ?      129           
  Lines              ?     6297           
  Branches           ?      820           
==========================================
  Hits               ?     6231           
  Misses             ?       65           
  Partials           ?        1
Impacted Files Coverage Δ
packages/mdc-menu/component.ts 100% <100%> (ø)
packages/mdc-menu/foundation.ts 96.25% <94.73%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6de4115...b0de834. Read the comment docs.

@mdc-web-bot
Copy link
Collaborator

@mdc-web-bot
Copy link
Collaborator

Copy link
Collaborator

@abhiomkar abhiomkar left a 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,
Copy link
Collaborator

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/README.md Outdated Show resolved Hide resolved
this.adapter_.removeAttributeFromElementAtIndex(selectedIndex, strings.ARIA_SELECTED_ATTR);
this.adapter_.removeClassFromElementAtIndex(selectedIndex, cssClasses.MENU_SELECTED_LIST_ITEM);
setSelectedIndex(index: number) {
if (!this.isIndexInRange_(index)) {
Copy link
Collaborator

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);

Copy link
Contributor Author

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_?

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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).

Copy link
Contributor Author

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/unit/mdc-menu/mdc-menu.test.js Show resolved Hide resolved
test/unit/mdc-menu/mdc-menu.test.js Outdated Show resolved Hide resolved
test/unit/mdc-menu/menu.foundation.test.js Outdated Show resolved Hide resolved
test/unit/mdc-menu/menu.foundation.test.js Outdated Show resolved Hide resolved
{times: 0});
td.verify(mockAdapter.addClassToElementAtIndex(0, cssClasses.MENU_SELECTED_LIST_ITEM), {times: 1});
try {
foundation.setSelectedIndex(5);
Copy link
Collaborator

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.

Copy link
Collaborator

@abhiomkar abhiomkar left a 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. :)

@moog16 moog16 changed the base branch from master to develop April 29, 2019 19:12
@mdc-web-bot
Copy link
Collaborator

@mdc-web-bot
Copy link
Collaborator

@abhiomkar abhiomkar changed the title feat(menu): add setSelectedIndex feat(menu): add setSelectedIndex to set selected item in menu selection group May 2, 2019
@moog16
Copy link
Contributor Author

moog16 commented May 6, 2019

This Pr requires #4679 to be merged first

@mdc-web-bot
Copy link
Collaborator

@moog16 moog16 merged commit a031927 into develop May 6, 2019
@moog16 moog16 deleted the feat/menu/selected-item-selection-group branch May 6, 2019 18:33
moog16 pushed a commit that referenced this pull request May 14, 2019
…on group (#4620)

BREAKING CHANGE: Replaced adapter methods getParentElement, getSelectedElementIndex with getSelectedSiblingOfItemAtIndex, isSelectableItemAtIndex.
moog16 pushed a commit that referenced this pull request May 28, 2019
…on group (#4620)

BREAKING CHANGE: Replaced adapter methods getParentElement, getSelectedElementIndex with getSelectedSiblingOfItemAtIndex, isSelectableItemAtIndex.
moog16 pushed a commit that referenced this pull request Jun 3, 2019
…on group (#4620)

BREAKING CHANGE: Replaced adapter methods getParentElement, getSelectedElementIndex with getSelectedSiblingOfItemAtIndex, isSelectableItemAtIndex.
abhiomkar pushed a commit that referenced this pull request Jun 11, 2019
…on group (#4620)

BREAKING CHANGE: Replaced adapter methods getParentElement, getSelectedElementIndex with getSelectedSiblingOfItemAtIndex, isSelectableItemAtIndex.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants