From 69582349bb6f5dc7e5657e37ced211c1ac5e92a8 Mon Sep 17 00:00:00 2001 From: Konstantin Vyatkin Date: Fri, 25 Oct 2019 08:09:27 -0400 Subject: [PATCH] remove redundant CSS (#697) * remove redundant CSS * fix error with lack of test for false * destruct dataset * fix typo --- src/scripts/choices.js | 7 ++++--- src/scripts/store/store.js | 6 ++++-- src/styles/choices.scss | 8 -------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/scripts/choices.js b/src/scripts/choices.js index 23e93a0f..91558c27 100644 --- a/src/scripts/choices.js +++ b/src/scripts/choices.js @@ -822,8 +822,9 @@ class Choices { } // If we are clicking on an option - const id = element.getAttribute('data-id'); + const { id } = element.dataset; const choice = this._store.getChoiceById(id); + if (!choice) return; const passedKeyCode = activeItems[0] && activeItems[0].keyCode ? activeItems[0].keyCode : null; const hasActiveDropdown = this.dropdown.isActive; @@ -835,7 +836,7 @@ class Choices { choice, }); - if (choice && !choice.selected && !choice.disabled) { + if (!choice.selected && !choice.disabled) { const canAddItem = this._canAddItem(activeItems, choice.value); if (canAddItem.response) { @@ -855,7 +856,7 @@ class Choices { this.clearInput(); - // We wont to close the dropdown if we are dealing with a single select box + // We want to close the dropdown if we are dealing with a single select box if (hasActiveDropdown && this._isSelectOneElement) { this.hideDropdown(true); this.containerOuter.focus(); diff --git a/src/scripts/store/store.js b/src/scripts/store/store.js index 133353d0..caef4720 100644 --- a/src/scripts/store/store.js +++ b/src/scripts/store/store.js @@ -139,11 +139,13 @@ export default class Store { /** * Get single choice by it's ID - * @return {Object} Found choice + * @param {id} string + * @return {import('../../../types/index').Choices.Choice | false} Found choice */ getChoiceById(id) { if (id) { - return this.activeChoices.find(choice => choice.id === parseInt(id, 10)); + const n = parseInt(id, 10); + return this.activeChoices.find(choice => choice.id === n); } return false; } diff --git a/src/styles/choices.scss b/src/styles/choices.scss index f7a6d229..a39855eb 100644 --- a/src/styles/choices.scss +++ b/src/styles/choices.scss @@ -343,12 +343,4 @@ $choices-icon-cross-inverse: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjEiI opacity: 0.5; } -.#{$choices-selector}__input[hidden], -.#{$choices-selector}[data-type*='select-one'] - .#{$choices-selector}__input[hidden], -.#{$choices-selector}[data-type*='select-multiple'] - .#{$choices-selector}__input[hidden] { - display: none; -} - /*===== End of Choices ======*/