From 48e632c17fea517b8bdf8798b881c07be7a50ecc Mon Sep 17 00:00:00 2001 From: Yiannis Christodoulou Date: Thu, 16 Oct 2025 17:13:44 +0300 Subject: [PATCH] Improve icon size calculation for AutoplayToggleButton Icon size is now calculated in pixels based on em units from PlayerConfig, with scaling and sensible defaults. Added defensive checks to ensure iconSize is always a valid number, improving reliability across device types. --- .../src/components/controls/AutoplayToggleButton.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend-tools/video-js/src/components/controls/AutoplayToggleButton.js b/frontend-tools/video-js/src/components/controls/AutoplayToggleButton.js index a7525051..46755a64 100644 --- a/frontend-tools/video-js/src/components/controls/AutoplayToggleButton.js +++ b/frontend-tools/video-js/src/components/controls/AutoplayToggleButton.js @@ -23,7 +23,9 @@ class AutoplayToggleButton extends Button { } */ // Store the appropriate font size based on device type - this.iconSize = isTouchDevice ? PlayerConfig.controlBar.mobileFontSize : PlayerConfig.controlBar.fontSize; + // PlayerConfig values are in em units, convert to pixels for SVG dimensions + const baseFontSize = isTouchDevice ? PlayerConfig.controlBar.mobileFontSize : PlayerConfig.controlBar.fontSize; + this.iconSize = Math.round((baseFontSize || 14) * 1.2); // Scale and default to 14em if undefined this.userPreferences = options.userPreferences; // Get autoplay preference from localStorage, default to false if not set @@ -72,6 +74,11 @@ class AutoplayToggleButton extends Button { } updateIconClass() { + // Ensure iconSize is a valid number (defensive check) + if (!this.iconSize || isNaN(this.iconSize)) { + this.iconSize = 16; // Default to 16px if undefined or NaN + } + // Remove existing icon classes this.iconSpan.className = 'vjs-icon-placeholder vjs-svg-icon vjs-autoplay-icon__OFFF'; this.iconSpan.style.position = 'relative';