Skip to content

Commit

Permalink
fix: fixed #1914. When the mathVirtualKeyboardPolicy is set to manual…
Browse files Browse the repository at this point in the history
…, the keyboard is not hidden, even when losing focus
  • Loading branch information
arnog committed Apr 8, 2023
1 parent b480c5e commit 645fa9d
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/virtual-keyboard/virtual-keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,22 +235,25 @@ export class VirtualKeyboard implements VirtualKeyboardInterface, EventTarget {
}
});

document.addEventListener('focusout', () => {
// If after a short delay the active element is no longer
// a mathfield (or there is no active element),
// hide the virtual keyboard
setTimeout(() => {
let target = document.activeElement;
let focusedMathfield = false;
while (target) {
if (target.tagName?.toLowerCase() === 'math-field') {
focusedMathfield = true;
break;
document.addEventListener('focusout', (evt) => {
const target = evt.target as MathfieldElement;
if (target.mathVirtualKeyboardPolicy !== 'manual') {
// If after a short delay the active element is no longer
// a mathfield (or there is no active element),
// hide the virtual keyboard
setTimeout(() => {
let target = document.activeElement;
let focusedMathfield = false;
while (target) {
if (target.tagName?.toLowerCase() === 'math-field') {
focusedMathfield = true;
break;
}
target = target.shadowRoot?.activeElement ?? null;
}
target = target.shadowRoot?.activeElement ?? null;
}
if (!focusedMathfield) this.hide();
}, 300);
if (!focusedMathfield) this.hide();
}, 300);
}
});
}

Expand Down

0 comments on commit 645fa9d

Please sign in to comment.