@@ -40,12 +40,15 @@ import { InputColorController } from './controller';
4040} )
4141export class KolInputColor implements InputColorAPI , FocusableElement {
4242 @Element ( ) private readonly host ?: HTMLKolInputColorElement ;
43- private inputRef ?: HTMLInputElement ;
43+ private refInputText ?: HTMLInputElement ;
44+ private refInputColor ?: HTMLInputElement ;
4445
4546 private readonly catchRef = ( ref ?: HTMLInputElement ) => {
46- this . inputRef = ref ;
47+ this . refInputText = ref ;
48+ } ;
49+ private readonly catchColorRef = ( ref ?: HTMLInputElement ) => {
50+ this . refInputColor = ref ;
4751 } ;
48-
4952 private readonly onBlur = ( event : FocusEvent ) => {
5053 this . controller . onFacade . onBlur ( event ) ;
5154 this . inputHasFocus = false ;
@@ -56,51 +59,75 @@ export class KolInputColor implements InputColorAPI, FocusableElement {
5659 this . inputHasFocus = true ;
5760 } ;
5861
59- private readonly onInput = ( event : InputEvent ) => {
60- this . _value = this . inputRef ?. value ?? '' ;
62+ private readonly onColorInput = ( event : InputEvent ) => {
63+ const value = ( event . target as HTMLInputElement ) . value ;
64+ this . _value = value ;
65+ if ( this . refInputText ) {
66+ this . refInputText . value = value ;
67+ }
68+ this . controller . onFacade . onInput ( event ) ;
69+ } ;
70+ private readonly onTextInput = ( event : InputEvent ) => {
71+ const value = ( event . target as HTMLInputElement ) . value ;
72+ this . _value = value ;
73+ if ( this . refInputColor ) {
74+ this . refInputColor . value = value ;
75+ }
6176 this . controller . onFacade . onInput ( event ) ;
6277 } ;
63-
6478 @Method ( )
6579 // eslint-disable-next-line @typescript-eslint/require-await
6680 public async getValue ( ) : Promise < string | undefined > {
67- return this . inputRef ?. value ;
81+ return this . refInputText ?. value ;
6882 }
6983
7084 @Method ( )
7185 // eslint-disable-next-line @typescript-eslint/require-await
7286 public async kolFocus ( ) {
73- this . inputRef ?. focus ( ) ;
87+ this . refInputText ?. focus ( ) ;
7488 }
7589
7690 private getFormFieldProps ( ) : FormFieldStateWrapperProps {
7791 return {
7892 state : this . state ,
7993 class : 'kol-input-color' ,
8094 tooltipAlign : this . _tooltipAlign ,
81- onClick : ( ) => this . inputRef ?. focus ( ) ,
95+ onClick : ( ) => this . refInputText ?. focus ( ) ,
8296 alert : this . showAsAlert ( ) ,
8397 } ;
8498 }
8599
86- private getInputProps ( ) : InputStateWrapperProps {
100+ private getInputColorProps ( ) : InputStateWrapperProps {
87101 return {
88- ref : this . catchRef ,
102+ ref : this . catchColorRef ,
89103 type : 'color' ,
90- slot : 'input' ,
104+ name : this . state . _name ? `${ this . state . _name } -color` : undefined ,
105+ 'aria-hidden' : 'true' ,
91106 state : this . state ,
92107 ...this . controller . onFacade ,
108+ onInput : this . onColorInput ,
109+ } ;
110+ }
111+ private getInputTextProps ( ) : InputStateWrapperProps {
112+ return {
113+ ref : this . catchRef ,
114+ type : 'text' ,
115+ name : this . state . _name ? `${ this . state . _name } -text` : undefined ,
116+ state : this . state ,
117+ ...this . controller . onFacade ,
118+ onInput : this . onTextInput ,
93119 onBlur : this . onBlur ,
94120 onFocus : this . onFocus ,
95- onInput : this . onInput ,
96121 } ;
97122 }
98-
99123 public render ( ) : JSX . Element {
100124 return (
101125 < KolFormFieldStateWrapperFc { ...this . getFormFieldProps ( ) } >
102- < KolInputContainerFc state = { this . state } >
103- < KolInputStateWrapperFc { ...this . getInputProps ( ) } />
126+ < KolInputContainerFc state = { this . state } class = "kol-input-color__inputs-wrapper" >
127+ < div class = "kol-input-color__inputs-wrapper" >
128+ < KolInputStateWrapperFc class = "kol-input-color__input kol-input-color__input--color" { ...this . getInputColorProps ( ) } />
129+ < KolInputStateWrapperFc class = "kol-input-color__input kol-input-color__input--text" { ...this . getInputTextProps ( ) } />
130+ </ div >
104131 </ KolInputContainerFc >
105132 </ KolFormFieldStateWrapperFc >
106133 ) ;
0 commit comments