Skip to content

Commit

Permalink
fix(s2): ensure slider respects custom widths and correct the fillOff…
Browse files Browse the repository at this point in the history
…set (#7138)

* fix(s2): ensure slider respects custom widths and correct fillOffset

* remove fieldInput from track styling

* add chromatic story replicating issue

* fix lint
  • Loading branch information
yihuiliao authored Oct 10, 2024
1 parent 0c28454 commit a45e2a5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 12 additions & 0 deletions packages/@react-spectrum/s2/chromatic/Slider.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ FormatOptions.args = {
formatOptions: {style: 'currency', currency: 'JPY'}
};

export const MinMaxValue = (args: any) => (
<div style={{display: 'flex', flexDirection: 'column', alignItems: 'start', gap: 8}}>
<Slider {...args} />
</div>
);

MinMaxValue.args = {
label: 'Size',
minValue: 1,
maxValue: 5
};

export const ContextualHelpExample = (args: any) => (
<div style={{display: 'flex', flexDirection: 'column', alignItems: 'start', gap: 8}}>
<Slider {...args} />
Expand Down
5 changes: 2 additions & 3 deletions packages/@react-spectrum/s2/src/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ const output = style({
});

export let track = style({
...fieldInput(),
gridArea: 'track',
position: 'relative',
width: 'full',
Expand Down Expand Up @@ -379,7 +378,7 @@ export function SliderBase<T extends number | number[]>(props: SliderBaseProps<T
</FieldLabel>
{labelPosition === 'top' && outputValue}
</div>
<div className={style({gridArea: 'input', display: 'inline-flex', alignItems: 'center', gap: {default: 16, size: {L: 20, XL: 24}}})({size})}>
<div className={style({...fieldInput(), display: 'inline-flex', alignItems: 'center', gap: {default: 16, size: {L: 20, XL: 24}}})({size})}>
{props.children}
{labelPosition === 'side' && outputValue}
</div>
Expand Down Expand Up @@ -416,7 +415,7 @@ function Slider(props: SliderProps, ref: FocusableRef<HTMLDivElement>) {
className={track({size, labelPosition, isInForm: !!formContext})}>
{({state, isDisabled}) => {

fillOffset = fillOffset !== undefined ? clamp(fillOffset, state.getThumbMinValue(0), state.getThumbMaxValue(0)) : 0;
fillOffset = fillOffset !== undefined ? clamp(fillOffset, state.getThumbMinValue(0), state.getThumbMaxValue(0)) : state.getThumbMinValue(0);

let fillWidth = state.getThumbPercent(0) - state.getValuePercent(fillOffset);
let isRightOfOffset = fillWidth > 0;
Expand Down

1 comment on commit a45e2a5

@rspbot
Copy link

@rspbot rspbot commented on a45e2a5 Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.