Skip to content

Commit

Permalink
Remove direction from slider context
Browse files Browse the repository at this point in the history
  • Loading branch information
mj12albert committed Jan 3, 2025
1 parent 54bd542 commit 6acd84b
Show file tree
Hide file tree
Showing 11 changed files with 6 additions and 28 deletions.
1 change: 0 additions & 1 deletion packages/react/src/slider/control/SliderControl.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { NOOP } from '../../utils/noop';
const testRootContext: SliderRootContext = {
active: -1,
handleInputChange: NOOP,
direction: 'ltr',
dragging: false,
disabled: false,
getFingerState: () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { NOOP } from '../../utils/noop';
const testRootContext: SliderRootContext = {
active: -1,
handleInputChange: NOOP,
direction: 'ltr',
dragging: false,
disabled: false,
getFingerState: () => ({
Expand Down
3 changes: 1 addition & 2 deletions packages/react/src/slider/indicator/SliderIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ const SliderIndicator = React.forwardRef(function SliderIndicator(
) {
const { render, className, ...otherProps } = props;

const { direction, disabled, orientation, state, percentageValues } = useSliderRootContext();
const { disabled, orientation, state, percentageValues } = useSliderRootContext();

const { getRootProps } = useSliderIndicator({
direction,
disabled,
orientation,
percentageValues,
Expand Down
5 changes: 1 addition & 4 deletions packages/react/src/slider/indicator/useSliderIndicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ export function useSliderIndicator(

export namespace useSliderIndicator {
export interface Parameters
extends Pick<
useSliderRoot.ReturnValue,
'direction' | 'disabled' | 'orientation' | 'percentageValues'
> {}
extends Pick<useSliderRoot.ReturnValue, 'disabled' | 'orientation' | 'percentageValues'> {}

export interface ReturnValue {
getRootProps: (externalProps?: GenericHTMLProps) => GenericHTMLProps;
Expand Down
3 changes: 0 additions & 3 deletions packages/react/src/slider/root/SliderRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useBaseUiId } from '../../utils/useBaseUiId';
import { useComponentRenderer } from '../../utils/useComponentRenderer';
import type { FieldRoot } from '../../field/root/FieldRoot';
import { CompositeList } from '../../composite/list/CompositeList';
import { useDirection } from '../../direction-provider/DirectionContext';
import { sliderStyleHookMapping } from './styleHooks';
import { useSliderRoot } from './useSliderRoot';
import { SliderRootContext } from './SliderRootContext';
Expand Down Expand Up @@ -46,15 +45,13 @@ const SliderRoot = React.forwardRef(function SliderRoot(
} = props;

const id = useBaseUiId(idProp);
const direction = useDirection();

const { labelId, state: fieldState, disabled: fieldDisabled } = useFieldRootContext();
const disabled = fieldDisabled || disabledProp;

const { getRootProps, ...slider } = useSliderRoot({
'aria-labelledby': ariaLabelledby ?? labelId ?? '',
defaultValue,
direction,
disabled,
id: id ?? '',
largeStep,
Expand Down
12 changes: 2 additions & 10 deletions packages/react/src/slider/root/useSliderRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useEventCallback } from '../../utils/useEventCallback';
import { useForkRef } from '../../utils/useForkRef';
import { valueToPercent } from '../../utils/valueToPercent';
import type { CompositeMetadata } from '../../composite/list/CompositeList';
import type { TextDirection } from '../../direction-provider/DirectionContext';
import { useDirection } from '../../direction-provider/DirectionContext';
import { useField } from '../../field/useField';
import { useFieldRootContext } from '../../field/root/FieldRootContext';
import { useFieldControlValidation } from '../../field/control/useFieldControlValidation';
Expand Down Expand Up @@ -109,7 +109,6 @@ export function useSliderRoot(parameters: useSliderRoot.Parameters): useSliderRo
const {
'aria-labelledby': ariaLabelledby,
defaultValue,
direction = 'ltr',
disabled = false,
id,
largeStep = 10,
Expand All @@ -125,6 +124,7 @@ export function useSliderRoot(parameters: useSliderRoot.Parameters): useSliderRo
value: valueProp,
} = parameters;

const direction = useDirection();
const { setControlId, setTouched, setDirty, validityData } = useFieldRootContext();

const {
Expand Down Expand Up @@ -375,7 +375,6 @@ export function useSliderRoot(parameters: useSliderRoot.Parameters): useSliderRo
getRootProps,
'aria-labelledby': ariaLabelledby,
active,
direction,
disabled,
dragging,
getFingerState,
Expand Down Expand Up @@ -404,7 +403,6 @@ export function useSliderRoot(parameters: useSliderRoot.Parameters): useSliderRo
getRootProps,
active,
ariaLabelledby,
direction,
disabled,
dragging,
getFingerState,
Expand Down Expand Up @@ -460,11 +458,6 @@ export namespace useSliderRoot {
* The default value. Use when the component is not controlled.
*/
defaultValue?: number | readonly number[];
/**
* Sets the direction. For right-to-left languages, the lowest value is on the right-hand side.
* @default 'ltr'
*/
direction: TextDirection;
/**
* Whether the component should ignore user interaction.
* @default false
Expand Down Expand Up @@ -555,7 +548,6 @@ export namespace useSliderRoot {
event: React.KeyboardEvent | React.ChangeEvent,
) => void;
dragging: boolean;
direction: TextDirection;
disabled: boolean;
getFingerState: (
fingerPosition: FingerPosition | null,
Expand Down
1 change: 0 additions & 1 deletion packages/react/src/slider/thumb/SliderThumb.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { NOOP } from '../../utils/noop';
const testRootContext: SliderRootContext = {
active: -1,
handleInputChange: NOOP,
direction: 'ltr',
dragging: false,
disabled: false,
getFingerState: () => ({
Expand Down
2 changes: 0 additions & 2 deletions packages/react/src/slider/thumb/SliderThumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const SliderThumb = React.forwardRef(function SliderThumb(
active: activeIndex,
'aria-labelledby': ariaLabelledby,
handleInputChange,
direction,
disabled: contextDisabled,
format = null,
largeStep,
Expand Down Expand Up @@ -91,7 +90,6 @@ const SliderThumb = React.forwardRef(function SliderThumb(
'aria-labelledby': ariaLabelledby ?? '',
'aria-valuetext': ariaValuetext ?? '',
handleInputChange,
direction,
disabled: disabledProp || contextDisabled,
format,
getAriaLabel: getAriaLabelProp ?? null,
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/slider/thumb/useSliderThumb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
END,
} from '../../composite/composite';
import { useCompositeListItem } from '../../composite/list/useCompositeListItem';
import { useDirection } from '../../direction-provider/DirectionContext';
import { useFieldControlValidation } from '../../field/control/useFieldControlValidation';
import { useFieldRootContext } from '../../field/root/FieldRootContext';
import { getSliderValue } from '../utils/getSliderValue';
Expand Down Expand Up @@ -60,7 +61,6 @@ export function useSliderThumb(parameters: useSliderThumb.Parameters): useSlider
'aria-labelledby': ariaLabelledby,
'aria-valuetext': ariaValuetext,
handleInputChange,
direction,
disabled,
format,
getAriaLabel = null,
Expand All @@ -80,6 +80,7 @@ export function useSliderThumb(parameters: useSliderThumb.Parameters): useSlider
values: sliderValues,
} = parameters;

const direction = useDirection();
const { setTouched } = useFieldRootContext();
const {
getInputValidationProps,
Expand Down Expand Up @@ -316,7 +317,6 @@ export namespace useSliderThumb {
| 'active'
| 'aria-labelledby'
| 'handleInputChange'
| 'direction'
| 'largeStep'
| 'max'
| 'min'
Expand Down
1 change: 0 additions & 1 deletion packages/react/src/slider/track/SliderTrack.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { NOOP } from '../../utils/noop';
const testRootContext: SliderRootContext = {
active: -1,
handleInputChange: NOOP,
direction: 'ltr',
dragging: false,
disabled: false,
getFingerState: () => ({
Expand Down
1 change: 0 additions & 1 deletion packages/react/src/slider/value/SliderValue.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { NOOP } from '../../utils/noop';
const testRootContext: SliderRootContext = {
active: -1,
handleInputChange: NOOP,
direction: 'ltr',
dragging: false,
disabled: false,
getFingerState: () => ({
Expand Down

0 comments on commit 6acd84b

Please sign in to comment.