Skip to content

Commit bf924aa

Browse files
committed
feat(List): a row tapped to push stays selected until the pop deselects it
UIKit keeps the table row that pushed a screen selected while that screen covers it; the deselect starts with the pop and runs inside the transition, linearly over its 0.35 s, so an interactive pop scrubs it with its progress, and a cancelled pop selects the row again at once. holdSelection(target) (core/utils, for a navigation stack) finds the List, Item or TreeList row under the activation, marks it held (the press layer at full strength, the dividers around it hidden), and returns a handle: animate() plays the in-transition deselect or a given spring or curve on the layer's opacity through the motion foundation's animator (Web Animations on the row's ::before, on the caller's clock), setProgress() follows a finger, presentation() answers from the closed-form curve, end() completes or restores, focus() returns focus to the row's control. The touch press controller now leaves a state it did not write alone. Rows carry the cell press profile in their marker. A Selection Hold story drives it with buttons standing in for a stack.
1 parent c2edd43 commit bf924aa

16 files changed

Lines changed: 1449 additions & 221 deletions

‎.changeset/list-selection-hold.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[feat] A list row tapped to push can stay selected while the pushed screen covers it, then deselect as the screen pops, as a UIKit table row does. `holdSelection(event.target)` from `@astryxdesign/core/utils` holds the `ListItem`, `Item` or `TreeList` row under an activation and returns a handle a navigation drives: `animate(1)` runs UIKit's in-transition deselect, `setProgress` follows an interactive pop, `end(false)` selects the row again after a cancelled pop, and `focus()` returns focus to the row. The deselect runs on the compositor. A divided list keeps the dividers around the held row hidden.
6+
7+
@vjeux

‎apps/storybook/stories/List.stories.tsx‎

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @position Storybook demonstrations for List consumers
88
*/
99

10-
import {useState} from 'react';
10+
import {useRef, useState, type MouseEvent} from 'react';
1111
import * as stylex from '@stylexjs/stylex';
1212
import type {Meta, StoryObj} from '@storybook/react';
1313
import {List, ListItem} from '@astryxdesign/core/List';
@@ -18,6 +18,11 @@ import {Icon} from '@astryxdesign/core/Icon';
1818
import {Switch} from '@astryxdesign/core/Switch';
1919
import {Heading, Text} from '@astryxdesign/core/Text';
2020
import {VStack} from '@astryxdesign/core/Layout';
21+
import {Button} from '@astryxdesign/core/Button';
22+
import {
23+
holdSelection,
24+
type SelectionHold as RowSelectionHold,
25+
} from '@astryxdesign/core/utils';
2126
import {
2227
Cog6ToothIcon,
2328
BellIcon,
@@ -408,3 +413,81 @@ export const HeaderInFlexParent: Story = {
408413
},
409414
},
410415
};
416+
417+
function SelectionHoldDemo() {
418+
const hold = useRef<RowSelectionHold | null>(null);
419+
const [open, setOpen] = useState<string | null>(null);
420+
const [progress, setProgress] = useState(0);
421+
const push = (label: string) => (event: MouseEvent) => {
422+
// In the same task as the activation that pushes.
423+
hold.current = holdSelection(event.target);
424+
setProgress(0);
425+
setOpen(label);
426+
};
427+
const settle = async (to: 0 | 1) => {
428+
const current = hold.current;
429+
await current?.animate(to);
430+
if (to === 1) {
431+
setOpen(null);
432+
current?.end(true);
433+
current?.focus({preventScroll: true});
434+
hold.current = null;
435+
} else {
436+
current?.end(false);
437+
setProgress(0);
438+
}
439+
};
440+
return (
441+
<VStack gap={4}>
442+
<List hasDividers>
443+
{['Inbox', 'Sent', 'Drafts'].map(label => (
444+
<ListItem
445+
key={label}
446+
label={label}
447+
onClick={push(label)}
448+
endContent={<Icon icon={ChevronRightIcon} />}
449+
/>
450+
))}
451+
</List>
452+
{open != null && (
453+
<VStack gap={2} data-testid="pushed-screen">
454+
<Text type="label">{open} (pushed)</Text>
455+
<Button label="Back" onClick={() => void settle(1)} />
456+
<label>
457+
Pop progress
458+
<input
459+
type="range"
460+
min={0}
461+
max={1}
462+
step={0.01}
463+
value={progress}
464+
onChange={event => {
465+
const value = Number(event.target.value);
466+
setProgress(value);
467+
hold.current?.setProgress(value);
468+
}}
469+
/>
470+
</label>
471+
<Button label="Finish pop" onClick={() => void settle(1)} />
472+
<Button label="Cancel pop" onClick={() => void settle(0)} />
473+
</VStack>
474+
)}
475+
</VStack>
476+
);
477+
}
478+
479+
export const SelectionHold: Story = {
480+
render: () => <SelectionHoldDemo />,
481+
parameters: {
482+
docs: {
483+
description: {
484+
story:
485+
'A row tapped to push stays selected while the pushed screen covers it ' +
486+
'and deselects as the screen pops (UIKit’s push from a table row), ' +
487+
'driven here by buttons standing in for a navigation stack: Back runs ' +
488+
'the in-transition deselect, the slider scrubs it like an edge swipe, ' +
489+
'and Cancel selects the row again.',
490+
},
491+
},
492+
},
493+
};

