@khanacademy/math-input 17.3.0 → 17.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ /// <reference path="../../types/aphrodite.d.ts" />
1
2
  import * as React from "react";
2
3
  import type { StyleType } from "@khanacademy/wonder-blocks-core";
3
4
  import type { CSSProperties } from "aphrodite";
package/dist/index.js CHANGED
@@ -47,7 +47,7 @@ var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
47
47
 
48
48
  // This file is processed by a Rollup plugin (replace) to inject the production
49
49
  const libName = "@khanacademy/math-input";
50
- const libVersion = "17.3.0";
50
+ const libVersion = "17.4.0";
51
51
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
52
52
 
53
53
  function _extends() {
@@ -1526,6 +1526,7 @@ class MathInput extends React__namespace.Component {
1526
1526
  };
1527
1527
  state = {
1528
1528
  focused: false,
1529
+ showInputFocusStyle: false,
1529
1530
  handle: {
1530
1531
  animateIntoPosition: false,
1531
1532
  visible: false,
@@ -1608,6 +1609,8 @@ class MathInput extends React__namespace.Component {
1608
1609
  // multi-touch.
1609
1610
  if (this.state.focused && this.didTouchOutside && !this.didScroll) {
1610
1611
  this.blur();
1612
+ this.mathField.blur();
1613
+ this.props.onBlur?.();
1611
1614
  }
1612
1615
  this.didTouchOutside = false;
1613
1616
  this.didScroll = false;
@@ -1632,6 +1635,7 @@ class MathInput extends React__namespace.Component {
1632
1635
  // in which case we don't want to dismiss the keypad on check.
1633
1636
  if (!isWithinKeypadBounds(x, y)) {
1634
1637
  this.blur();
1638
+ this.props.onBlur && this.props.onBlur();
1635
1639
  }
1636
1640
  }
1637
1641
  }
@@ -1726,15 +1730,14 @@ class MathInput extends React__namespace.Component {
1726
1730
  };
1727
1731
  blur = () => {
1728
1732
  this.mathField.blur();
1729
- this.props.onBlur && this.props.onBlur();
1730
1733
  this.setState({
1731
- focused: false,
1734
+ showInputFocusStyle: false,
1732
1735
  handle: {
1733
1736
  visible: false
1734
1737
  }
1735
1738
  });
1736
1739
  };
1737
- focus = () => {
1740
+ focus = setKeypadActive => {
1738
1741
  // Pass this component's handleKey method to the keypad so it can call
1739
1742
  // it whenever it needs to trigger a keypress action.
1740
1743
  this.props.keypadElement?.setKeyHandler(key => {
@@ -1761,8 +1764,10 @@ class MathInput extends React__namespace.Component {
1761
1764
  });
1762
1765
  this.mathField.focus();
1763
1766
  this.props?.onFocus();
1767
+ setKeypadActive(true);
1764
1768
  this.setState({
1765
- focused: true
1769
+ focused: true,
1770
+ showInputFocusStyle: true
1766
1771
  }, () => {
1767
1772
  // NOTE(charlie): We use `setTimeout` to allow for a layout pass to
1768
1773
  // occur. Otherwise, the keypad is measured incorrectly. Ideally,
@@ -1975,7 +1980,7 @@ class MathInput extends React__namespace.Component {
1975
1980
 
1976
1981
  // Trigger a focus event, if we're not already focused.
1977
1982
  if (!this.state.focused) {
1978
- this.focus();
1983
+ this.focus(setKeypadActive);
1979
1984
  }
1980
1985
 
1981
1986
  // If the user clicked on the input using a mouse or tap gesture,
@@ -2013,7 +2018,7 @@ class MathInput extends React__namespace.Component {
2013
2018
 
2014
2019
  // Trigger a focus event, if we're not already focused.
2015
2020
  if (!this.state.focused) {
2016
- this.focus();
2021
+ this.focus(setKeypadActive);
2017
2022
  }
2018
2023
 
2019
2024
  // If the user clicked on the input using a mouse or tap gesture,
@@ -2218,7 +2223,7 @@ class MathInput extends React__namespace.Component {
2218
2223
  };
2219
2224
  render() {
2220
2225
  const {
2221
- focused,
2226
+ showInputFocusStyle,
2222
2227
  handle
2223
2228
  } = this.state;
2224
2229
  const {
@@ -2227,7 +2232,7 @@ class MathInput extends React__namespace.Component {
2227
2232
  const innerStyle = {
2228
2233
  ...inlineStyles.innerContainer,
2229
2234
  borderWidth: this.getBorderWidthPx(),
2230
- ...(focused ? {
2235
+ ...(showInputFocusStyle ? {
2231
2236
  borderColor: Color__default["default"].blue
2232
2237
  } : {}),
2233
2238
  ...style
@@ -2266,13 +2271,17 @@ class MathInput extends React__namespace.Component {
2266
2271
  ref: node => {
2267
2272
  this.inputRef = node;
2268
2273
  },
2274
+ onFocus: () => {
2275
+ this.focus(setKeypadActive);
2276
+ },
2277
+ onBlur: this.blur,
2269
2278
  onKeyUp: this.handleKeyUp
2270
2279
  }, /*#__PURE__*/React__namespace.createElement("div", {
2271
2280
  ref: node => {
2272
2281
  this._mathContainer = ReactDOM__default["default"].findDOMNode(node);
2273
2282
  },
2274
2283
  style: innerStyle
2275
- })), focused && handle.visible && /*#__PURE__*/React__namespace.createElement(CursorHandle, _extends({}, handle, {
2284
+ })), showInputFocusStyle && handle.visible && /*#__PURE__*/React__namespace.createElement(CursorHandle, _extends({}, handle, {
2276
2285
  onTouchStart: this.onCursorHandleTouchStart,
2277
2286
  onTouchMove: this.onCursorHandleTouchMove,
2278
2287
  onTouchEnd: this.onCursorHandleTouchEnd,