Skip to content

Commit 85a30f1

Browse files
cixzhangvjeux
andcommitted
Merge #8140 (1c5f465: dividers stay drawn on press; no Core selection hold) as a dependency
Co-authored-by: Christopher Chedeau <vjeuxx@gmail.com>
2 parents af760b2 + 1c5f465 commit 85a30f1

21 files changed

Lines changed: 27 additions & 2195 deletions

‎.changeset/list-dividers-hide-on-press.md‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

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

Lines changed: 0 additions & 8 deletions
This file was deleted.

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

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

10-
import {useMemo, useRef, useState, type MouseEvent} from 'react';
10+
import {useMemo, useState} 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';
@@ -21,11 +21,6 @@ import {Heading, Text} from '@astryxdesign/core/Text';
2121
import {VStack} from '@astryxdesign/core/Layout';
2222
import {Button} from '@astryxdesign/core/Button';
2323
import {ContextMenu} from '@astryxdesign/core/ContextMenu';
24-
// The selection hold is internal to core (no public API records it yet).
25-
import {
26-
holdSelection,
27-
type SelectionHold as RowSelectionHold,
28-
} from '../../../packages/core/src/List/selectionHold';
2924
import {
3025
Cog6ToothIcon,
3126
BellIcon,
@@ -417,121 +412,6 @@ export const HeaderInFlexParent: Story = {
417412
},
418413
};
419414

