@khanacademy/math-input 20.0.2 → 20.1.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.
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
44
44
 
45
45
  // This file is processed by a Rollup plugin (replace) to inject the production
46
46
  const libName = "@khanacademy/math-input";
47
- const libVersion = "20.0.2";
47
+ const libVersion = "20.1.0";
48
48
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
49
49
 
50
50
  function _extends() {
@@ -1457,9 +1457,9 @@ class MathWrapper {
1457
1457
  mathField; // MathQuill MathField input
1458
1458
  callbacks;
1459
1459
  mobileKeyTranslator;
1460
- constructor(element, strings, locale) {
1461
- let callbacks = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1462
- this.mathField = createMathField(element, locale, strings, () => {
1460
+ constructor(mathFieldMount, ariaLabel, strings, locale) {
1461
+ let callbacks = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
1462
+ this.mathField = createMathField(mathFieldMount, locale, strings, () => {
1463
1463
  return {
1464
1464
  // use a span instead of a textarea so that we don't bring up the
1465
1465
  // native keyboard on mobile when selecting the input
@@ -1468,6 +1468,7 @@ class MathWrapper {
1468
1468
  }
1469
1469
  };
1470
1470
  });
1471
+ this.mathField?.setAriaLabel(ariaLabel);
1471
1472
  this.callbacks = callbacks;
1472
1473
  this.mobileKeyTranslator = {
1473
1474
  ...getKeyTranslator(locale),
@@ -1689,7 +1690,7 @@ class MathInput extends React__namespace.Component {
1689
1690
  };
1690
1691
  componentDidMount() {
1691
1692
  this._isMounted = true;
1692
- this.mathField = new MathWrapper(this._mathContainer, this.context.strings, this.context.locale, {
1693
+ this.mathField = new MathWrapper(this._mathContainer, this.props.ariaLabel, this.context.strings, this.context.locale, {
1693
1694
  onCursorMove: cursor => {
1694
1695
  // TODO(charlie): It's not great that there is so much coupling
1695
1696
  // between this keypad and the input behavior. We should wrap
@@ -2669,10 +2670,25 @@ function TabbarItem(props) {
2669
2670
  } = props;
2670
2671
  const tabRef = React.useRef(null);
2671
2672
  React.useEffect(() => {
2673
+ let timeout;
2672
2674
  if (role === "tab" && focus) {
2673
- // Move element into view when it is focused
2674
- tabRef?.current?.focus();
2675
+ /**
2676
+ * When tabs are within a WonderBlocks Popover component, the
2677
+ * manner in which the component is rendered and moved causes
2678
+ * focus to snap to the bottom of the page on first focus.
2679
+ *
2680
+ * This timeout moves around that by delaying the focus enough
2681
+ * to wait for the WonderBlock Popover to move to the correct
2682
+ * location and scroll the user to the correct location.
2683
+ * */
2684
+ timeout = setTimeout(() => {
2685
+ if (tabRef?.current) {
2686
+ // Move element into view when it is focused
2687
+ tabRef?.current.focus();
2688
+ }
2689
+ }, 0);
2675
2690
  }
2691
+ return () => clearTimeout(timeout);
2676
2692
  }, [role, focus, tabRef]);
2677
2693
  return /*#__PURE__*/React__namespace.createElement(Clickable__default["default"], {
2678
2694
  onClick: onClick,