FIX: prevents s shortcut to generate an error (#13974)

When no element is selected, on the homepage for example, pressing `s` would generate the following error:

```
Uncaught TypeError: Cannot read property 'click' of undefined
```

Note that this commit also removes jquery usage.
This commit is contained in:
Joffrey JAFFEUX 2021-08-09 09:39:01 +02:00 committed by GitHub
parent 0790bbdea5
commit 800926fcce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 6 deletions

View File

@ -536,13 +536,13 @@ export default {
_bindToClick(selector, binding) {
binding = binding.split(",");
this.keyTrapper.bind(binding, function (e) {
const $sel = $(selector);
const selection = document.querySelector(selector);
// Special case: We're binding to enter.
if (e && e.keyCode === 13) {
// Binding to enter should only be effective when there is something
// to select.
if ($sel.length === 0) {
if (!selection) {
return;
}
@ -550,10 +550,7 @@ export default {
e.preventDefault();
}
// If there is more than one match for the selector, just click
// the first one, we don't want to click multiple things from one
// shortcut.
$sel[0].click();
selection?.click();
});
},