From 6f468c670a7657b5daf38d62f7e44a4553727fd8 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Fri, 6 Dec 2019 11:50:45 +0100 Subject: [PATCH] UI: Segment Input change (#20925) * Add input segment * Rename story * Cleanup * Fix lint error * More cleanup * Use measure text util * Keep value in local state --- .../src/components/Segment/SegmentInput.tsx | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/grafana-ui/src/components/Segment/SegmentInput.tsx b/packages/grafana-ui/src/components/Segment/SegmentInput.tsx index ebc026ff0e1..b046f842c57 100644 --- a/packages/grafana-ui/src/components/Segment/SegmentInput.tsx +++ b/packages/grafana-ui/src/components/Segment/SegmentInput.tsx @@ -12,18 +12,21 @@ export interface SegmentInputProps extends SegmentProps { const FONT_SIZE = 14; export function SegmentInput({ - value, + value: initialValue, onChange, Component, className, }: React.PropsWithChildren>) { const ref = useRef(null); - const [inputWidth, setInputWidth] = useState(measureText(value.toString(), FONT_SIZE).width); + const [value, setValue] = useState(initialValue); + const [inputWidth, setInputWidth] = useState(measureText(initialValue.toString(), FONT_SIZE).width); const [Label, , expanded, setExpanded] = useExpandableLabel(false); useClickAway(ref, () => setExpanded(false)); if (!expanded) { - return