-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
fix(ripple): make ripples conform with specs #2859
Conversation
ae80099
to
22d09ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, overall very clean and much simpler tests
private _rippleElement: HTMLElement; | ||
|
||
/** Element where the ripples are being added to. */ | ||
private _targetElement: HTMLElement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we call this containerElement
?
private _isMousedown: boolean = false; | ||
|
||
/** Currently showing ripples that will be closed on mouseup. */ | ||
private _showingRipples: HTMLElement[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_activeRipples
?
src/lib/core/ripple/ripple.ts
Outdated
@Input('md-ripple-trigger') | ||
get _triggerDeprecated() { return this.trigger; } | ||
set _triggerDeprecated(value: HTMLElement|HTMLElement) { this.trigger = value; }; | ||
@Input('mdRippleTrigger') trigger: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather keep the type on this, even if it is clunky
(the HTMLElement|HTMLElement
thing is a workaround for server-side prerendering)
src/lib/core/ripple/ripple.ts
Outdated
isKeyEvent); | ||
} | ||
/** Creates a manual ripple at the specified position. */ | ||
createRipple(pageX: number, pageY: number, config?: RippleConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is already the ripple class, we could just call this something like launch()
// Specify events which need to be registered on the trigger. | ||
this._triggerEvents.set('mousedown', this.onMousedown.bind(this)); | ||
this._triggerEvents.set('mouseup', this.onMouseup.bind(this)); | ||
this._triggerEvents.set('mouseleave', this.onMouseLeave.bind(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than using a Map
, how about an array of tuples? Better for iteration
let triggerEvents: [string, (MouseEvent) => void][] = [
['mousedown', e => this.onMouseDown(e)],
// ...
];
(generally prefer arrow functions to .bind()
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think that will be better for iteration. A map already provides a suitable iterator for those eventpairs.
I would personally like to stay with the Map
for convenience and readability.
59cfd11
to
6911161
Compare
@jelbourn Addressed your feedback. Thanks. |
6911161
to
f77b5cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3 this is amazing
@@ -68,16 +68,16 @@ | |||
} | |||
} | |||
|
|||
.md-checkbox:not(.md-checkbox-disabled) { | |||
&.md-primary .md-checkbox-ripple .md-ripple-foreground { | |||
md-checkbox:not(.md-checkbox-disabled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use class rather than element selector (so it works with comparability mode mat-* elements as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I actually had that change only in this PR for testing purposes. I have another PR open for this. See #2857
Also I think we can only use the class here, as soon as Andrew's PR is merged.
@@ -18,8 +18,7 @@ | |||
<div md-ripple *ngIf="!_isRippleDisabled()" class="md-checkbox-ripple" | |||
[mdRippleTrigger]="_getHostElement()" | |||
[mdRippleCentered]="true" | |||
[mdRippleSpeedFactor]="0.3" | |||
mdRippleBackgroundColor="rgba(0, 0, 0, 0)"></div> | |||
[mdRippleSpeedFactor]="0.3"></div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the spec say anything about what the speed of these ripples should be? i think the button one looks a little slower in your demo than it does in the specs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed on Slack, we are going to have another PR to make all component ripples align with the specs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created #2901 for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I assign it to me?
let offsetX = pageX - containerRect.left; | ||
let offsetY = pageY - containerRect.top; | ||
|
||
let ripple = document.createElement('div'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use the Renderer to create this and set styles?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed on Slack, we will revisit this in issue #308 and once we have feedback from Jeremy about this.
// ripple elements. This is critical because then the `scale` would not animate properly. | ||
// Enforce a style recalculation by calling `getComputedStyle` and accessing any property. | ||
// See: https://gist.github.com/paulirish/5d52fb081b3570c81e3a | ||
window.getComputedStyle(ripple).getPropertyValue('opacity'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems like a good candidate for extracting into some DOM utility class, I don't think we have one yet, but maybe make it a private method with a note that we can extract it?
|
||
ripple.style.transform = 'scale(1)'; | ||
|
||
// Wait for the ripple to be faded in. Once faded in the ripple can be hided if the mouse is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/hided/hidden
@@ -86,112 +65,86 @@ describe('MdRipple', () => { | |||
document.body.style.margin = originalBodyMargin; | |||
}); | |||
|
|||
function dispatchMouseEvent(type: string, offsetX = 0, offsetY = 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I swear this function is in like half of our test files, we should create a test utilities file sometime (not part of this PR though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created #2902 for this
src/lib/radio/_radio-theme.scss
Outdated
@@ -29,7 +29,7 @@ | |||
} | |||
} | |||
|
|||
.md-radio-ripple .md-ripple-foreground { | |||
.md-radio-ripple .md-ripple-element { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when adding new classes make them mat-* to make andrew's life easier :p
@mmalerba Thanks for your feedback. Addressed the comments you added. Also glad you like it :) |
lgtm |
a32ea4f
to
b48d2a9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
const MIN_RIPPLE_FILL_TIME_SECONDS = 0.1; | ||
const MAX_RIPPLE_FILL_TIME_SECONDS = 0.3; | ||
export const RIPPLE_SPEED_PX_PER_SECOND = 170; | ||
export const RIPPLE_FADE_OUT_DURATION = 600; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add doc somewhere to mention the fade out duration is fixed and is not changed with speed factor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Added it to the @Input()
and also added comments for those constants.
This makes the ripple service conform with the specifications and other Material reference implementations. See https://material.io/guidelines/motion/material-motion.html#material-motion-how-does-material-move This means the following: * Ripples now trigger on `mousedown` * Ripples now persists as long as the element is being hold. * No longer adds an unnecessary background ripple. * Removes the ugly `scale(0.00001)` for ripple animations Not only visually the ripple has been changed. The whole renderer has been rewritten and now has a very simple API, that can be easily used by developers. References angular#1434
630cc8c
to
209e4b0
Compare
209e4b0
to
48bccb5
Compare
Just rebased the PR due to the compatibility changes. |
Great PR! Was about to open up an issue about the current state of ripple effects. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This makes the ripple service conform with the specifications and other Material reference implementations.
See https://material.io/guidelines/motion/material-motion.html#material-motion-how-does-material-move
Reference from the Material specifications
This means the following:
mousedown
scale(0.00001)
for ripple animationsNot only visually the ripple has been changed. The whole renderer has been rewritten and now has a very simple API, that can be easily used by developers.
Also the API has been changed to something more intuitive
As seen in the example, developers are now able to specify a simple Ripple Config object
Live Demo: https://material2-dashboard.firebaseapp.com/button (temporary)
References #1434