11import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
2- import {
3- Directive ,
4- ElementRef ,
5- EventEmitter ,
6- Inject ,
7- Input ,
8- OnChanges ,
9- Optional ,
10- Output ,
11- Renderer2 ,
12- Self
13- } from '@angular/core' ;
2+ import { Directive , ElementRef , EventEmitter , Inject , Input , OnChanges , Optional , Output , Self } from '@angular/core' ;
143import { NgControl } from '@angular/forms' ;
154import { COMMA , ENTER , SEMICOLON , SPACE , TAB } from '@koobiq/cdk/keycodes' ;
165import { KbqAutocompleteTrigger } from '@koobiq/components/autocomplete' ;
17- import { isBoolean } from '@koobiq/components/core' ;
6+ import { isBoolean , KbqFieldSizingContent } from '@koobiq/components/core' ;
187import { KbqTrim } from '@koobiq/components/form-field' ;
198import { KBQ_TAGS_DEFAULT_OPTIONS , KbqTagsDefaultOptions } from './tag-default-options' ;
209import { KbqTagList } from './tag-list.component' ;
@@ -63,7 +52,8 @@ let nextUniqueId = 0;
6352 '(focus)' : 'onFocus()' ,
6453 '(input)' : 'onInput()' ,
6554 '(paste)' : 'onPaste($event)'
66- }
55+ } ,
56+ hostDirectives : [ KbqFieldSizingContent ]
6757} )
6858export class KbqTagInput implements KbqTagTextControl , OnChanges {
6959 /** Whether the control is focused. */
@@ -160,25 +150,25 @@ export class KbqTagInput implements KbqTagTextControl, OnChanges {
160150 return ! this . inputElement . value ;
161151 }
162152
153+ /**
154+ * @docs -private
155+ *
156+ * @deprecated Unused. Will be removed in next major release.
157+ */
163158 countOfSymbolsForUpdateWidth : number = 3 ;
164159
165- private oneSymbolWidth : number ;
166-
167160 /** The native input element to which this directive is attached. */
168161 private inputElement : HTMLInputElement ;
169162
170163 constructor (
171164 private elementRef : ElementRef < HTMLInputElement > ,
172- private renderer : Renderer2 ,
173165 @Inject ( KBQ_TAGS_DEFAULT_OPTIONS ) private defaultOptions : KbqTagsDefaultOptions ,
174166 @Optional ( ) @Self ( ) private trimDirective : KbqTrim ,
175167 @Optional ( ) @Self ( ) public ngControl : NgControl ,
176168 @Optional ( ) @Self ( ) public autocompleteTrigger ?: KbqAutocompleteTrigger
177169 ) {
178170 this . inputElement = this . elementRef . nativeElement as HTMLInputElement ;
179171
180- this . setDefaultInputWidth ( ) ;
181-
182172 this . _separators = this . defaultOptions . separators || KbqTagInputDefaultSeparators ;
183173 this . _addOnPaste = isBoolean ( this . defaultOptions . addOnPaste ) ? this . defaultOptions . addOnPaste : true ;
184174 }
@@ -231,7 +221,6 @@ export class KbqTagInput implements KbqTagTextControl, OnChanges {
231221 if ( this . distinct && this . hasDuplicates ) return ;
232222
233223 this . tagEnd . emit ( { input : this . inputElement , value : this . trimValue ( this . inputElement . value ) } ) ;
234- this . updateInputWidth ( ) ;
235224 }
236225 }
237226
@@ -242,7 +231,6 @@ export class KbqTagInput implements KbqTagTextControl, OnChanges {
242231 }
243232
244233 onInput ( ) {
245- this . updateInputWidth ( ) ;
246234 // Let tag list know whenever the value changes.
247235 this . _tagList . stateChanges . next ( ) ;
248236 }
@@ -277,25 +265,16 @@ export class KbqTagInput implements KbqTagTextControl, OnChanges {
277265 . filter ( ( item ) => ! tagValues . includes ( item ) )
278266 . forEach ( ( item ) => this . tagEnd . emit ( { input : this . inputElement , value : item } ) ) ;
279267
280- this . updateInputWidth ( ) ;
281-
282268 $event . preventDefault ( ) ;
283269 $event . stopPropagation ( ) ;
284270 }
285271
286- updateInputWidth ( ) : void {
287- const length = this . inputElement . value . length ;
288-
289- this . renderer . setStyle ( this . inputElement , 'max-width' , 0 ) ;
290- this . oneSymbolWidth = this . inputElement . scrollWidth / length ;
291- this . renderer . setStyle ( this . inputElement , 'max-width' , '' ) ;
292-
293- if ( length > this . countOfSymbolsForUpdateWidth ) {
294- this . renderer . setStyle ( this . inputElement , 'width' , `${ length * this . oneSymbolWidth } px` ) ;
295- } else {
296- this . setDefaultInputWidth ( ) ;
297- }
298- }
272+ /**
273+ * @docs -private
274+ *
275+ * @deprecated Unused. Will be removed in next major release.
276+ */
277+ updateInputWidth ( ) : void { }
299278
300279 /** @docs -private */
301280 onFocus ( ) : void {
@@ -333,10 +312,6 @@ export class KbqTagInput implements KbqTagTextControl, OnChanges {
333312 return ! ! this . ngControl ;
334313 }
335314
336- private setDefaultInputWidth ( ) {
337- this . renderer . setStyle ( this . inputElement , 'width' , '30px' ) ;
338- }
339-
340315 /** Checks whether a keycode is one of the configured separators. */
341316 private isSeparatorKey ( event : KeyboardEvent ) {
342317 return this . separators . some ( ( separator ) => separator . key === event . key && ! event . shiftKey ) ;
0 commit comments