Comments (7)
@rosinghal yes, because there is no keybinding for "[". The keybinding that got filtered out was for "alt+leftbracket". If you want "leftbracket" to do something else, you can add a keybinding for it.
from mathlive.
The issue is most likely occurring because the mathfield is not properly mounted by the time you attempt top customize it (by the time you set the event listener). React lifecycle can be a bit tricky.
To ensure a mathfield is customized at the right time, I recommend two options:
1/ Use the onMount
event handler. The TypeScript bindings for the math-field element currently do not have this event handler type appropriately, so you may need to do some convincing to have TypeScript let you use it.
2/ Use a useEffect
hook, but wait on the ref to be ready.
useEffect(() => {
const mathfield = ref.current;
// ...
}, [ref.current]);
Also, note you do not need to copy the set of keybindings from source. You can simply filter the ones you don't want at runtime:
mathfield.keybindings = mathfield.keybindings.filter((x) => !x.key.includes("[BracketLeft]"));
from mathlive.
Thanks for the suggestion. However, it does not work either. Here is my code
import { createElement, DetailedHTMLProps, HTMLAttributes, ReactElement, useEffect, useMemo, useRef } from 'react';
import Mathlive, { MathfieldElement } from 'mathlive';
type MathfieldProps = DetailedHTMLProps<HTMLAttributes<MathfieldElement>, MathfieldElement>;
export const Mathfield = ({ children, className, ...props }: MathfieldProps): ReactElement<MathfieldProps> => {
const ref = useRef<MathfieldElement>(null);
const mfe = useMemo(() => new MathfieldElement(), []);
useEffect(() => {
const mathfield = ref.current;
if (mathfield) {
mathfield.keybindings = mathfield.keybindings.filter(x => !x.key.includes('[BracketLeft]'));
}
}, [ref, mfe]);
return createElement('math-field', { ref, class: className, 'data-testid': 'math-field', ...props }, children);
};
from mathlive.
Please check https://codesandbox.io/p/sandbox/exciting-aryabhata-th68p9
from mathlive.
I think it should work if you use the code I included. Try https://codesandbox.io/p/sandbox/exciting-aryabhata-forked-tll5zh?file=%2Fsrc%2FMathField.jsx
Note that the dependency in the useEffect
is on ref.current
. Also, you don't need the reference to mfe
.
from mathlive.
@arnog even in the code you sent, if I type [ab]
I get the value as \left\lbrack ab\right\rbrack
even though we have filtered out keybindings with [BracketLeft]
.
You will see the output after typing in the math field and then click outside.
from mathlive.
Understood, I have updated the keybindings to
mathfield.keybindings = [
...mathfield.keybindings.filter(
(x) => !x.key.includes("[BracketLeft]")
),
{
key: "[BracketLeft]",
ifLayout: ["apple.en-intl", "windows.en-intl", "linux.en"],
ifMode: "math",
command: ["insert", "[#0]"],
},
];
This is what I was looking for. Thanks a lot. Closing the issue.
from mathlive.
Related Issues (20)
- Incorrect positioning of lower bound in definite integrals HOT 1
- Mathfield in Iframe and touch devices only allows one character to be written. HOT 9
- Weird box like characters HOT 5
- Macros not available at MFE instantiation HOT 4
- TypeError while pressing arrow
- Menu shouldn't display when clicking other math field element HOT 2
- Selection area exception in low version of chrome HOT 4
- Is it possible to "lock" the submenu of the variant?
- --keycap-height issues in iframe HOT 1
- export to mathml-core HOT 6
- PlusMinus retains some kind of state HOT 2
- Disabling context menu with mf.menuItems = [] does not work on mobile HOT 8
- onInput and onKeyDown sequencing issue
- MathfieldElement's Chinese locale configuration is invalid
- keybinding command switchMode should insert the prefix in the previous mode and the suffix with the new mode HOT 1
- Curly-bracket cannot be input when smart-fence is off
- Change Color is Not Working As Expected When Combined With Virtual Keyboard
- Can't set "\\right)" as latex for virtual keyboard HOT 7
- Repeating decimal and parenthesis HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mathlive.