Skip to content

Commit

Permalink
Fix mosuedown in dropdown causing blur and therefore close of dropdow…
Browse files Browse the repository at this point in the history
…n without selection
  • Loading branch information
julkue committed Jun 3, 2021
1 parent b084ac1 commit 997f0a0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@julmot/form-components",
"version": "1.1.3",
"version": "1.1.4",
"description": "Custom Form Components. Without Any Framework. Accessible.",
"keywords": [
"form",
Expand Down
2 changes: 1 addition & 1 deletion src/components/_common/_fonts.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@font-face {
font-family: "form-components-icons";
src: url("../../fonts/form-components-icons/form-components-icons.woff?2281ab3a92848f43e971c33de7b726d3") format("woff");
src: url("../../fonts/form-components-icons/form-components-icons.woff?65b1e42927684e703d14d95aa39a85f6") format("woff");
font-weight: normal;
font-style: normal;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,16 @@ export class Select extends FormComponent {
});
});
}
// blur event.explicitOriginalTarget isn't cross-browser compatible. To check whether the blur event wasn't
// caused by a mousedown inside the dropdown, catch the event beforehand
let clicky = null;
this.context.addEventListener('mousedown', event => clicky = event.target);
this.context.addEventListener('mouseup', () => clicky = null);
this.field.addEventListener('blur', () => {
if (!this.field.hasAttribute('disabled')) {
// Make sure to not close the dropdown before the option click event
// is called. Otherwise you can't select any value using click
setTimeout(() => {
const target = document.activeElement;
if (target === this.context || this.context.contains(target)) {
return;
}
if (clicky === null || (this.context !== clicky && !this.context.contains(clicky))) {
this.close();
}, 150);
}
}
});
}
Expand Down
Binary file modified src/fonts/form-components-icons/form-components-icons.woff
Binary file not shown.

0 comments on commit 997f0a0

Please sign in to comment.