420-
function SelectionHoldDemo() {
421-
const hold = useRef<RowSelectionHold | null>(null);
422-
const slider = useRef<HTMLInputElement | null>(null);
423-
const [open, setOpen] = useState<string | null>(null);
424-
const [progress, setProgress] = useState(0);
425-
const push = (label: string) => (event: MouseEvent) => {
426-
// In the same task as the activation that pushes.
427-
hold.current = holdSelection(event.target);
428-
setProgress(0);
429-
setOpen(label);
430-
};
431-
const settle = async (
432-
to: 0 | 1,
433-
timing?: Parameters<RowSelectionHold['animate']>[1],
434-
{followSlider = false}: {followSlider?: boolean} = {},
435-
) => {
436-
const current = hold.current;
437-
// A slow pop shows where it is on the slider (written to the input, no
438-
// render per frame), so a finger that takes the slider over mid-flight
439-
// continues from the value on screen. (Off for the regular pop, whose
440-
// proof counts every paint.)
441-
const following = {frame: 0};
442-
const follow = () => {
443-
if (current != null && slider.current != null) {
444-
slider.current.value = String(current.presentation());
445-
}
446-
following.frame = requestAnimationFrame(follow);
447-
};
448-
if (followSlider) {
449-
following.frame = requestAnimationFrame(follow);
450-
}
451-
// No hold under a mouse: the screen just pops.
452-
const arrived = current == null || (await current.animate(to, timing));
453-
cancelAnimationFrame(following.frame);
454-
if (!arrived) {
455-
// Interrupted (a finger took the progress over mid-flight): the hold
456-
// stays where the finger left it.
457-
return;
458-
}
459-
if (to === 1) {
460-
setOpen(null);
461-
current?.end(true);
462-
current?.focus({preventScroll: true});
463-
hold.current = null;
464-
} else {
465-
current?.end(false);
466-
setProgress(0);
467-
}
468-
};
469-
return (
470-
<VStack gap={4}>
471-
<List hasDividers>
472-
{['Inbox', 'Sent', 'Drafts'].map(label => (
473-
<ListItem
474-
key={label}
475-
label={label}
476-
onClick={push(label)}
477-
endContent={<Icon icon={ChevronRightIcon} />}
478-
/>
479-
))}
480-
</List>
481-
{open != null && (
482-
<VStack gap={2} data-testid="pushed-screen">
483-
<Text type="label">{open} (pushed)</Text>
484-
<Button label="Back" onClick={() => void settle(1)} />
485-
<Button
486-
label="Back, slowly"
487-
onClick={() =>
488-
void settle(
489-
1,
490-
{durationMs: 3000, curve: [0, 0, 1, 1]},
491-
{followSlider: true},
492-
)
493-
}
494-
/>
495-
<label>
496-
Pop progress
497-
<input
498-
ref={slider}
499-
type="range"
500-
min={0}
501-
max={1}
502-
step={0.01}
503-
value={progress}
504-
onChange={event => {
505-
const value = Number(event.target.value);
506-
setProgress(value);
507-
hold.current?.setProgress(value);
508-
}}
509-
/>
510-
</label>
511-
<Button label="Finish pop" onClick={() => void settle(1)} />
512-
<Button label="Cancel pop" onClick={() => void settle(0)} />
513-
</VStack>
514-
)}
515-
</VStack>
516-
);
517-
}
518-
519-
export const SelectionHold: Story = {
520-
render: () => <SelectionHoldDemo />,
521-
parameters: {
522-
docs: {
523-
description: {
524-
story:
525-
'A row tapped to push stays selected while the pushed screen covers it ' +
526-
'and deselects as the screen pops (UIKit’s push from a table row), ' +
527-
'driven here by buttons standing in for a navigation stack: Back runs ' +
528-
'the in-transition deselect, the slider scrubs it like an edge swipe, ' +
529-
'and Cancel selects the row again.',
530-
},
531-
},
532-
},
533-
};
534-
535415
function AnimatedChangesDemo() {
536416
const [rows, setRows] = useState([
537417
'Inbox',

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ import {useDevWarning} from '../hooks/useDevWarning';
5858
import {themeProps} from '../utils/themeProps';
5959
import {focusOutlineProps} from '../utils/focusOutline.stylex';
6060
import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
61-
import {cellPressableProps} from '../utils/pressFeedback';
6261
import {rowPressLayerStyles} from '../utils/rowPressLayer';
6362
import {usePressFeedback} from '../hooks/usePressFeedback';
64-
import {useInteractionModalityTracking} from '../utils/interactionModality';
6563
import type {ItemSwipeBridge} from './ItemSwipeLayer';
6664

6765
// The gesture and the panels, loaded only by a row that has swipe actions: a
@@ -594,10 +592,6 @@ export function Item({
594592
...restProps
595593
}: ItemProps) {
596594
const pressable = usePressFeedback();
597-
// A selection hold (List/selectionHold.ts) returns focus to this row after
598-
// a pop; its ring follows how the user last interacted, so a finger's pop
599-
// shows none.
600-
useInteractionModalityTracking();
601595
const LinkComponent = useLinkComponent();
602596

603597
// Delegation mode: the row is an enlarged click/tap target for a nested
@@ -919,7 +913,7 @@ export function Item({
919913
(isSelected && !allowsAriaSelected ? true : undefined)
920914
}
921915
aria-disabled={isDisabled || undefined}
922-
{...(isInteractive ? {...pressable, ...cellPressableProps} : undefined)}
916+
{...(isInteractive ? pressable : undefined)}
923917
{...mergeProps(
924918
themeProps('item', {density, align}),
925919
focusOutlineProps.focusWithin(

‎packages/core/src/List/List.doc.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const docs = {
3838
{
3939
name: 'hasDividers',
4040
type: 'boolean',
41-
description: 'Show dividers between items. Under a finger, a touch press hides the dividers on either side of the pressed row until the finger lifts, as iOS lists do.',
41+
description: 'Show dividers between items.',
4242
default: 'false',
4343
},
4444
{

‎packages/core/src/List/List.exports.test.ts‎

Lines changed: 0 additions & 31 deletions
This file was deleted.

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

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -524,73 +524,6 @@ describe('List', () => {
524524
expect(hrs).toHaveLength(0);
525525
});
526526

527-
it('hides a touch-pressed row’s divider and the one above it, with the press layer over its own, under a finger only', () => {
528-
render(
529-
<List hasDividers>
530-
<ListItem label="Item 1" onClick={() => {}} />
531-
<ListItem label="Item 2" onClick={() => {}} />
532-
</List>,
533-
);
534-
const row = screen.getByText('Item 1').closest('li') as HTMLElement;
535-
const {touch: rules, other} = touchGatedRules(row);
536-
// Outside the touch gate (a mouse) no press arm touches the dividers.
537-
expect(
538-
other.some(
539-
rule =>
540-
rule.slice(0, rule.indexOf('{')).includes('data-astryx-press') &&
541-
/border-(bottom|block-end)-color|(^|[;{\s])(bottom|inset-block-end):/.test(
542-
rule,
543-
),
544-
),
545-
).toBe(false);
546-
const selector = (rule: string) => rule.slice(0, rule.indexOf('{'));
547-
const hides = (condition: string) =>
548-
rules.some(
549-
rule =>
550-
selector(rule).includes(condition) &&
551-
!selector(rule).includes('::before') &&
552-
/border-(bottom|block-end)-color:\s*transparent/.test(rule),
553-
);
554-
// Its own divider while it is pressed, and the divider above the row
555-
// being pressed: the row before a pressed sibling.
556-
expect(hides('[data-astryx-press="on"]')).toBe(true);
557-
expect(hides(':has(+ [data-astryx-press="on"])')).toBe(true);
558-
// Only while the press is on: the release shows both again at once.
559-
expect(hides('[data-astryx-press="fading"]')).toBe(false);
560-
// The pressed row's layer reaches over the hidden divider, except on the
561-
// last row, which has none.
562-
const layer = rules.filter(
563-
rule =>
564-
selector(rule).includes('::before') &&
565-
selector(rule).includes('[data-astryx-press="on"]') &&
566-
/(bottom|inset-block-end):/.test(rule),
567-
);
568-
expect(layer.some(rule => /calc\(\s*-1\s*\*\s*var\(/.test(rule))).toBe(
569-
true,
570-
);
571-
expect(
572-
layer.some(
573-
rule =>
574-
selector(rule).includes(':last-child') &&
575-
/(bottom|inset-block-end):\s*0(px)?[;}\s]/.test(rule),
576-
),
577-
).toBe(true);
578-
});
579-
580-
it('leaves a list without dividers alone during a press', () => {
581-
render(
582-
<List>
583-
<ListItem label="Item 1" onClick={() => {}} />
584-
</List>,
585-
);
586-
const row = screen.getByText('Item 1').closest('li') as HTMLElement;
587-
expect(
588-
rulesDeclaredFor(row).some(rule =>
589-
rule.slice(0, rule.indexOf('{')).includes(':has(+ [data-astryx-press'),
590-
),
591-
).toBe(false);
592-
});
593-
594527
// ===========================================================================
595528
// Touch hit area (`spec:AST-094` FR42; `component:List` FR10, #8571)
596529
// ===========================================================================

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ export interface ListProps extends BaseProps<
111111
reorderable?: Reorderable;
112112

113113
/**
114-
* Whether to show dividers between list items. Under a finger, a touch
115-
* press hides the dividers on either side of the pressed row until the
116-
* finger lifts, as iOS lists do.
114+
* Whether to show dividers between list items.
117115
* @default false
118116
*/
119117
hasDividers?: boolean;

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

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
/**
66
* @file ListItem.tsx
77
* @input Uses React, ReactNode, StyleXStyles, theme tokens, the List row edge
8-
* treatment, the press layer (dividers beside a touch-pressed or held row
9-
* hide and the layer reaches over the row's own), the touch hit area
10-
* (utils/touchHitArea.ts and its layer), the travelling
11-
* marker of an update's slide (List/useListUpdateMotion.ts), CheckboxInput,
12-
* and the marker or task checkbox a ListMarkerScope sets (Markdown's nested
13-
* lists and the task items of mixed lists)
8+
* treatment, the touch hit area (utils/touchHitArea.ts and its layer), the
9+
* travelling marker of an update's slide (List/useListUpdateMotion.ts),
10+
* CheckboxInput, and the marker or task checkbox a ListMarkerScope sets
11+
* (Markdown's nested lists and the task items of mixed lists)
1412
* @output Exports ListItem component, ListItemProps type
1513
* @position Core implementation; consumed by List, index.ts, tested by List.test.tsx
1614
*
@@ -226,52 +224,14 @@ const styles = stylex.create({
226224
withDivider: {
227225
borderBlockEndWidth: borderVars['--border-width'],
228226
borderBlockEndStyle: 'solid',
229-
// Under a finger (a coarse primary pointer, TOUCH_QUERY in
230-
// utils/touchPresentation.ts), a touch press hides this row's divider
231-
// and the one above it, in the frame the press is believed, with no
232-
// transition, as a highlighted UIKit cell hides its separators; both
233-
// come back in the first frame of the release, while the press is still
234-
// fading. A selection hold (the row kept selected through a navigation
235-
// push) hides them the same way until its deselect begins, and again
236-
// after a cancel. With a mouse the dividers stay drawn.
237-
borderBlockEndColor: {
238-
default: colorVars['--color-border'],
239-
'@media (pointer: coarse)': {
240-
default: null,
241-
'[data-astryx-press="on"]': 'transparent',
242-
'[data-astryx-press="held"]:not([data-astryx-deselecting])':
243-
'transparent',
244-
':has(+ [data-astryx-press="on"])': 'transparent',
245-
':has(+ [data-astryx-press="held"]:not([data-astryx-deselecting]))':
246-
'transparent',
247-
},
248-
},
227+
borderBlockEndColor: colorVars['--color-border'],
249228
// A longhand, not the `borderBlockEnd` shorthand: StyleX's default
250229
// property-specificity mode drops border shorthands silently, so the
251230
// shorthand never reached the shipped CSS and the last item kept its
252231
// divider.
253232
':last-child': {
254233
borderBlockEndWidth: 0,
255234
},
256-
// While its divider is hidden, the press layer (the `cell` style of
257-
// utils/interactionOverlay.stylex.ts) reaches over it, so the whole row
258-
// is pressed. The last row has no divider to cover.
259-
'::before': {
260-
insetBlockEnd: {
261-
default: null,
262-
'@media (pointer: coarse)': {
263-
default: null,
264-
'[data-astryx-press="on"]': {
265-
default: `calc(-1 * ${borderVars['--border-width']})`,
266-
':last-child': 0,
267-
},
268-
'[data-astryx-press="held"]:not([data-astryx-deselecting])': {
269-
default: `calc(-1 * ${borderVars['--border-width']})`,
270-
':last-child': 0,
271-
},
272-
},
273-
},
274-
},
275235
},
276236
});
277237

0 commit comments

Comments
 (0)