Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling context menu with mf.menuItems = [] does not work on mobile #2369

Closed
gunnarmein-ts opened this issue May 10, 2024 · 8 comments
Closed

Comments

@gunnarmein-ts
Copy link
Contributor

gunnarmein-ts commented May 10, 2024

Description

mf.menuItems = [] works fine on a laptop, but on mobile (in a simulator and on the device), the menu appears anyway.

Steps to Reproduce

load attached test.html in mobile iOS browser (simulator will be fine), context menu was disabled by mf.menuItems = [];
press and hold any part of mathfield

Actual Behavior

context menu appears

Expected Behavior

Nothing should happen (as is the case on non-mobile)

Environment

mathlive 0.98.6
iOS Safari, latest version

@gunnarmein-ts
Copy link
Contributor Author

gunnarmein-ts commented May 10, 2024

@arnog Seems like this could be fixed by changing

// If no items visible, don't show anything
if (!menu.visible) return false;

to

// If no items visible, don't show anything
if (!menu.visible || !menu.menuItems?.length) return false;

at the end of src/ui/menu/context-menu.ts (around line 83 in my fork)

@arnog
Copy link
Owner

arnog commented May 10, 2024

The .visible accessor should already return false if there are no menu items:

  get visible(): boolean {
    this.updateIfDirty();
    return this._menuItems.some((x) => x.type !== 'divider' && x.visible);
  }

@gunnarmein-ts
Copy link
Contributor Author

Don't know what to tell you. Try the test case I attached above on a phone. Perhaps _menuItems is not updated correctly when menuItems is empty.

@arnog
Copy link
Owner

arnog commented May 10, 2024

FYI, I don't see an attached test.html.

@gunnarmein-ts
Copy link
Contributor Author

test.html.zip
Apologies, that must not have worked.

@arnog
Copy link
Owner

arnog commented May 21, 2024

It's a script execution/timing issue. The <script> tag on line 29 is executed before the <script> on line 6 which has a defer attribute. Note that this may or may not be the case depending on the browser, environment, etc... since the defer attribute is not prescriptive.

When the line 36 mf.menuItems = [] is executed, the mf has not yet been converted to a MathfieldElement. So, the menuItems attribute get set, but it has no effect since the base HTMLElement doesn't know what to do with it. Later, when this element is upgraded to a MathfieldElement instance, the menu is reset to the default.

To avoid this issue, listen for a mount event from the mathfield element. When this event is dispatched, the mathfield is ready to be configured. Set the menuItems property in the handler of that event.

@gunnarmein-ts
Copy link
Contributor Author

Duh! I should have known better. Thanks!

@arnog
Copy link
Owner

arnog commented May 23, 2024

Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants