diff --git a/packages/grafana-ui/src/components/Input/AutoSizeInput.test.tsx b/packages/grafana-ui/src/components/Input/AutoSizeInput.test.tsx
index e9e7d833bf9..cea1de3eabb 100644
--- a/packages/grafana-ui/src/components/Input/AutoSizeInput.test.tsx
+++ b/packages/grafana-ui/src/components/Input/AutoSizeInput.test.tsx
@@ -1,13 +1,15 @@
-import { screen, render, fireEvent } from '@testing-library/react';
+import { screen, render, fireEvent, waitFor } from '@testing-library/react';
import React from 'react';
+import { measureText } from '../../utils/measureText';
+
import { AutoSizeInput } from './AutoSizeInput';
jest.mock('../../utils/measureText', () => {
// Mocking measureText
- const measureText = (text: string, fontSize: number) => {
+ const measureText = jest.fn().mockImplementation((text: string, fontSize: number) => {
return { width: text.length * fontSize };
- };
+ });
return { measureText };
});
@@ -94,4 +96,26 @@ describe('AutoSizeInput', () => {
expect(onCommitChange).toHaveBeenCalled();
});
+
+ it('should respect min width', async () => {
+ render();
+
+ await waitFor(() => expect(measureText).toHaveBeenCalled());
+
+ expect(getComputedStyle(screen.getByTestId('input-wrapper')).width).toBe('32px');
+ });
+
+ it('should respect max width', async () => {
+ render(
+
+ );
+
+ await waitFor(() => expect(measureText).toHaveBeenCalled());
+
+ expect(getComputedStyle(screen.getByTestId('input-wrapper')).width).toBe('32px');
+ });
});
diff --git a/packages/grafana-ui/src/components/Input/AutoSizeInput.tsx b/packages/grafana-ui/src/components/Input/AutoSizeInput.tsx
index ae9c2873eef..3575f10b485 100644
--- a/packages/grafana-ui/src/components/Input/AutoSizeInput.tsx
+++ b/packages/grafana-ui/src/components/Input/AutoSizeInput.tsx
@@ -63,7 +63,7 @@ function getWidthFor(value: string, minWidth: number, maxWidth: number | undefin
}
if (maxWidth && realWidth > maxWidth) {
- return realWidth;
+ return maxWidth;
}
return realWidth;
diff --git a/public/app/plugins/datasource/prometheus/querybuilder/shared/OperationParamEditor.tsx b/public/app/plugins/datasource/prometheus/querybuilder/shared/OperationParamEditor.tsx
index 7f5eb8e60b4..2e0941d5bfb 100644
--- a/public/app/plugins/datasource/prometheus/querybuilder/shared/OperationParamEditor.tsx
+++ b/public/app/plugins/datasource/prometheus/querybuilder/shared/OperationParamEditor.tsx
@@ -38,6 +38,7 @@ function SimpleInputParamEditor(props: QueryBuilderOperationParamEditorProps) {
minWidth={props.paramDef.minWidth}
placeholder={props.paramDef.placeholder}
title={props.paramDef.description}
+ maxWidth={(props.paramDef.minWidth || 20) * 3}
onCommitChange={(evt) => {
props.onChange(props.index, evt.currentTarget.value);
if (props.paramDef.runQueryOnEnter && evt.type === 'keydown') {