Bug 1475208 - (Part 3) Record upper bounds by unit in font size component. r=gl draft
authorRazvan Caliman <rcaliman@mozilla.com>
Mon, 30 Jul 2018 23:35:08 +0200
changeset 827671 55d1e276322322823648fd28ac8bebf3ebbfde60
parent 827670 a5e097d28cfc8bbc5b4974cf93deed638087b760
child 827672 bf5afc8d975045ea82f7864ac8cfdc0add99be4b
push id118557
push userbmo:rcaliman@mozilla.com
push dateWed, 08 Aug 2018 16:44:17 +0000
reviewersgl
bugs1475208
milestone63.0a1
Bug 1475208 - (Part 3) Record upper bounds by unit in font size component. r=gl MozReview-Commit-ID: Ku6dBVux3GP
devtools/client/inspector/fonts/components/FontSize.js
--- a/devtools/client/inspector/fonts/components/FontSize.js
+++ b/devtools/client/inspector/fonts/components/FontSize.js
@@ -15,17 +15,23 @@ const { getUnitFromValue, getStepForUnit
 class FontSize extends PureComponent {
   static get propTypes() {
     return {
       onChange: PropTypes.func.isRequired,
       value: PropTypes.string.isRequired,
     };
   }
 
+  constructor(props) {
+    super(props);
+    this.historicMax = {};
+  }
+
   render() {
+    const value = parseFloat(this.props.value);
     const unit = getUnitFromValue(this.props.value);
     let max;
     switch (unit) {
       case "em":
       case "rem":
         max = 4;
         break;
       case "vh":
@@ -37,23 +43,32 @@ class FontSize extends PureComponent {
       case "%":
         max = 200;
         break;
       default:
         max = 72;
         break;
     }
 
+    // Allow the upper bound to increase so it accomodates the out-of-bounds value.
+    max = Math.max(max, value);
+    // Ensure we store the max value ever reached for this unit type. This will be the
+    // max value of the input and slider. Without this memoization, the value and slider
+    // thumb get clamped at the upper bound while decrementing an out-of-bounds value.
+    this.historicMax[unit] = this.historicMax[unit]
+      ? Math.max(this.historicMax[unit], max)
+      : max;
+
     return FontPropertyValue({
       label: getStr("fontinspector.fontSizeLabel"),
       min: 0,
-      max,
+      max: this.historicMax[unit],
       name: "font-size",
       onChange: this.props.onChange,
       showUnit: true,
       step: getStepForUnit(unit),
       unit,
-      value: parseFloat(this.props.value),
+      value,
     });
   }
 }
 
 module.exports = FontSize;