Skip to content

Commit a45e2a5

Browse files
authored
fix(s2): ensure slider respects custom widths and correct the fillOffset (#7138)
* fix(s2): ensure slider respects custom widths and correct fillOffset * remove fieldInput from track styling * add chromatic story replicating issue * fix lint
1 parent 0c28454 commit a45e2a5

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/@react-spectrum/s2/chromatic/Slider.stories.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ FormatOptions.args = {
6868
formatOptions: {style: 'currency', currency: 'JPY'}
6969
};
7070

71+
export const MinMaxValue = (args: any) => (
72+
<div style={{display: 'flex', flexDirection: 'column', alignItems: 'start', gap: 8}}>
73+
<Slider {...args} />
74+
</div>
75+
);
76+
77+
MinMaxValue.args = {
78+
label: 'Size',
79+
minValue: 1,
80+
maxValue: 5
81+
};
82+
7183
export const ContextualHelpExample = (args: any) => (
7284
<div style={{display: 'flex', flexDirection: 'column', alignItems: 'start', gap: 8}}>
7385
<Slider {...args} />

packages/@react-spectrum/s2/src/Slider.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ const output = style({
148148
});
149149

150150
export let track = style({
151-
...fieldInput(),
152151
gridArea: 'track',
153152
position: 'relative',
154153
width: 'full',
@@ -379,7 +378,7 @@ export function SliderBase<T extends number | number[]>(props: SliderBaseProps<T
379378
</FieldLabel>
380379
{labelPosition === 'top' && outputValue}
381380
</div>
382-
<div className={style({gridArea: 'input', display: 'inline-flex', alignItems: 'center', gap: {default: 16, size: {L: 20, XL: 24}}})({size})}>
381+
<div className={style({...fieldInput(), display: 'inline-flex', alignItems: 'center', gap: {default: 16, size: {L: 20, XL: 24}}})({size})}>
383382
{props.children}
384383
{labelPosition === 'side' && outputValue}
385384
</div>
@@ -416,7 +415,7 @@ function Slider(props: SliderProps, ref: FocusableRef<HTMLDivElement>) {
416415
className={track({size, labelPosition, isInForm: !!formContext})}>
417416
{({state, isDisabled}) => {
418417

419-
fillOffset = fillOffset !== undefined ? clamp(fillOffset, state.getThumbMinValue(0), state.getThumbMaxValue(0)) : 0;
418+
fillOffset = fillOffset !== undefined ? clamp(fillOffset, state.getThumbMinValue(0), state.getThumbMaxValue(0)) : state.getThumbMinValue(0);
420419

421420
let fillWidth = state.getThumbPercent(0) - state.getValuePercent(fillOffset);
422421
let isRightOfOffset = fillWidth > 0;

0 commit comments

Comments
 (0)