Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

feat(top-app-bar): Implement short top app bar #2290

Merged
merged 21 commits into from
Feb 28, 2018

Conversation

williamernest
Copy link
Contributor

Fixes: #2223

@codecov-io
Copy link

codecov-io commented Feb 22, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@a9f9bf2). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2290   +/-   ##
=========================================
  Coverage          ?   99.08%           
=========================================
  Files             ?      100           
  Lines             ?     4046           
  Branches          ?      524           
=========================================
  Hits              ?     4009           
  Misses            ?       37           
  Partials          ?        0
Impacted Files Coverage Δ
packages/mdc-top-app-bar/foundation.js 100% <100%> (ø)
packages/mdc-top-app-bar/constants.js 100% <100%> (ø)
packages/mdc-top-app-bar/util.js 100% <100%> (ø)
packages/mdc-top-app-bar/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 a9f9bf2...1537127. Read the comment docs.

@@ -25,18 +25,29 @@
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<style>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't this in demos/top-app-bar.scss?

@@ -137,6 +201,36 @@
drawer.open = true;
});

var iconSection = document.getElementById('iconSection');
var shortCheckbox = document.getElementById('short');
var oneRightIcon = document.getElementById('no-right-icon');
Copy link
Contributor

Choose a reason for hiding this comment

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

Variable name seems backwards of what this does?


