@@ -59,6 +59,20 @@ export interface ITagInputProps extends IntentProps, Props {
5959 */
6060 addOnPaste ?: boolean ;
6161
62+ /**
63+ * Whether the component should automatically resize as a user types in the text input.
64+ * This will have no effect when `fill={true}`.
65+ *
66+ * @default false
67+ */
68+ autoResize ?: boolean ;
69+
70+ /**
71+ * Optional child elements which will be rendered between the selected tags and
72+ * the text input. Rendering children is usually unnecessary.
73+ *
74+ * @default undefined
75+ */
6276 children ?: React . ReactNode ;
6377
6478 /**
@@ -76,6 +90,7 @@ export interface ITagInputProps extends IntentProps, Props {
7690 /**
7791 * React props to pass to the `<input>` element.
7892 * Note that `ref` and `key` are not supported here; use `inputRef` below.
93+ * Also note that `inputProps.style.width` will be overriden if `autoResize={true}`.
7994 */
8095 inputProps ?: HTMLInputProps ;
8196
@@ -204,6 +219,7 @@ export class TagInput extends AbstractPureComponent2<TagInputProps, ITagInputSta
204219 public static defaultProps : Partial < TagInputProps > = {
205220 addOnBlur : false ,
206221 addOnPaste : true ,
222+ autoResize : false ,
207223 inputProps : { } ,
208224 separator : / [ , \n \r ] / ,
209225 tagProps : { } ,
@@ -233,7 +249,8 @@ export class TagInput extends AbstractPureComponent2<TagInputProps, ITagInputSta
233249 private handleRef : React . Ref < HTMLInputElement > = refHandler ( this , "inputElement" , this . props . inputRef ) ;
234250
235251 public render ( ) {
236- const { className, disabled, fill, inputProps, intent, large, leftIcon, placeholder, values } = this . props ;
252+ const { autoResize, className, disabled, fill, inputProps, intent, large, leftIcon, placeholder, values } =
253+ this . props ;
237254
238255 const classes = classNames (
239256 Classes . INPUT ,
@@ -253,6 +270,21 @@ export class TagInput extends AbstractPureComponent2<TagInputProps, ITagInputSta
253270 const isSomeValueDefined = values . some ( val => ! ! val ) ;
254271 const resolvedPlaceholder = placeholder == null || isSomeValueDefined ? inputProps ?. placeholder : placeholder ;
255272
273+ // final props that may be sent to <input> or <ResizableInput>
274+ const resolvedInputProps = {
275+ value : this . state . inputValue ,
276+ ...inputProps ,
277+ className : classNames ( Classes . INPUT_GHOST , inputProps ?. className ) ,
278+ disabled,
279+ onChange : this . handleInputChange ,
280+ onFocus : this . handleInputFocus ,
281+ onKeyDown : this . handleInputKeyDown ,
282+ onKeyUp : this . handleInputKeyUp ,
283+ onPaste : this . handleInputPaste ,
284+ placeholder : resolvedPlaceholder ,
285+ ref : this . handleRef ,
286+ } ;
287+
256288 return (
257289 < div className = { classes } onBlur = { this . handleContainerBlur } onClick = { this . handleContainerClick } >
258290 < Icon
@@ -263,19 +295,7 @@ export class TagInput extends AbstractPureComponent2<TagInputProps, ITagInputSta
263295 < div className = { Classes . TAG_INPUT_VALUES } >
264296 { values . map ( this . maybeRenderTag ) }
265297 { this . props . children }
266- < ResizableInput
267- value = { this . state . inputValue }
268- { ...inputProps }
269- onFocus = { this . handleInputFocus }
270- onChange = { this . handleInputChange }
271- onKeyDown = { this . handleInputKeyDown }
272- onKeyUp = { this . handleInputKeyUp }
273- onPaste = { this . handleInputPaste }
274- placeholder = { resolvedPlaceholder }
275- ref = { this . handleRef }
276- className = { classNames ( Classes . INPUT_GHOST , inputProps ?. className ) }
277- disabled = { disabled }
278- />
298+ { autoResize ? < ResizableInput { ...resolvedInputProps } /> : < input { ...resolvedInputProps } /> }
279299 </ div >
280300 { this . props . rightElement }
281301 </ div >
0 commit comments