From 9f543cf1d30b9a276f31bbeace0597cdafaf6c66 Mon Sep 17 00:00:00 2001 From: denisavitski Date: Sat, 11 Jan 2025 12:03:51 +0300 Subject: [PATCH] radio: disable/enable --- package.json | 2 +- src/components/packages/radio/index.ts | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index c07aa2f..8d91e2c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aptechka", - "version": "0.51.2", + "version": "0.51.3", "repository": { "type": "git", "url": "git+https://github.com/denisavitski/aptechka.git" diff --git a/src/components/packages/radio/index.ts b/src/components/packages/radio/index.ts index 111f63a..70ece26 100644 --- a/src/components/packages/radio/index.ts +++ b/src/components/packages/radio/index.ts @@ -9,6 +9,8 @@ export class RadioElement extends HTMLElement { #value: T | undefined #currentButtonElement: HTMLElement | null = null + #disabled = false + public get value() { return this.#value } @@ -21,6 +23,18 @@ export class RadioElement extends HTMLElement { return this.#currentButtonElement } + public get disabled() { + return this.#disabled + } + + public disable() { + this.#disabled = true + } + + public enable() { + this.#disabled = false + } + public addButton(element: HTMLElement) { this.#buttonElements.push(element) @@ -99,12 +113,14 @@ export class RadioElement extends HTMLElement { } #buttonClickListener = (e: Event) => { - const ct = e.currentTarget as HTMLElement + if (!this.#disabled) { + const ct = e.currentTarget as HTMLElement - const value = ct.getAttribute('data-value') + const value = ct.getAttribute('data-value') - if (value) { - this.setValue(value as T) + if (value) { + this.setValue(value as T) + } } }