oneRightIcon.addEventListener('change', function() {
if(this.checked) {
iconSection.innerHTML = '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we apply a class to the icon to set its display to none, rather than tweaking innerHTML? This doesn't seem like how we'd want anyone to actually do things.

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 we'd have to change the totalActionItems adapter method to ignore display:none

@@ -95,6 +116,10 @@ Method Signature | Description
`registerNavigationIconInteractionHandler(evtType: string, handler: EventListener) => void` | Registers an event listener on the native navigation icon element for a given event.
`deregisterNavigationIconInteractionHandler(evtType: string, handler: EventListener) => void` | Deregisters an event listener on the native navigation icon element for a given event.
`notifyNavigationIconClicked() => void` | Emits a custom event `MDCTopAppBar:nav` when the navigation icon is clicked.
`registerScrollHandler(handler) => void` | Registers a handler to be called when user scrolls. Our default implementation adds the handler as a listener to the window's `scroll` event.
`deregisterScrollHandler(handler) => void` | Unregisters a handler to be called when user scrolls. Our default implementation removes the handler as a listener to the window's `scroll` event.
`getViewportScrollY() => number` | Gets the number of pixels that the content of body is scrolled upward.
Copy link
Contributor

Choose a reason for hiding this comment

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

"upward" sounds potentially backwards here depending on how you think about it... how about "scrolled from the top of the page"?

`registerScrollHandler(handler) => void` | Registers a handler to be called when user scrolls. Our default implementation adds the handler as a listener to the window's `scroll` event.
`deregisterScrollHandler(handler) => void` | Unregisters a handler to be called when user scrolls. Our default implementation removes the handler as a listener to the window's `scroll` event.
`getViewportScrollY() => number` | Gets the number of pixels that the content of body is scrolled upward.
`totalActionIcons() => number` | Gets the number of action items on the right side of the top app bar.
Copy link
Contributor

Choose a reason for hiding this comment

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

We refer to action items in prose but the API uses the word Icons? Do we ever expect any action items that aren't icons?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Spec refers to them as Action Items but never uses anything other than icons. I'll change all of them to Items for consistency.

@@ -17,9 +17,17 @@
/** @enum {string} */
const strings = {
NAVIGATION_EVENT: 'MDCTopAppBar:nav',
TOPAPPBAR_SELECTOR: '.mdc-top-app-bar',
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to ROOT_SELECTOR (we have ROOT in other constants files for the top-level class)

@@ -36,13 +37,12 @@
position: relative;
box-sizing: border-box;
width: 100%;
height: auto;
min-height: $mdc-top-app-bar-row-height;
height: $mdc-top-app-bar-row-height;
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious why we had height + min-height earlier but now don't need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was brought over from toolbar. I think it was used for flexible toolbars. I'll leave it in so we don't have to change it all when we get the flexible toolbar moved.

$mdc-top-app-bar-short-collapsed-width: 56px;
$mdc-top-app-bar-short-collapsed-right-icon-padding: 12px;

$mdc-top-app-bar-standard-easing: cubic-bezier(.4, 0, .2, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Pretty sure this matches one of the variables in mdc-animation; reuse that instead?

`registerScrollHandler(handler) => void` | Registers a handler to be called when user scrolls. Our default implementation adds the handler as a listener to the window's `scroll` event.
`deregisterScrollHandler(handler) => void` | Unregisters a handler to be called when user scrolls. Our default implementation removes the handler as a listener to the window's `scroll` event.
`getViewportScrollY() => number` | Gets the number of pixels that the content of body is scrolled from the top of the page.
`totalActionIcons() => number` | Gets the number of action items on the right side of the top app bar.
Copy link
Contributor

Choose a reason for hiding this comment

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

Update to totalActionItems

appBar.destroy();
appBar = mdc.topAppBar.MDCTopAppBar.attachTo(appBarEl);

if(!this.checked){
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing spaces around parens here and L208

});

shortCheckbox.addEventListener('change', function() {
this.checked ? appBarEl.classList.add('mdc-top-app-bar--short') : appBarEl.classList.remove('mdc-top-app-bar--short');
Copy link
Contributor

Choose a reason for hiding this comment

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

appBarEl.classList[this.checked ? 'add' : 'remove'](...);

(It's awkward to use a ternary for an entire statement.)

margin: 0;
box-sizing: border-box;
}
.demo-main {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add newline above this line

@@ -15,6 +15,7 @@
//

@import "@material/theme/variables"; // for mdc-theme-accessible-ink-color
@import "@material/animation/variables";
Copy link
Contributor

Choose a reason for hiding this comment

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

Alphabetize these - move this and ripple above theme

/** @enum {string} */
const cssClasses = {
SHORT_CLASS: 'mdc-top-app-bar--short',
RIGHT_ACTION_ITEM_CLASS: 'mdc-top-app-bar--short__right-action-item',
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the meaning behind "right" action item, anyway? This term is probably a misnomer in RTL context so I'm wondering if there's something more semantic/agnostic we could use.

registerScrollHandler: (/* handler: EventListener */) => {},
deregisterScrollHandler: (/* handler: EventListener */) => {},
getViewportScrollY: () => /* number */ 0,
totalActionItems: () => /* number */ 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I realized this late, but this probably deserves to be called getTotalActionItems (verbs in function names are good)

@williamernest williamernest force-pushed the feat/top-app-bar/add-short-top-app-bar branch from 6fd2e5e to a9f1749 Compare February 23, 2018 22:57
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.

The collapsed bar seems to have incorrect paddings in IE11 (the rightmost icon is always too far to the right, even in RTL).

image

image

</div>
<div>
<input type="checkbox" id="no-right-item-checkbox"/>
<label for="no-right-item-checkbox">No Right Item</label>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: reword to "No Action Item"?

`registerScrollHandler(handler) => void` | Registers a handler to be called when user scrolls. Our default implementation adds the handler as a listener to the window's `scroll` event.
`deregisterScrollHandler(handler) => void` | Unregisters a handler to be called when user scrolls. Our default implementation removes the handler as a listener to the window's `scroll` event.
`getViewportScrollY() => number` | Gets the number of pixels that the content of body is scrolled from the top of the page.
`getTotalActionItems() => number` | Gets the number of action items on the top app bar.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: on -> in?

@include mdc-rtl-reflexive_(border-bottom-left-radius, 0, border-bottom-right-radius, $mdc-top-app-bar-short-collapsed-border-radius);
}

@mixin mdc-top-app-bar-mobile-breakpoint($mobile-breakpoint: $mdc-top-app-bar-mobile-breakpoint) {
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 make this a private mixin and add !default to the breakpoint variable instead? Otherwise these styles are getting emitted for the default breakpoint anyway and there's not really a way to undo that.

const cssClasses = {
SHORT_CLASS: 'mdc-top-app-bar--short',
SHORT_HAS_ACTION_ITEM_CLASS: 'mdc-top-app-bar--short-has-action-item',
SHORT_CLOSED_CLASS: 'mdc-top-app-bar--short-collapsed',
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to SHORT_COLLAPSED_CLASS if we're referring to the state as collapsed in the JS anyway?

/**
* Used to set the initial style of the short top app bar
*/
styleShortAppBar() {
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 a reason why this API is public? (We're not even using it in the demo, but that's kind of a special case anyway; we normally wouldn't expect people to switch the type of app bar dynamically.)

td.verify(mockAdapter.registerScrollHandler(td.matchers.isA(Function)), {times: 1});
});

test('short top app bar: on scroll listener is removed on destroy', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Remove "on" before "scroll"

td.verify(mockAdapter.addClass(MDCTopAppBarFoundation.cssClasses.SHORT_HAS_ACTION_ITEM_CLASS), {times: 1});
});

test('short top app bar: class is not added if it has an action item', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

"if it does not have an action item"

@@ -140,6 +142,14 @@ test('#adapter.registerNavigationIconInteractionHandler adds a handler to the na
td.verify(handler(td.matchers.anything()));
});

test('#adapter.deregisterScrollHandler does not remove a handler to the nav icon if the nav icon is null ', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

to -> from

component.getDefaultFoundation().adapter_.deregisterScrollHandler(handler);
domEvents.emit(window, 'scroll');
try {
td.verify(handler(td.matchers.anything()), {times: 0});
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still going to properly fail the test case if we catch it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're not catching the error, we're just using a finally to ensure the scroll handler gets unregistered from the window. I've checked that the test fails if the deregister fails.

},
},
};
assert.isNotOk(util.applyPassive(mockWindow, true));
Copy link
Contributor

Choose a reason for hiding this comment

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

isNotOk -> isFalse

@williamernest williamernest force-pushed the feat/top-app-bar/add-short-top-app-bar branch 6 times, most recently from 5b38e44 to 1e2d75f Compare February 27, 2018 19:12
@williamernest williamernest force-pushed the feat/top-app-bar/add-short-top-app-bar branch from 1e2d75f to b359062 Compare February 27, 2018 19:29
td.when(mockAdapter.hasClass(MDCTopAppBarFoundation.cssClasses.SHORT_CLASS)).thenReturn(true);
foundation.init();
foundation.destroy();
td.verify(mockAdapter.registerScrollHandler(td.matchers.isA(Function)), {times: 1});
Copy link
Contributor

Choose a reason for hiding this comment

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

This is supposed to be testing deregister, right?

td.when(mockAdapter.hasClass(MDCTopAppBarFoundation.cssClasses.SHORT_CLASS)).thenReturn(true);
td.when(mockAdapter.getTotalActionItems()).thenReturn(0);
foundation.init();
td.verify(mockAdapter.addClass(MDCTopAppBarFoundation.cssClasses.SHORT_HAS_ACTION_ITEM_CLASS), {times: 0});
Copy link
Contributor

Choose a reason for hiding this comment

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

Our impl is actually removing this class in this case, right? We should test that removeClass is invoked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're testing that this class was never added. It's added during init if the html has an action item.

assert.equal(component.getDefaultFoundation().adapter_.getViewportScrollY(), window.pageYOffset);
});

test('adapter#getTotalActionItems returns the amount of action icons on the opposite side of 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.

amount -> number, icons -> items?

@williamernest williamernest merged commit fd8d8d9 into master Feb 28, 2018
@williamernest williamernest deleted the feat/top-app-bar/add-short-top-app-bar branch February 28, 2018 19:21
acdvorak added a commit that referenced this pull request Mar 8, 2018
commit f17e0d3
Author: Will Ernest <34519388+williamernest@users.noreply.github.com>
Date:   Thu Mar 8 13:20:48 2018 -0500

    fix(text-field): Clicking label should focus textfield (#2353)

commit 77b15f4
Author: Bonnie Zhou <bzbee003@gmail.com>
Date:   Wed Mar 7 16:29:57 2018 -0800

    refactor(button): Remove compact variant (#2361)

    BREAKING CHANGE: The compact variant of MDC Button is removed.

commit 35a5cfc
Author: Will Ernest <34519388+williamernest@users.noreply.github.com>
Date:   Tue Mar 6 19:54:23 2018 -0500

    fix(toolbar): Fix colors for svg icons. Update custom-toolbar demo (#2331)

    SVG icons in the toolbar will now use the same color as the font icons.

commit dc52201
Author: Andrew C. Dvorak <acdvorak@gmail.com>
Date:   Tue Mar 6 16:00:12 2018 -0800

    fix(theme): Move @alternate annotations for Closure Stylesheets (#2355)

    `@alternate` annotations need to come before the _second_ property. Otherwise, Closure Compiler strips the first property (it does not output it at all).

commit 3c04419
Author: aprigogin <17075403+aprigogin@users.noreply.github.com>
Date:   Tue Mar 6 14:29:12 2018 -0800

    fix(button): icon in rtl should have margin right flipped. (#2346)

commit b9000a4
Author: Cory Reed <swashcap@gmail.com>
Date:   Tue Mar 6 07:37:40 2018 -0800

    fix(demos): Correct RTL/LTR toggling in demos in Safari (#2348)

commit ab85736
Author: Andrew C. Dvorak <acdvorak@gmail.com>
Date:   Mon Mar 5 19:00:11 2018 -0500

    fix: Use `var` instead of `const` in menu demo (#2345)

    Safari 9.x and IE 10 do not support `const`

commit dc3d69f
Author: aprigogin <17075403+aprigogin@users.noreply.github.com>
Date:   Mon Mar 5 15:22:31 2018 -0800

    fix(rtl): Adding noflip annotations to fix downstream rtl issues (#2344)

    * fix(rtl): Adding noflip annotations to fix downstream rtl issues

    * fix(rtl): remove changes to button, will be in separate PR

    * fix(rtl): remove changes to button, will be in separate PR - second attempt.

    * fix(rtl): removed extra whitespace

commit eb4138e
Author: Patrick RoDee <prodee@google.com>
Date:   Mon Mar 5 14:10:46 2018 -0800

    docs: Update CHANGELOG.md

commit f478610
Author: Patrick RoDee <prodee@google.com>
Date:   Mon Mar 5 14:10:30 2018 -0800

    chore: Publish

commit 78408bb
Author: Andrew C. Dvorak <acdvorak@gmail.com>
Date:   Mon Mar 5 16:13:02 2018 -0500

    fix: Use `var` instead of `const` in demos/ready.js (#2343)

    Safari 9.x and IE 10 do not support `const`, and `ready.js` is not transpiled to ES5.

commit 49a9449
Author: Will Ernest <34519388+williamernest@users.noreply.github.com>
Date:   Mon Mar 5 12:21:54 2018 -0500

    chore(select): Fix JS example in Readme (#2332)

commit bc17291
Author: Will Ernest <34519388+williamernest@users.noreply.github.com>
Date:   Fri Mar 2 13:21:07 2018 -0500

    feat(top app bar): Add short top app bar always collapsed feature (#2327)

commit 0ba7d10
Author: Matty Goo <mattgoo@google.com>
Date:   Fri Mar 2 11:33:19 2018 -0500

    fix(text-field): disable validation check in setRequired (#2201)

    BREAKING CHANGE: removed setRequired and isRequired from foundation.

commit c14d244
Author: Will Ernest <34519388+williamernest@users.noreply.github.com>
Date:   Fri Mar 2 10:37:18 2018 -0500

    chore(select): Fix ID values in demo (#2330)

    Remove unused ID and changed duplicated ID values. Also fixed the parentheses in RTL.

commit ecf4060
Author: Bonnie Zhou <bzbee003@gmail.com>
Date:   Thu Mar 1 16:38:41 2018 -0500

    feat(chips): Change chip color when selected (#2329)

    BREAKING CHANGE: The `mdc-chip--activated` class, `mdc-chip-activated-ink-color` Sass mixin, and the `toggleActive` methods on `MDCChip`/`MDCChipSet` have been renamed to `mdc-chip--selected`, `mdc-chip-selected-ink-color`, and `toggleSelected`, respectively.

commit 4b24b51
Author: Matty Goo <mattgoo@google.com>
Date:   Wed Feb 28 15:20:19 2018 -0500

    chore(floating-label): separate label module from text-field (#2237)

    BREAKING CHANGE: must use `.mdc-floating-label` selector instead of `.mdc-text-field__label`

commit fd8d8d9
Author: Will Ernest <34519388+williamernest@users.noreply.github.com>
Date:   Wed Feb 28 14:21:55 2018 -0500

    feat(top-app-bar): Implement short top app bar (#2290)

    Adds the short top app bar variant to the top app bar.

commit a9f9bf2
Author: Kenneth G. Franqueiro <kfranqueiro@users.noreply.github.com>
Date:   Wed Feb 28 13:06:41 2018 -0500

    docs(select): Fix front matter for label sub-component (#2323)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants