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-surface): Update setPosition adapter API to use numeric values #4351

Merged
merged 8 commits into from
Feb 5, 2019

Conversation

acdvorak
Copy link
Contributor

@acdvorak acdvorak commented Feb 4, 2019

Accepting string values implies that we support all valid CSS units (em, rem, %, etc.), but in truth we only support px.

Changing the type of the properties from string to number makes this clearer, and also simplifies converting the package to TypeScript in PR #4273.

BREAKING CHANGE: MDCMenuSurfaceAdapter.setPosition() now expects an object with properties of type number rather than string. E.g., setPosition({top: '5px', left: '10px'}) is now setPosition({top: 5, left: 10}).

Accepting `string` values implies that we support all valid CSS units (`em`, `rem`, `%`, etc.), but in truth we only support `px`.

Changing the type of the properties from `string` to `number` makes this clearer, and also simplifies converting the package to TypeScript in PR #4273.

BREAKING CHANGE: `MDCMenuSurfaceAdapter.setPosition()` now expects an object with properties of type `number` rather than `string`. E.g., `setPosition({top: '5px', left: '10px'})` is now `setPosition({top: 5, left: 10})`.
packages/mdc-menu-surface/foundation.js Outdated Show resolved Hide resolved
packages/mdc-menu-surface/foundation.js Outdated Show resolved Hide resolved
this.root_.style.right = 'right' in position ? position.right : null;
this.root_.style.top = 'top' in position ? position.top : null;
this.root_.style.bottom = 'bottom' in position ? position.bottom : null;
this.root_.style.left = 'left' in position ? `${position.left}px` : '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this change from null to '' here, if we're not doing that in the TypeScript PR? (It occurred to me to suggest this there, but I figured we were preserving existing behavior.)

Copy link
Contributor Author

@acdvorak acdvorak Feb 4, 2019

Choose a reason for hiding this comment

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

The Closure Compiler test suddenly complained that these values can't be null 🤷‍♂️

TypeScript's lib.dom.d.ts, however, includes | null in the types for all of these properties, so tsc doesn't complain about 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.

CSS specs seem to indicate that null is not a valid value. Empty string is preferred.
So Closure Compiler is technically correct; TypeScript is wrong.

@codecov-io
Copy link

codecov-io commented Feb 4, 2019

Codecov Report

Merging #4351 into master will increase coverage by 0.08%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4351      +/-   ##
==========================================
+ Coverage   98.48%   98.56%   +0.08%     
==========================================
  Files         130      130              
  Lines        5736     5731       -5     
  Branches      766      763       -3     
==========================================
  Hits         5649     5649              
+ Misses         87       82       -5
Impacted Files Coverage Δ
packages/mdc-menu-surface/index.js 100% <100%> (+0.97%) ⬆️
packages/mdc-menu-surface/foundation.js 100% <100%> (+1.71%) ⬆️

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 af950fc...55ac7cf. Read the comment docs.

@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit 08f5fe9 vs. master! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit 5264ea9 vs. master! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit acfef88 vs. master! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit 8501b4d vs. master! 💯🎉

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.

One nit otherwise LGTM

@@ -26,7 +26,7 @@
* top: number,
* right: number,
* bottom: number,
* left: number
* left: number,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is trailing comma valid in closure annotations?

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's Closure, so probably not. Removed. Thanks!

@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit fb02775 vs. master! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit 55ac7cf vs. master! 💯🎉

@acdvorak acdvorak merged commit 701ed5c into master Feb 5, 2019
@acdvorak acdvorak deleted the feat/menu-surface/setPosition-api branch February 5, 2019 17:51
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.

None yet

5 participants