From 88b5cfeb21fcacc49f745dde00cfef459a4b5df6 Mon Sep 17 00:00:00 2001 From: Elizabeth Mitchell Date: Mon, 5 Jun 2023 13:25:31 -0700 Subject: [PATCH] fix(ripple): wrong start point for pressing unbounded ripples PiperOrigin-RevId: 537965121 --- ripple/demo/stories.ts | 73 +++++++++++++++++++++--------------------- ripple/lib/ripple.ts | 10 ++---- 2 files changed, 39 insertions(+), 44 deletions(-) diff --git a/ripple/demo/stories.ts b/ripple/demo/stories.ts index 6c769c26bc..ecfe056bb0 100644 --- a/ripple/demo/stories.ts +++ b/ripple/demo/stories.ts @@ -17,71 +17,70 @@ export interface StoryKnobs { '--md-ripple-hover-opacity': number; } -const bounded: MaterialStoryInit = { - name: 'Bounded', +const ripples: MaterialStoryInit = { + name: 'Ripples', styles: css` - .container { - border-radius: 16px; - height: 64px; - outline: 1px solid var(--md-sys-color-outline); - position: relative; - width: 64px; + .row { + align-items: center; + display: flex; + gap: 32px; } - `, - render() { - return html` -
- -
- `; - } -}; -const unbounded: MaterialStoryInit = { - name: 'Unbounded', - styles: css` .container { align-items: center; border-radius: 24px; display: flex; - gap: 16px; - height: 48px; - outline: 1px dashed var(--md-sys-color-outline); + height: 64px; + justify-content: center; + outline: 1px solid var(--md-sys-color-outline); padding: 16px; + position: relative; + width: 64px; } - .icon { + .container:has(.unbounded) { + border-radius: 50%; + outline-style: dashed; + } + + .anchor { + background: var(--md-sys-color-primary-container); border: 1px solid var(--md-sys-color-outline); border-radius: 50%; - display: grid; height: 24px; + width: 24px; + + /* Recommended styles for an unbounded ripple's anchor. */ + display: grid; place-items: center; position: relative; - width: 24px; } - .anchor { - background: var(--md-sys-color-primary-container); - } + md-ripple.unbounded { + height: 64px; + width: 64px; - md-ripple { + /* Recommended styles for an unbounded ripple. */ border-radius: 50%; - height: 40px; inset: unset; - width: 40px; } `, render() { return html` -
-
- +
+
+ +
+ +
+
+ +
-
`; } }; /** Ripple stories. */ -export const stories = [bounded, unbounded]; +export const stories = [ripples]; diff --git a/ripple/lib/ripple.ts b/ripple/lib/ripple.ts index 3c8b1578f7..d24d080b86 100644 --- a/ripple/lib/ripple.ts +++ b/ripple/lib/ripple.ts @@ -256,12 +256,8 @@ export class Ripple extends LitElement implements Attachable { this.endPressAnimation(); } - private getDimensions() { - return (this.parentElement ?? this).getBoundingClientRect(); - } - private determineRippleSize() { - const {height, width} = this.getDimensions(); + const {height, width} = this.getBoundingClientRect(); const maxDim = Math.max(height, width); const softEdgeSize = Math.max(SOFT_EDGE_CONTAINER_RATIO * maxDim, SOFT_EDGE_MINIMUM_SIZE); @@ -278,7 +274,7 @@ export class Ripple extends LitElement implements Attachable { private getNormalizedPointerEventCoords(pointerEvent: PointerEvent): {x: number, y: number} { const {scrollX, scrollY} = window; - const {left, top} = this.getDimensions(); + const {left, top} = this.getBoundingClientRect(); const documentX = scrollX + left; const documentY = scrollY + top; const {pageX, pageY} = pointerEvent; @@ -286,7 +282,7 @@ export class Ripple extends LitElement implements Attachable { } private getTranslationCoordinates(positionEvent?: Event) { - const {height, width} = this.getDimensions(); + const {height, width} = this.getBoundingClientRect(); // end in the center const endPoint = { x: (width - this.initialSize) / 2,