From 997f0a0d41ba59b68db2ee8817515a8494855786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=BChnel?= Date: Thu, 3 Jun 2021 15:28:40 +0200 Subject: [PATCH] Fix mosuedown in dropdown causing blur and therefore close of dropdown without selection --- package.json | 2 +- src/components/_common/_fonts.scss | 2 +- .../select-material-like.js | 15 +++++++-------- .../form-components-icons.woff | Bin 3432 -> 3432 bytes 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index f405800..67d873b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/_common/_fonts.scss b/src/components/_common/_fonts.scss index bd6fae3..e068904 100644 --- a/src/components/_common/_fonts.scss +++ b/src/components/_common/_fonts.scss @@ -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; } diff --git a/src/components/select/select-material-like/select-material-like.js b/src/components/select/select-material-like/select-material-like.js index 8c75ffb..b96a7d8 100644 --- a/src/components/select/select-material-like/select-material-like.js +++ b/src/components/select/select-material-like/select-material-like.js @@ -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); + } } }); } diff --git a/src/fonts/form-components-icons/form-components-icons.woff b/src/fonts/form-components-icons/form-components-icons.woff index 306d657573f715300b8d41f23379fce9dd4a2e77..a90c43fc03cc73f929cf5e31b7992918991db4f5 100644 GIT binary patch delta 353 zcmV-n0iOQo8t593JOqu_Yao$8oCF-kR9%taTM70600LD#!Al^ML;*1+-^!0O38YH@$%?ol&(bX1$9dooTTwzdlGHTc^1oo%Y%DgWsEYB{7-pU#LgZ32gq!wdF| z-#7JHzoE8cINso}<^#d^hY-)TxKd>=-?mPDV|Ui6qvP-YaAb94zDae$R+O!j=^O^b zv5s96yr`~ARh55u^aFFeZWaIlc${NkVgQ5xD;Sf)44Dniz0MCX8URL}2kQU;Q_G}i delta 353 zcmV-n0iOQo8t593JOqq_=B|-IoCF(k&+C!kTM6|500LOf6CU1^L;*1+BbDe!@%%Pl z8RVH5K;Vwa@$Cru{{iM}j0b>R4hFC^05;eQ)w7xbDhhwGYQr!PhJPhapfp34?3zPm z&Vo?L*uh)ZJV0G1c(5+W?%t=!Q}l)UHvO$?YaoSIaJrBG?w3viu)+lf(=yoLA@dAt zyk?%G!e{0J8}pcXfwj@hOX?r&G{qg2ZE{UKgT+(kIbQIVxxm)kXI{XX=gdp$?>Isc z(Ziu3^*DcX4`>-92C7}s0~tq+y=$~TYiPqbxUSJa`KIrurB0PjADa zjYFrwid3bD*nhb63z~dxivR!sc${NkVgQ5xD;Sf)44Dm%$?@$l8UQ{22B81|?bojc