MCPcopy Create free account
hub / github.com/cutedCha/noteBoook / checkTouchTargetSize

Function checkTouchTargetSize

tests/touch-target.property.test.js:82–108  ·  view source on GitHub ↗

* Helper function to check if element meets minimum touch target size * @param {HTMLElement} element - DOM element to check * @returns {object} Object with width, height, and isValid properties

(element)

Source from the content-addressed store, hash-verified

80 * @returns {object} Object with width, height, and isValid properties
81 */
82 function checkTouchTargetSize(element) {
83 const computedStyle = window.getComputedStyle(element);
84
85 // Get actual dimensions
86 const width = element.offsetWidth || parseCSSValueToPixels(computedStyle.width);
87 const height = element.offsetHeight || parseCSSValueToPixels(computedStyle.height);
88
89 // Get min-width and min-height
90 const minWidth = parseCSSValueToPixels(computedStyle.minWidth);
91 const minHeight = parseCSSValueToPixels(computedStyle.minHeight);
92
93 // Element is valid if either actual size or min-size meets requirement
94 const effectiveWidth = Math.max(width, minWidth);
95 const effectiveHeight = Math.max(height, minHeight);
96
97 return {
98 width: effectiveWidth,
99 height: effectiveHeight,
100 minWidth,
101 minHeight,
102 actualWidth: width,
103 actualHeight: height,
104 isWidthValid: effectiveWidth >= MIN_TOUCH_TARGET_SIZE,
105 isHeightValid: effectiveHeight >= MIN_TOUCH_TARGET_SIZE,
106 isValid: effectiveWidth >= MIN_TOUCH_TARGET_SIZE && effectiveHeight >= MIN_TOUCH_TARGET_SIZE
107 };
108 }
109
110 /**
111 * Helper function to create a mock element with specified styles

Callers 1

Calls 1

parseCSSValueToPixelsFunction · 0.85

Tested by

no test coverage detected