Skip to content

Commit 358480c

Browse files
authored
fix(s2): Fix ColorLoupe position in ColorSlider for RTL locales (#8894)
* fix(s2): Fix ColorLoupe position in ColorSlider for RTL locales * Fix ColorArea in RTL locales
1 parent 84ff482 commit 358480c

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import {
1414
ColorArea as AriaColorArea,
1515
ColorAreaProps as AriaColorAreaProps,
16-
ContextValue
16+
ContextValue,
17+
useLocale
1718
} from 'react-aria-components';
1819
import {ColorHandle} from './ColorHandle';
1920
import {createContext, forwardRef} from 'react';
@@ -34,6 +35,7 @@ export const ColorArea = forwardRef(function ColorArea(props: ColorAreaProps, re
3435
[props, ref] = useSpectrumContextProps(props, ref, ColorAreaContext);
3536
let {UNSAFE_className = '', UNSAFE_style, styles} = props;
3637
let containerRef = useDOMRef(ref);
38+
let {direction} = useLocale();
3739
return (
3840
<AriaColorArea
3941
{...props}
@@ -67,7 +69,13 @@ export const ColorArea = forwardRef(function ColorArea(props: ColorAreaProps, re
6769
{({state}) =>
6870
(<ColorHandle
6971
containerRef={containerRef}
70-
getPosition={() => state.getThumbPosition()} />)
72+
getPosition={() => {
73+
let {x, y} = state.getThumbPosition();
74+
return {
75+
x: direction === 'ltr' ? x : 1 - x,
76+
y
77+
};
78+
}} />)
7179
}
7280
</AriaColorArea>
7381
);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const ColorSlider = forwardRef(function ColorSlider(props: ColorSliderPro
4141
let {UNSAFE_className = '', UNSAFE_style, styles} = props;
4242
let containerRef = useDOMRef(ref);
4343
let trackRef = useRef(null);
44-
let {locale} = useLocale();
44+
let {direction, locale} = useLocale();
4545

4646
return (
4747
<AriaColorSlider
@@ -133,7 +133,8 @@ export const ColorSlider = forwardRef(function ColorSlider(props: ColorSliderPro
133133
<ColorHandle
134134
containerRef={trackRef}
135135
getPosition={() => {
136-
let x = state.orientation === 'horizontal' ? state.getThumbPercent(0) : 0.5;
136+
let thumbLeft = direction === 'ltr' ? state.getThumbPercent(0) : 1 - state.getThumbPercent(0);
137+
let x = state.orientation === 'horizontal' ? thumbLeft : 0.5;
137138
let y = state.orientation === 'horizontal' ? 0.5 : 1 - state.getThumbPercent(0);
138139
return {x, y};
139140
}} />

0 commit comments

Comments
 (0)