Skip to content

Commit

Permalink
Don't read "direction" from the document; use inherited style instead
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn committed Oct 27, 2024
1 parent 95d2f21 commit 6b3a95b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/react-resizable-panels/src/PanelGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ export type PanelGroupProps = Omit<
storage?: PanelGroupStorage;
style?: CSSProperties;
tagName?: keyof HTMLElementTagNameMap;

// Better TypeScript hinting
dir?: "auto" | "ltr" | "rtl" | undefined;
}>;

const debounceMap: {
Expand Down Expand Up @@ -613,8 +616,19 @@ function PanelGroupWithForwardedRef({
}, []);

const registerResizeHandle = useCallback((dragHandleId: string) => {
let isRTL = false;

const panelGroupElement = panelGroupElementRef.current;
if (panelGroupElement) {
const style = window.getComputedStyle(panelGroupElement, null);
if (style.getPropertyValue("direction") === "rtl") {
isRTL = true;
}
}

return function resizeHandler(event: ResizeEvent) {
event.preventDefault();

const panelGroupElement = panelGroupElementRef.current;
if (!panelGroupElement) {
return () => null;
Expand Down Expand Up @@ -646,9 +660,9 @@ function PanelGroupWithForwardedRef({
panelGroupElement
);

// Support RTL layouts
const isHorizontal = direction === "horizontal";
if (document.dir === "rtl" && isHorizontal) {

if (isHorizontal && isRTL) {
delta = -delta;
}

Expand Down

0 comments on commit 6b3a95b

Please sign in to comment.