mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 05:29:42 -06:00
Update
This commit is contained in:
parent
d4b4ae0a10
commit
a3b527e0c6
@ -11,9 +11,9 @@ export interface Props extends InputProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const AutoSizeInput = React.forwardRef<HTMLInputElement, Props>((props, ref) => {
|
export const AutoSizeInput = React.forwardRef<HTMLInputElement, Props>((props, ref) => {
|
||||||
const { defaultValue, minWidth = 10, maxWidth, onCommitChange, onKeyDown, onBlur, ...restProps } = props;
|
const { defaultValue = '', minWidth = 10, maxWidth, onCommitChange, onKeyDown, onBlur, ...restProps } = props;
|
||||||
const [value, setValue] = React.useState('');
|
const [value, setValue] = React.useState(defaultValue.toString());
|
||||||
const [inputWidth, setInputWidth] = React.useState(0);
|
const [inputWidth, setInputWidth] = React.useState(minWidth);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setInputWidth(getWidthFor(value.toString(), minWidth, maxWidth));
|
setInputWidth(getWidthFor(value.toString(), minWidth, maxWidth));
|
||||||
@ -21,9 +21,7 @@ export const AutoSizeInput = React.forwardRef<HTMLInputElement, Props>((props, r
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setInputWidth(minWidth);
|
setInputWidth(minWidth);
|
||||||
if (defaultValue) {
|
setValue(defaultValue.toString());
|
||||||
setValue(defaultValue.toString());
|
|
||||||
}
|
|
||||||
}, [minWidth, defaultValue]);
|
}, [minWidth, defaultValue]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user