‎packages/core/src/Item/Item.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import {themeProps} from '../utils/themeProps';
5555
import {focusOutlineProps} from '../utils/focusOutline.stylex';
5656
import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
5757
import {pressLayerStyles} from '../utils/pressLayer.stylex';
58+
import {cellPressableProps} from '../utils/selectionHold';
5859
import {usePressFeedback} from '../hooks/usePressFeedback';
5960
import type {ItemSwipeBridge} from './ItemSwipeLayer';
6061

@@ -876,7 +877,7 @@ export function Item({
876877
(isSelected && !allowsAriaSelected ? true : undefined)
877878
}
878879
aria-disabled={isDisabled || undefined}
879-
{...(isInteractive ? pressable : undefined)}
880+
{...(isInteractive ? {...pressable, ...cellPressableProps} : undefined)}
880881
{...mergeProps(
881882
themeProps('item', {density, align}),
882883
focusOutlineProps.focusWithin(

‎packages/core/src/List/ListItem.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,17 @@ const styles = stylex.create({
190190
// A touch press hides this row's divider and the one above it, in the
191191
// frame the press is believed, with no transition, as a highlighted
192192
// UIKit cell hides its separators; both come back in the first frame of
193-
// the release, while the press is still fading.
193+
// the release, while the press is still fading. A selection hold (the row
194+
// kept selected through a navigation push) hides them the same way until
195+
// its deselect begins, and again after a cancel.
194196
borderBlockEndColor: {
195197
default: colorVars['--color-border'],
196198
'[data-astryx-press="on"]': 'transparent',
199+
'[data-astryx-press="held"]:not([data-astryx-deselecting])':
200+
'transparent',
197201
':has(+ [data-astryx-press="on"])': 'transparent',
202+
':has(+ [data-astryx-press="held"]:not([data-astryx-deselecting]))':
203+
'transparent',
198204
},
199205
// A longhand, not the `borderBlockEnd` shorthand: StyleX's default
200206
// property-specificity mode drops border shorthands silently, so the
@@ -213,6 +219,10 @@ const styles = stylex.create({
213219
default: `calc(-1 * ${borderVars['--border-width']})`,
214220
':last-child': 0,
215221
},
222+
'[data-astryx-press="held"]:not([data-astryx-deselecting])': {
223+
default: `calc(-1 * ${borderVars['--border-width']})`,
224+
':last-child': 0,
225+
},
216226
},
217227
},
218228
},

0 commit comments

Comments
 (0)