diff --git a/packages/grafana-ui/src/components/UnitPicker/UnitPicker.tsx b/packages/grafana-ui/src/components/UnitPicker/UnitPicker.tsx index 4a85f410839..169e493cd8f 100644 --- a/packages/grafana-ui/src/components/UnitPicker/UnitPicker.tsx +++ b/packages/grafana-ui/src/components/UnitPicker/UnitPicker.tsx @@ -26,15 +26,23 @@ export class UnitPicker extends PureComponent { render() { const { value, width } = this.props; + // Set the current selection + let current: SelectableValue | undefined = undefined; + + // All units const unitGroups = getValueFormats(); // Need to transform the data structure to work well with Select const groupOptions = unitGroups.map(group => { const options = group.submenu.map(unit => { - return { + const sel = { label: unit.text, value: unit.value, }; + if (unit.value === value) { + current = sel; + } + return sel; }); return { @@ -43,14 +51,15 @@ export class UnitPicker extends PureComponent { }; }); - const valueOption = groupOptions.map(group => { - return group.options.find(option => option.value === value); - }); + // Show the custom unit + if (value && !current) { + current = { value, label: value }; + } return (