Skip to content

Commit 3b0b5e2

Browse files
author
Kenan Yıldız
committed
feat(keyboard): flag keyboard resizes as user interactions (#716)
Keyboard separator adjustments (arrow keys, Home/End, Enter collapse/expand) originate from a real DOM event on the separator, so they are user interactions just like pointer drags. Pass isUserInteraction: true from adjustLayoutForSeparator (the sole keyboard dispatch site, reached only from onDocumentKeyDown). Imperative API calls (setLayout, etc.) remain false: the library cannot attribute the caller's intent there. Update the onLayoutChanged JSDoc to state the pointer+keyboard vs. library-driven boundary, and the keyboard test to expect true.
1 parent ca7b0ae commit 3b0b5e2

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

lib/components/group/Group.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ describe("Group", () => {
101101
panelRef: RefObject<PanelImperativeHandle | null>;
102102
}) => Promise<void>,
103103
expectedLayout: Layout,
104-
// `true` when the callback simulates a pointer drag (see #716);
105-
// `false` for keyboard / imperative API / mount which fall under the
106-
// "library-driven" bucket of the new flag.
104+
// `true` when the callback simulates a direct separator manipulation —
105+
// a pointer drag or a keyboard resize (see #716); `false` for imperative
106+
// API / mount which fall under the "library-driven" bucket of the flag.
107107
expectedIsUserInteraction: boolean
108108
) {
109109
setElementBoundsFunction((element) => {
@@ -197,7 +197,7 @@ describe("Group", () => {
197197
left: 55,
198198
right: 45
199199
},
200-
false
200+
true
201201
);
202202
});
203203

lib/components/group/types.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ export type GroupProps = HTMLAttributes<HTMLDivElement> & {
161161
* This method is recommended when saving layouts to some storage api.
162162
*
163163
* The second argument `isUserInteraction` is `true` when the change was
164-
* caused by the user releasing a pointer drag, and `false` for every other
165-
* source (programmatic `setLayout`, constraint recompute, default-size
166-
* change, initial mount). See #716.
164+
* caused by the user directly manipulating a separator — releasing a pointer
165+
* drag or pressing a resize key (arrow keys, Home/End, Enter). It is `false`
166+
* for every other source (programmatic `setLayout` and other imperative API
167+
* calls, constraint recompute, default-size change, initial mount), because
168+
* the library cannot attribute the caller's intent there. See #716.
167169
*/
168170
onLayoutChanged?: (layout: Layout, isUserInteraction: boolean) => void;
169171

lib/global/utils/adjustLayoutForSeparator.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,20 @@ export function adjustLayoutForSeparator(
4343
});
4444

4545
if (!layoutsEqual(prevLayout, nextLayout)) {
46-
updateMountedGroup(group, {
47-
defaultLayoutDeferred: groupState.defaultLayoutDeferred,
48-
derivedPanelConstraints: groupState.derivedPanelConstraints,
49-
groupSize: groupState.groupSize,
50-
layout: nextLayout,
51-
separatorToPanels: groupState.separatorToPanels
52-
});
46+
updateMountedGroup(
47+
group,
48+
{
49+
defaultLayoutDeferred: groupState.defaultLayoutDeferred,
50+
derivedPanelConstraints: groupState.derivedPanelConstraints,
51+
groupSize: groupState.groupSize,
52+
layout: nextLayout,
53+
separatorToPanels: groupState.separatorToPanels
54+
},
55+
// Keyboard resizes (arrow keys, Home/End, Enter collapse/expand) originate
56+
// from a real DOM event on the separator, so they are user interactions
57+
// just like pointer drags. This function is only reached from
58+
// onDocumentKeyDown. See #716.
59+
{ isUserInteraction: true }
60+
);
5361
}
5462
}

0 commit comments

Comments
 (0)