From af17111480d41f4770c7129733817e0dfd2d4f7c Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sat, 11 Sep 2021 00:02:13 +0700 Subject: input: allow label to be HTMLElement instead of only string A label on input can be a string or another HTMLElement. --- input/number.d.ts | 2 +- input/number.ts | 20 +++++++++++++++----- input/select.d.ts | 2 +- input/select.ts | 16 ++++++++++++---- input/string.d.ts | 2 +- input/string.ts | 33 +++++++++++++++++++++++++-------- 6 files changed, 55 insertions(+), 20 deletions(-) diff --git a/input/number.d.ts b/input/number.d.ts index cbf847a..654b7e3 100644 --- a/input/number.d.ts +++ b/input/number.d.ts @@ -1,5 +1,5 @@ export interface WuiInputNumberOpts { - label: string; + label: string | HTMLElement; value: number; id?: string; hint?: string; diff --git a/input/number.ts b/input/number.ts index 11e561b..e2d1bc5 100644 --- a/input/number.ts +++ b/input/number.ts @@ -1,5 +1,5 @@ export interface WuiInputNumberOpts { - label: string + label: string | HTMLElement value: number id?: string hint?: string @@ -24,7 +24,9 @@ const WUI_INPUT_NUMBER_CLASS_LABEL = "wui_input_number_label" // //
//
-// +// // { diff --git a/input/select.d.ts b/input/select.d.ts index 6a568f3..88f1faa 100644 --- a/input/select.d.ts +++ b/input/select.d.ts @@ -6,7 +6,7 @@ export interface WuiKeySelectOption { [key: string]: WuiInputOption; } export interface WuiInputSelectOpts { - label: string; + label: string | HTMLElement; name: string; options: WuiKeySelectOption; id?: string; diff --git a/input/select.ts b/input/select.ts index 1989c06..df6f450 100644 --- a/input/select.ts +++ b/input/select.ts @@ -9,7 +9,7 @@ export interface WuiKeySelectOption { } export interface WuiInputSelectOpts { - label: string + label: string | HTMLElement name: string options: WuiKeySelectOption id?: string @@ -31,7 +31,9 @@ const WUI_INPUT_SELECT_CLASS_LABEL = "wui_input_select_label" // //
//
-// +// // { if (this.opts.onChangeHandler) { - if (this.value !== this.el_input.value) { - this.opts.onChangeHandler(this.el_input.value) - this.value = this.el_input.value + if ( + this.value !== + this.el_input.value + ) { + this.opts.onChangeHandler( + this.el_input.value, + ) + this.value = + this.el_input.value } } } @@ -102,7 +117,9 @@ export class WuiInputString { private generateHintToggler(wrapper: HTMLElement) { this.el_hint_toggler = document.createElement("span") - this.el_hint_toggler.classList.add(WUI_INPUT_STRING_CLASS_HINT_TOGGLER) + this.el_hint_toggler.classList.add( + WUI_INPUT_STRING_CLASS_HINT_TOGGLER, + ) this.el_hint_toggler.innerHTML = " ℹ" this.el_hint_toggler.onmouseover = () => { -- cgit v1.3