Skip to content

Commit

Permalink
Merge pull request #21459 from gitstart/fix/range-control
Browse files Browse the repository at this point in the history
Controls: Fix glitchy range control
  • Loading branch information
JReinhold authored Mar 16, 2023
2 parents ebc763a + 78b0e73 commit f751229
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions code/ui/blocks/src/controls/Range.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ const RangeLabel = styled.span({
fontVariantNumeric: 'tabular-nums',
});

const RangeCurrentAndMaxLabel = styled(RangeLabel)<{
numberOFDecimalsPlaces: number;
max: number;
}>(({ numberOFDecimalsPlaces, max }) => ({
// Fixed width of "current / max" label to avoid slider width changes
// 3 = size of separator " / "
width: `${numberOFDecimalsPlaces + max.toString().length * 2 + 3}ch`,
textAlign: 'right',
flexShrink: 0,
}));

const RangeWrapper = styled.div({
display: 'flex',
alignItems: 'center',
Expand Down Expand Up @@ -208,9 +219,9 @@ export const RangeControl: FC<RangeProps> = ({
onChange={handleChange}
{...{ name, value, min, max, step, onFocus, onBlur }}
/>
<RangeLabel>
<RangeCurrentAndMaxLabel numberOFDecimalsPlaces={numberOFDecimalsPlaces} max={max}>
{`${hasValue ? value.toFixed(numberOFDecimalsPlaces) : '--'}`} / {max}
</RangeLabel>
</RangeCurrentAndMaxLabel>
</RangeWrapper>
);
};

0 comments on commit f751229

Please sign in to comment.