Skip to content

Commit

Permalink
fix(splitter): correct collapse behavior in RTL mode (ant-design#52501)
Browse files Browse the repository at this point in the history
* fix(splitter): correct collapse behavior in RTL mode

* chore: update rtl logic

* chore: remove unnecessary Optional Chaining

* Update components/splitter/hooks/useResizable.ts

Signed-off-by: afc163 <[email protected]>

---------

Signed-off-by: afc163 <[email protected]>
Co-authored-by: afc163 <[email protected]>
  • Loading branch information
aojunhao123 and afc163 authored Jan 21, 2025
1 parent 3dad73f commit 287d042
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion components/splitter/Splitter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ const Splitter: React.FC<React.PropsWithChildren<SplitterProps>> = (props) => {
useSizes(items, containerSize);

// ====================== Resizable =======================
const resizableInfos = useResizable(items, itemPxSizes);
const resizableInfos = useResizable(items, itemPxSizes, isRTL);

const [onOffsetStart, onOffsetUpdate, onOffsetEnd, onCollapse, movingIndex] = useResize(
items,
resizableInfos,
itemPtgSizes,
containerSize,
updateSizes,
isRTL,
);

// ======================== Events ========================
Expand Down
6 changes: 3 additions & 3 deletions components/splitter/hooks/useResizable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type ResizableInfo = {
endCollapsible: boolean;
};

export default function useResizable(items: ItemType[], pxSizes: number[]) {
export default function useResizable(items: ItemType[], pxSizes: number[], isRTL: boolean) {
return React.useMemo(() => {
const resizeInfos: ResizableInfo[] = [];

Expand Down Expand Up @@ -52,8 +52,8 @@ export default function useResizable(items: ItemType[], pxSizes: number[]) {

resizeInfos[i] = {
resizable: mergedResizable,
startCollapsible: !!startCollapsible,
endCollapsible: !!endCollapsible,
startCollapsible: !!(isRTL ? endCollapsible : startCollapsible),
endCollapsible: !!(isRTL ? startCollapsible : endCollapsible),
};
}

Expand Down
8 changes: 5 additions & 3 deletions components/splitter/hooks/useResize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function useResize(
percentSizes: number[],
containerSize: number | undefined,
updateSizes: (sizes: number[]) => void,
isRTL: boolean,
) {
const limitSizes = items.map((item) => [item.min, item.max]);

Expand Down Expand Up @@ -119,9 +120,10 @@ export default function useResize(
// ======================= Collapse =======================
const onCollapse = (index: number, type: 'start' | 'end') => {
const currentSizes = getPxSizes();
const adjustedType = isRTL ? (type === 'start' ? 'end' : 'start') : type;

const currentIndex = type === 'start' ? index : index + 1;
const targetIndex = type === 'start' ? index + 1 : index;
const currentIndex = adjustedType === 'start' ? index : index + 1;
const targetIndex = adjustedType === 'start' ? index + 1 : index;

const currentSize = currentSizes[currentIndex];
const targetSize = currentSizes[targetIndex];
Expand All @@ -146,7 +148,7 @@ export default function useResize(
const targetCacheCollapsedSize = cacheCollapsedSize.current[index];
const currentCacheCollapsedSize = totalSize - targetCacheCollapsedSize;

const shouldUseCache =
const shouldUseCache =
targetCacheCollapsedSize &&
targetCacheCollapsedSize <= targetSizeMax &&
targetCacheCollapsedSize >= targetSizeMin &&
Expand Down

0 comments on commit 287d042

Please sign in to comment.