Skip to content

Commit bb271a1

Browse files
fix(VColorPicker, VCalendar, ripple) support CSS zoom (#22774)
fixes #22761
1 parent ecbe030 commit bb271a1

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

packages/vuetify/src/components/VCalendar/composables/calendarWithIntervals.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
validateTime,
1717
} from '../util/timestamp'
1818
import { propsFactory } from '@/util'
19+
import { Box, getTargetBox } from '@/util/box'
1920

2021
// Types
2122
import type { PropType, StyleValue } from 'vue'
@@ -165,13 +166,14 @@ export function useCalendarWithIntervals (props: CalendarWithIntervalsProps) {
165166

166167
function getTimestampAtEvent (e: Event, day: CalendarTimestamp): CalendarTimestamp {
167168
const timestamp: CalendarTimestamp = copyTimestamp(day)
168-
const bounds = (e.currentTarget as HTMLElement).getBoundingClientRect()
169+
const bounds = new Box(e.currentTarget as HTMLElement)
169170
const baseMinutes: number = firstMinute.value
170171
const touchEvent: TouchEvent = e as TouchEvent
171172
const mouseEvent: MouseEvent = e as MouseEvent
172173
const touches: TouchList = touchEvent.changedTouches || touchEvent.touches
173-
const clientY: number = touches && touches[0] ? touches[0].clientY : mouseEvent.clientY
174-
const addIntervals: number = (clientY - bounds.top) / parsedIntervalHeight.value
174+
const target = touches && touches[0] ? touches[0] : mouseEvent
175+
const point = getTargetBox([target.clientX, target.clientY])
176+
const addIntervals: number = (point.y - bounds.top) / parsedIntervalHeight.value
175177
const addMinutes: number = Math.floor(addIntervals * parsedIntervalMinutes.value)
176178
const minutes: number = baseMinutes + addMinutes
177179

packages/vuetify/src/components/VColorPicker/VColorPickerCanvas.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import { useResizeObserver } from '@/composables/resizeObserver'
88
// Utilities
99
import { computed, onMounted, ref, shallowRef, toRef, watch } from 'vue'
1010
import { clamp, convertToUnit, defineComponent, getEventCoordinates, propsFactory, useRender } from '@/util'
11+
import { getTargetBox } from '@/util/box'
1112

1213
// Types
1314
import type { PropType } from 'vue'
1415
import type { HSV } from '@/util'
16+
import type { Box } from '@/util/box'
1517

1618
export const makeVColorPickerCanvasProps = propsFactory({
1719
color: {
@@ -91,7 +93,7 @@ export const VColorPickerCanvas = defineComponent({
9193
canvasHeight.value = Math.round(height)
9294
})
9395

94-
function updateDotPosition (x: number, y: number, rect: DOMRect) {
96+
function updateDotPosition (x: number, y: number, rect: Box) {
9597
const { left, top, width, height } = rect
9698
dotPosition.value = {
9799
x: clamp(x - left, 0, width),
@@ -121,8 +123,9 @@ export const VColorPickerCanvas = defineComponent({
121123
isInteracting.value = true
122124

123125
const coords = getEventCoordinates(e)
126+
const point = getTargetBox([coords.clientX, coords.clientY])
124127

125-
updateDotPosition(coords.clientX, coords.clientY, canvasRef.value.getBoundingClientRect())
128+
updateDotPosition(point.x, point.y, getTargetBox(canvasRef.value))
126129
}
127130

128131
function handleMouseUp () {

packages/vuetify/src/directives/ripple/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import './VRipple.sass'
33

44
// Utilities
55
import { isObject } from '@/util'
6+
import { Box, getTargetBox } from '@/util/box'
67

78
// Types
89
import type { DirectiveBinding } from 'vue'
@@ -53,11 +54,12 @@ const calculate = (
5354
let localY = 0
5455

5556
if (!isKeyboardEvent(e)) {
56-
const offset = el.getBoundingClientRect()
57+
const offset = new Box(el)
5758
const target = isTouchEvent(e) ? e.touches[e.touches.length - 1] : e
59+
const point = getTargetBox([target.clientX, target.clientY])
5860

59-
localX = target.clientX - offset.left
60-
localY = target.clientY - offset.top
61+
localX = point.x - offset.left
62+
localY = point.y - offset.top
6163
}
6264

6365
let radius = 0

0 commit comments

Comments
 (0)