Skip to content

Commit 88b5cfe

Browse files
asynclizcopybara-github
authored andcommitted
fix(ripple): wrong start point for pressing unbounded ripples
PiperOrigin-RevId: 537965121
1 parent 0e94e28 commit 88b5cfe

File tree

2 files changed

+39
-44
lines changed

2 files changed

+39
-44
lines changed

ripple/demo/stories.ts

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,71 +17,70 @@ export interface StoryKnobs {
1717
'--md-ripple-hover-opacity': number;
1818
}
1919

20-
const bounded: MaterialStoryInit<StoryKnobs> = {
21-
name: 'Bounded',
20+
const ripples: MaterialStoryInit<StoryKnobs> = {
21+
name: 'Ripples',
2222
styles: css`
23-
.container {
24-
border-radius: 16px;
25-
height: 64px;
26-
outline: 1px solid var(--md-sys-color-outline);
27-
position: relative;
28-
width: 64px;
23+
.row {
24+
align-items: center;
25+
display: flex;
26+
gap: 32px;
2927
}
30-
`,
31-
render() {
32-
return html`
33-
<div class="container">
34-
<md-ripple></md-ripple>
35-
</div>
36-
`;
37-
}
38-
};
3928
40-
const unbounded: MaterialStoryInit<StoryKnobs> = {
41-
name: 'Unbounded',
42-
styles: css`
4329
.container {
4430
align-items: center;
4531
border-radius: 24px;
4632
display: flex;
47-
gap: 16px;
48-
height: 48px;
49-
outline: 1px dashed var(--md-sys-color-outline);
33+
height: 64px;
34+
justify-content: center;
35+
outline: 1px solid var(--md-sys-color-outline);
5036
padding: 16px;
37+
position: relative;
38+
width: 64px;
5139
}
5240
53-
.icon {
41+
.container:has(.unbounded) {
42+
border-radius: 50%;
43+
outline-style: dashed;
44+
}
45+
46+
.anchor {
47+
background: var(--md-sys-color-primary-container);
5448
border: 1px solid var(--md-sys-color-outline);
5549
border-radius: 50%;
56-
display: grid;
5750
height: 24px;
51+
width: 24px;
52+
53+
/* Recommended styles for an unbounded ripple's anchor. */
54+
display: grid;
5855
place-items: center;
5956
position: relative;
60-
width: 24px;
6157
}
6258
63-
.anchor {
64-
background: var(--md-sys-color-primary-container);
65-
}
59+
md-ripple.unbounded {
60+
height: 64px;
61+
width: 64px;
6662
67-
md-ripple {
63+
/* Recommended styles for an unbounded ripple. */
6864
border-radius: 50%;
69-
height: 40px;
7065
inset: unset;
71-
width: 40px;
7266
}
7367
`,
7468
render() {
7569
return html`
76-
<div id="touch" class="container">
77-
<div class="icon anchor">
78-
<md-ripple for="touch"></md-ripple>
70+
<div class="row">
71+
<div class="container">
72+
<md-ripple></md-ripple>
73+
</div>
74+
75+
<div class="container" id="touch">
76+
<div class="anchor">
77+
<md-ripple for="touch" class="unbounded"></md-ripple>
78+
</div>
7979
</div>
80-
<div class="icon"></div>
8180
</div>
8281
`;
8382
}
8483
};
8584

8685
/** Ripple stories. */
87-
export const stories = [bounded, unbounded];
86+
export const stories = [ripples];

ripple/lib/ripple.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,8 @@ export class Ripple extends LitElement implements Attachable {
256256
this.endPressAnimation();
257257
}
258258

259-
private getDimensions() {
260-
return (this.parentElement ?? this).getBoundingClientRect();
261-
}
262-
263259
private determineRippleSize() {
264-
const {height, width} = this.getDimensions();
260+
const {height, width} = this.getBoundingClientRect();
265261
const maxDim = Math.max(height, width);
266262
const softEdgeSize =
267263
Math.max(SOFT_EDGE_CONTAINER_RATIO * maxDim, SOFT_EDGE_MINIMUM_SIZE);
@@ -278,15 +274,15 @@ export class Ripple extends LitElement implements Attachable {
278274
private getNormalizedPointerEventCoords(pointerEvent: PointerEvent):
279275
{x: number, y: number} {
280276
const {scrollX, scrollY} = window;
281-
const {left, top} = this.getDimensions();
277+
const {left, top} = this.getBoundingClientRect();
282278
const documentX = scrollX + left;
283279
const documentY = scrollY + top;
284280
const {pageX, pageY} = pointerEvent;
285281
return {x: pageX - documentX, y: pageY - documentY};
286282
}
287283

288284
private getTranslationCoordinates(positionEvent?: Event) {
289-
const {height, width} = this.getDimensions();
285+
const {height, width} = this.getBoundingClientRect();
290286
// end in the center
291287
const endPoint = {
292288
x: (width - this.initialSize) / 2,

0 commit comments

Comments
 (0)