From b7a829ff12c908821717998a33df21ae88be05f1 Mon Sep 17 00:00:00 2001 From: KoloMl Date: Fri, 3 Jan 2025 05:13:29 +0400 Subject: [PATCH] Added tag category, storing the original category in the component class --- src/lib/components/TagDropdownWrapper.js | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/lib/components/TagDropdownWrapper.js b/src/lib/components/TagDropdownWrapper.js index 3be464f..ce87347 100644 --- a/src/lib/components/TagDropdownWrapper.js +++ b/src/lib/components/TagDropdownWrapper.js @@ -36,6 +36,11 @@ export class TagDropdownWrapper extends BaseComponent { */ #isEntered = false; + /** + * @type {string|undefined|null} + */ + #originalCategory = null; + build() { this.#dropdownContainer = this.container.querySelector('.dropdown__content'); } @@ -57,6 +62,41 @@ export class TagDropdownWrapper extends BaseComponent { return this.container.dataset.tagName; } + /** + * @return {string|undefined} + */ + get tagCategory() { + return this.container.dataset.tagCategory; + } + + /** + * @param {string|undefined} targetCategory + */ + set tagCategory(targetCategory) { + // Make sure original category is properly stored. + this.originalCategory; + + this.container.dataset.tagCategory = targetCategory; + + if (targetCategory) { + this.container.setAttribute('data-tag-category', targetCategory); + return; + } + + this.container.removeAttribute('data-tag-category'); + } + + /** + * @return {string|undefined} + */ + get originalCategory() { + if (this.#originalCategory === null) { + this.#originalCategory = this.tagCategory; + } + + return this.#originalCategory; + } + #onDropdownEntered() { this.#isEntered = true; this.#updateButtons();