@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.
@@ -3,6 +3,7 @@ import { MathInputI18nContext } from "../i18n-context";
3
3
  import type { KeypadAPI, KeypadContextType } from "../../types";
4
4
  type Props = {
5
5
  keypadElement?: KeypadAPI;
6
+ ariaLabel: string;
6
7
  onBlur: () => void;
7
8
  onChange: (value: string, callback: any) => void;
8
9
  onFocus: () => void;
@@ -10,7 +10,7 @@ declare class MathWrapper {
10
10
  mathField: MathFieldInterface;
11
11
  callbacks: any;
12
12
  mobileKeyTranslator: Record<Key, MathFieldUpdaterCallback>;
13
- constructor(element: any, strings: MathInputStrings, locale: string, callbacks?: {});
13
+ constructor(mathFieldMount: any, ariaLabel: string, strings: MathInputStrings, locale: string, callbacks?: {});
14
14
  focus(): void;
15
15
  blur(): void;
16
16
  /**
package/dist/es/index.js CHANGED
@@ -15,7 +15,7 @@ import PropTypes from 'prop-types';
15
15
 
16
16
  // This file is processed by a Rollup plugin (replace) to inject the production
17
17
  const libName = "@khanacademy/math-input";
18
- const libVersion = "20.0.2";
18
+ const libVersion = "20.1.0";
19
19
  addLibraryVersionToPerseusDebug(libName, libVersion);
20
20
 
21
21
  function _extends() {
@@ -1402,12 +1402,13 @@ const getKeyTranslator = locale => ({
1402
1402
  * from MathQuill changes.
1403
1403
  */
1404
1404
  class MathWrapper {
1405
- constructor(element, strings, locale, callbacks = {}) {
1405
+ constructor(mathFieldMount, ariaLabel, strings, locale, callbacks = {}) {
1406
+ var _this$mathField;
1406
1407
  this.mathField = void 0;
1407
1408
  // MathQuill MathField input
1408
1409
  this.callbacks = void 0;
1409
1410
  this.mobileKeyTranslator = void 0;
1410
- this.mathField = createMathField(element, locale, strings, () => {
1411
+ this.mathField = createMathField(mathFieldMount, locale, strings, () => {
1411
1412
  return {
1412
1413
  // use a span instead of a textarea so that we don't bring up the
1413
1414
  // native keyboard on mobile when selecting the input
@@ -1416,6 +1417,7 @@ class MathWrapper {
1416
1417
  }
1417
1418
  };
1418
1419
  });
1420
+ (_this$mathField = this.mathField) == null || _this$mathField.setAriaLabel(ariaLabel);
1419
1421
  this.callbacks = callbacks;
1420
1422
  this.mobileKeyTranslator = _extends({}, getKeyTranslator(locale), {
1421
1423
  // note(Matthew): our mobile backspace logic is really complicated
@@ -2179,7 +2181,7 @@ class MathInput extends React.Component {
2179
2181
  }
2180
2182
  componentDidMount() {
2181
2183
  this._isMounted = true;
2182
- this.mathField = new MathWrapper(this._mathContainer, this.context.strings, this.context.locale, {
2184
+ this.mathField = new MathWrapper(this._mathContainer, this.props.ariaLabel, this.context.strings, this.context.locale, {
2183
2185
  onCursorMove: cursor => {
2184
2186
  // TODO(charlie): It's not great that there is so much coupling
2185
2187
  // between this keypad and the input behavior. We should wrap
@@ -2609,11 +2611,25 @@ function TabbarItem(props) {
2609
2611
  } = props;
2610
2612
  const tabRef = useRef(null);
2611
2613
  useEffect(() => {
2614
+ let timeout;
2612
2615
  if (role === "tab" && focus) {
2613
- var _tabRef$current;
2614
- // Move element into view when it is focused
2615
- tabRef == null || (_tabRef$current = tabRef.current) == null || _tabRef$current.focus();
2616
+ /**
2617
+ * When tabs are within a WonderBlocks Popover component, the
2618
+ * manner in which the component is rendered and moved causes
2619
+ * focus to snap to the bottom of the page on first focus.
2620
+ *
2621
+ * This timeout moves around that by delaying the focus enough
2622
+ * to wait for the WonderBlock Popover to move to the correct
2623
+ * location and scroll the user to the correct location.
2624
+ * */
2625
+ timeout = setTimeout(() => {
2626
+ if (tabRef != null && tabRef.current) {
2627
+ // Move element into view when it is focused
2628
+ tabRef == null || tabRef.current.focus();
2629
+ }
2630
+ }, 0);
2616
2631
  }
2632
+ return () => clearTimeout(timeout);
2617
2633
  }, [role, focus, tabRef]);
2618
2634
  return /*#__PURE__*/React.createElement(Clickable, {
2619
2635
  onClick: onClick,