diff --git a/public/app/plugins/datasource/prometheus/querybuilder/shared/AutoSizeInput.tsx b/public/app/plugins/datasource/prometheus/querybuilder/shared/AutoSizeInput.tsx index b5d242a20a1..f3904dcc272 100644 --- a/public/app/plugins/datasource/prometheus/querybuilder/shared/AutoSizeInput.tsx +++ b/public/app/plugins/datasource/prometheus/querybuilder/shared/AutoSizeInput.tsx @@ -11,9 +11,9 @@ export interface Props extends InputProps { } export const AutoSizeInput = React.forwardRef((props, ref) => { - const { defaultValue, minWidth = 10, maxWidth, onCommitChange, onKeyDown, onBlur, ...restProps } = props; - const [value, setValue] = React.useState(''); - const [inputWidth, setInputWidth] = React.useState(0); + const { defaultValue = '', minWidth = 10, maxWidth, onCommitChange, onKeyDown, onBlur, ...restProps } = props; + const [value, setValue] = React.useState(defaultValue.toString()); + const [inputWidth, setInputWidth] = React.useState(minWidth); useEffect(() => { setInputWidth(getWidthFor(value.toString(), minWidth, maxWidth)); @@ -21,9 +21,7 @@ export const AutoSizeInput = React.forwardRef((props, r useEffect(() => { setInputWidth(minWidth); - if (defaultValue) { - setValue(defaultValue.toString()); - } + setValue(defaultValue.toString()); }, [minWidth, defaultValue]); return (