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(tab): Emit selection and activation events #3139

Merged
merged 6 commits into from
Jul 18, 2018

Conversation

patrickrodee
Copy link
Contributor

@patrickrodee patrickrodee commented Jul 18, 2018

Add notifySelected and notifyActivated methods to adapter. Add handleClick to the foundation. Update tests and demo. Update readme. Closes #3123

Copy link
Contributor

@acdvorak acdvorak left a comment

Choose a reason for hiding this comment

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

LGTM!

td.verify(mockAdapter.notifySelected(), {times: 1});
});

test('on click, do nothing if the Tab is already active', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this basically doing the same thing as 2 tests up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but ensures we get 100% coverage.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we just be verifying that handleClick is called here, then let the test above verify the rest?

@@ -114,12 +114,15 @@ Method Signature | Description
`getOffsetWidth() => number` | Returns the `offsetWidth` value of the root element
`getContentOffsetLeft() => number` | Returns the `offsetLeft` value of the content element
`getContentOffsetWidth() => number` | Returns the `offsetWidth` value of the content element
`notifySelected() => void` | Emits the `MDCTab:selected` event
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any other word we can use for this event? Like notifyInteracted or something?

My problem with "selected" is that it overlaps with another term in the states subsystem... and generally you never mix selected and activated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

notifyInteracted is cool by me. I'll update.

Copy link
Contributor

@kfranqueiro kfranqueiro left a comment

Choose a reason for hiding this comment

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

We should also add an events section under the component in the README to document the events that are emitted.

e.g. https://github.com/material-components/material-components-web/tree/master/packages/mdc-icon-button#events

@@ -96,6 +96,11 @@ Method Signature | Description
`computeIndicatorClientRect() => ClientRect` | Returns the bounding client rect of the indicator.
`computeDimensions() => MDCTabDimensions` | Returns the dimensions of the Tab.

Event Name | Event Data Structure | Description
--- | --- | ---
`MDCTab:interacted` | `{"detail": {"tab": MDCTab}}` | Emitted when the Tab is interacted with but not active. Used by parent components.
Copy link
Contributor

Choose a reason for hiding this comment

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

I had some initial misunderstanding of when this fires, which I discussed with Pat.

I think this will be clearer to express in the context of Tab if it emits regardless of whether it's active, and update the docs from "but not active" to "regardless of active state".

td.verify(mockAdapter.notifyInteracted(td.matchers.anything()), {times: 0});
});

test('#handleClick emits the selected event if it is not active', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

selected -> interacted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch

demos/tab.html Outdated
@@ -332,10 +332,10 @@ <h2>Customization</h2>
activeTab = tab;
}

tabEl.addEventListener('click', function() {
tabEl.addEventListener('MDCTab:selected', function(evt) {
Copy link
Contributor

Choose a reason for hiding this comment

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

selected -> interacted (assuming this should still be using this and not activated)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch

@patrickrodee patrickrodee merged commit b8dc57a into feat/tabs/tabs Jul 18, 2018
@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (feat/tabs/tabs@1d51c75). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@                Coverage Diff                @@
##             feat/tabs/tabs    #3139   +/-   ##
=================================================
  Coverage                  ?   98.42%           
=================================================
  Files                     ?      113           
  Lines                     ?     4818           
  Branches                  ?      600           
=================================================
  Hits                      ?     4742           
  Misses                    ?       76           
  Partials                  ?        0
Impacted Files Coverage Δ
packages/mdc-tab/constants.js 100% <ø> (ø)
packages/mdc-tab/foundation.js 100% <100%> (ø)
packages/mdc-tab/index.js 100% <100%> (ø)

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 1d51c75...dad0619. Read the comment docs.

kfranqueiro pushed a commit that referenced this pull request Jul 27, 2018
WIP fixed bg coloring of icons

fix(tab-indicator): Use absolute positioning (#2547)

WIP start of tab scroller

WIP fixed transition duration

WIP progress on scroller

WIP added demos back

chore(tabs): Removed tab scroller

feat(tabs): Add tab indicator inside tab (#2565)

feat(tab-scroller): Add tab scroller (#2577)

Merge master into feat/tabs/tabs (#3096)

feat(tab): Update tab color and typography (#3108)

docs(tabs): Update metadata and synopses (#3117)

feat(tab): Add MDCTabDimensions computation (#3122)

feat(tab): Emit selection and activation events (#3139)

docs(tabs): Update new READMEs to match standard (#3142)

feat(tab): Give focus to tab when activated (#3164)

feat(tab): Add mixin for parent positioning; Use mixin in tab scroller (#3179)

fix(tabs): Suppress area occupied by scrollbar on platforms that show it (#3149)

fix(tab): Remove extraneous padding from the stacked text label in LTR (#3193)

feat(tabs): Add missing docs and create helper util API (#3194)

Merge master into feat/tabs/tabs (#3227)

feat(tab): Update layout; Add fixed-width mixin; Add min-width class (#3220)

fix(tab-scroller): Fix incorrect animation stopping scroll value in RTL (#3237)

feat(tab-scroller): Add scroll content width method for use in tab bar (#3222)

feat(tab): Remove activation event emitting (#3242)

feat(tab-bar): Add tab bar (#3229)
@kfranqueiro kfranqueiro deleted the feat/tabs/tab-emit-selection-event branch August 1, 2018 16:20
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.

6 participants