Skip to content

Mathfield does not scroll into view when the virtual keyboard shows with animation #2950

@Wigny

Description

@Wigny

In React, I noticed that while a padding is added to the page body when the keyboard shows up, the view is never scrolled so that the math-field is visible when the mathVirtualKeyboardPolicy is auto or when it is manual and mathVirtualKeyboard.show({ animate: true }) is called.

It seems that we can forcefully make the view scroll by executing the scrollIntoView command, and that can be done when the keyboard geometry changes, but to make it work, it still seems required to wait for the keyboard animation.

Here is a working example of what is required to make the scroll happen in React, but if you ever change mathVirtualKeyboardPolicy to auto, set mathVirtualKeyboard.show({ animate: false }) or remove the setTimeout, the scroll stops working:

import React, { useState } from 'react';
import 'mathlive';

export default function App() {
  const [value, setValue] = useState('');

  return (
    <>
      <div style={{ height: '80vh' }}></div>
      <math-field
        style={{ width: '100%' }}
        ref={(mathfield) => {
          if (mathfield === null) return;

          mathfield.mathVirtualKeyboardPolicy = 'manual';

          window.mathVirtualKeyboard.addEventListener('geometrychange', () => {
            setTimeout(() => mathfield.executeCommand('scrollIntoView'), 300);
          });
        }}
        onFocus={() => window.mathVirtualKeyboard.show({ animate: true })}
        onBlur={() => window.mathVirtualKeyboard.hide({ animate: true })}
        onInput={(evt) => setValue(evt.currentTarget.value)}
      >
        {value}
      </math-field>
    </>
  );
}

Is this the intended configuration to have auto-scroll when the input is focused, and the keyboard appears?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions