Skip to content

Commit a5e51da

Browse files
fix click outside
1 parent 262ba96 commit a5e51da

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

projects/angular-keyboard/src/lib/keyboard-container/keyboard-container.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,16 @@ export class KeyboardContainerComponent implements OnInit, OnDestroy {
3333

3434
onClickOnPage(e) {
3535
const isFakeInput = this.angularKeyboardService.inputFields
36-
.map(fakeInputElt => isAncestor(e.target, fakeInputElt.nativeElement))
36+
.map(fakeInputElt => {
37+
try {
38+
// Check if the fake input element is an ancestor of the clicked element
39+
return isAncestor(e.target, fakeInputElt.nativeElement);
40+
} catch {
41+
// It is possible that the clicked element is already not present anymore in the DOM, then isAncestor throws an error.
42+
// In this case assume a click outside to close the keyboard
43+
return false;
44+
}
45+
})
3746
.reduce((a, b) => a || b, false);
3847
if (isFakeInput) {
3948
// don't blur

0 commit comments

Comments
 (0)