From f8509273cbe9838d60efd7693bf6c56d7902e61e Mon Sep 17 00:00:00 2001 From: Josh Hunt Date: Thu, 6 Feb 2025 16:14:38 +0000 Subject: [PATCH] Slider: Fix text input box being too wide (#100138) * Fix Input width from className not being respected * Also use width prop in Slider --- packages/grafana-ui/src/components/Input/Input.tsx | 10 ++++++---- packages/grafana-ui/src/components/Slider/Slider.tsx | 1 + packages/grafana-ui/src/components/Slider/styles.ts | 1 - 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/grafana-ui/src/components/Input/Input.tsx b/packages/grafana-ui/src/components/Input/Input.tsx index 09b113cf76b..563adfa9772 100644 --- a/packages/grafana-ui/src/components/Input/Input.tsx +++ b/packages/grafana-ui/src/components/Input/Input.tsx @@ -60,19 +60,21 @@ export const Input = forwardRef((props, ref) => { // if a better solution is found. const isInAutoSizeInput = useContext(AutoSizeInputContext); const accessoriesWidth = (prefixRect.width || 0) + (suffixRect.width || 0); - const finalWidth = isInAutoSizeInput && width ? width + accessoriesWidth / 8 : width; + const autoSizeWidth = isInAutoSizeInput && width ? width + accessoriesWidth / 8 : undefined; const theme = useTheme2(); // Don't pass the width prop, as this causes an unnecessary amount of Emotion calls when auto sizing - const styles = getInputStyles({ theme, invalid: !!invalid }); + const styles = getInputStyles({ theme, invalid: !!invalid, width: autoSizeWidth ? undefined : width }); const suffix = suffixProp || (loading && ); return (
{!!addonBefore &&
{addonBefore}
} @@ -130,7 +132,7 @@ export const getInputStyles = stylesFactory(({ theme, invalid = false, width }: css({ label: 'input-wrapper', display: 'flex', - width: width ? theme.spacing(width) : '100%', // Not used in Input, as this causes performance issues with auto sizing + width: width ? theme.spacing(width) : '100%', height: theme.spacing(theme.components.height.md), borderRadius: theme.shape.radius.default, '&:hover': { diff --git a/packages/grafana-ui/src/components/Slider/Slider.tsx b/packages/grafana-ui/src/components/Slider/Slider.tsx index 5da049a3d0c..c677d402dc9 100644 --- a/packages/grafana-ui/src/components/Slider/Slider.tsx +++ b/packages/grafana-ui/src/components/Slider/Slider.tsx @@ -109,6 +109,7 @@ export const Slider = ({