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 --selected class to menu items #2084

Merged
merged 10 commits into from
Jan 30, 2018

Conversation

williamernest
Copy link
Contributor

fixes: #2031
related: #536
Adds mdc-list-item--selected class to menu items when rememberSelection is set to true.
Auto-focuses on the last selected item when opened when rememberSelection is set to true.

@codecov-io
Copy link

codecov-io commented Jan 25, 2018

Codecov Report

Merging #2084 into master will decrease coverage by 0.15%.
The diff coverage is 89.58%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2084      +/-   ##
==========================================
- Coverage   99.46%   99.31%   -0.16%     
==========================================
  Files          84       84              
  Lines        3722     3770      +48     
  Branches      480      496      +16     
==========================================
+ Hits         3702     3744      +42     
- Misses         20       26       +6
Impacted Files Coverage Δ
packages/mdc-menu/constants.js 100% <ø> (ø) ⬆️
packages/mdc-menu/foundation.js 99.33% <100%> (+0.07%) ⬆️
packages/mdc-menu/index.js 93.82% <66.66%> (-6.18%) ⬇️
packages/mdc-textfield/foundation.js 98.19% <0%> (-0.6%) ⬇️

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 c928bce...82ed956. Read the comment docs.

@lynnmercier lynnmercier self-requested a review January 25, 2018 18:41
@lynnmercier lynnmercier self-assigned this Jan 25, 2018
@@ -141,6 +141,34 @@ class MDCMenuAdapter {

/** @param {string} height */
setMaxHeight(height) {}

/** @param {number} index */
getOptionAtIndex(index) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

does this return something? It is a getter after all...

@@ -22,6 +22,7 @@ const cssClasses = {
ANIMATING_OPEN: 'mdc-menu--animating-open',
ANIMATING_CLOSED: 'mdc-menu--animating-closed',
LIST_ITEM: 'mdc-list-item',
SELECTED_LIST_ITEM: 'mdc-list-item--selected',
Copy link
Contributor

Choose a reason for hiding this comment

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

you should be able to reference the constants on MDCListFoundation.strings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MDCListFoundation doesn't exist

/** @private {boolean} */
this.rememberSelection_ = false;
/** @private {boolean} */
this.keyDownWithinMenu_ = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

this keeps track of whether the user currently has a keydown interaction happening on the mdc-menu component?

These sorts of fields can be vague...so add a comment about exactly what it is this field represents

/**
* @param {?number} focusIndex
* @private
*/
focusOnOpen_(focusIndex) {
if (focusIndex === null) {
// First, try focusing the menu.
// First focus the last selected item if we're remembering selections and it has been set
Copy link
Contributor

Choose a reason for hiding this comment

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

flip this
"If this instance of MDCMenu remembers selections, and the user has made a selection, then focus the last selected item"

@@ -241,6 +263,9 @@ class MDCMenuFoundation extends MDCFoundation {
const isArrowUp = key === 'ArrowUp' || keyCode === 38;
const isArrowDown = key === 'ArrowDown' || keyCode === 40;
const isSpace = key === 'Space' || keyCode === 32;
const isEnter = key === 'Enter' || keyCode === 13;

this.keyDownWithinMenu_ = isEnter || isSpace;
Copy link
Contributor

Choose a reason for hiding this comment

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

explain whats going on here

this.adapter_.focusItemAtIndex(this.selectedIndex_);
return;
}
// Then, try focusing the menu.
Copy link
Contributor

Choose a reason for hiding this comment

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

You probably dont need this comment.

@@ -297,7 +322,12 @@ class MDCMenuFoundation extends MDCFoundation {
const isEscape = key === 'Escape' || keyCode === 27;

if (isEnter || isSpace) {
this.handlePossibleSelected_(evt);
// If our menu didn't catch the keydown, then the user likely hit the
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no "we" or "our" in comments. The program is the thing running. Try and be specific about which part of the program is doing what action.

For example,

"If MDCMenu does not see a keydown event, then it assumes the user triggered an enter or space event"

Also, how is enter and space NOT a keydown event??

@@ -564,6 +597,38 @@ class MDCMenuFoundation extends MDCFoundation {
isOpen() {
return this.isOpen_;
}

/** @return {?Element} */
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we try NOT to reference HTML Element in our Foundation classes. Maybe this public method is not necessary...

Copy link
Contributor

@lynnmercier lynnmercier left a comment

Choose a reason for hiding this comment

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

LGTM

@williamernest williamernest merged commit 04a6ee6 into master Jan 30, 2018
@williamernest williamernest deleted the feat/menu/add-selected-to-list-items branch January 30, 2018 00:03
trimox added a commit to trimox/angular-mdc-web that referenced this pull request Feb 14, 2018
Change as per material-components-web v0.30.0
reference: material-components/material-components-web#2084

Adds `mdc-list-item--selected` class to menu items when `rememberSelection` is set to `true`.

#### New Public methods
- [x] Add `setRememberSelection(rememberSelection: boolean)`
- [x] Add `getSelectedIndex(): number`
- [x] Add `setSelectedIndex(index): void`
- [x] Add `setMaxHeight(height: number): void`

Closes #618
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MDCMenuFoundation add --selected to list items, so that states code is applied to menu
3 participants