@astryxdesign/lab 0.7.6-canary.f73623d → 0.7.6-canary.f77aaf2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CommentPin/CommentPin.js +1 -1
- package/dist/Comments/CommentComposer.d.ts.map +1 -1
- package/dist/Comments/CommentComposer.js +12 -4
- package/dist/MobilePowerSearch/MobilePowerSearch.d.ts +3 -6
- package/dist/MobilePowerSearch/MobilePowerSearch.d.ts.map +1 -1
- package/dist/MobilePowerSearch/MobilePowerSearch.js +12 -76
- package/dist/MobileTokenizer/MobileTokenizer.d.ts +10 -7
- package/dist/MobileTokenizer/MobileTokenizer.d.ts.map +1 -1
- package/dist/MobileTokenizer/MobileTokenizer.js +191 -114
- package/dist/internal/MobileSheetConfirmation.d.ts +12 -0
- package/dist/internal/MobileSheetConfirmation.d.ts.map +1 -0
- package/dist/internal/MobileSheetConfirmation.js +88 -0
- package/dist/internal/useDismissSearchOnTouchDrag.d.ts +21 -0
- package/dist/internal/useDismissSearchOnTouchDrag.d.ts.map +1 -0
- package/dist/internal/useDismissSearchOnTouchDrag.js +43 -0
- package/package.json +4 -4
- package/src/CommentPin/CommentPin.tsx +1 -1
- package/src/Comments/CommentComposer.test.tsx +56 -0
- package/src/Comments/CommentComposer.tsx +18 -13
- package/src/MobilePowerSearch/MobilePowerSearch.doc.mjs +1 -1
- package/src/MobilePowerSearch/MobilePowerSearch.test.tsx +7 -2
- package/src/MobilePowerSearch/MobilePowerSearch.tsx +16 -83
- package/src/MobileTokenizer/MobileTokenizer.doc.mjs +3 -3
- package/src/MobileTokenizer/MobileTokenizer.test.tsx +287 -31
- package/src/MobileTokenizer/MobileTokenizer.tsx +242 -137
- package/src/Schedule/__tests__/ScheduleTimeDirection.a11y.chromium.spec.ts +4 -0
- package/src/TransferList/TransferList.doc.mjs +1 -1
- package/src/internal/MobileSheetConfirmation.test.tsx +68 -0
- package/src/internal/MobileSheetConfirmation.tsx +97 -0
- package/src/internal/useDismissSearchOnTouchDrag.test.tsx +94 -0
- package/src/internal/useDismissSearchOnTouchDrag.ts +57 -0
- package/src/CommentPin/CommentPin.spec.md +0 -319
- package/src/Schedule/Schedule.spec.md +0 -590
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {fireEvent, render, screen, within} from '@testing-library/react';
|
|
4
|
+
import {beforeEach, describe, expect, it, vi} from 'vitest';
|
|
5
|
+
import {MobileSheetConfirmation} from './MobileSheetConfirmation';
|
|
6
|
+
|
|
7
|
+
// jsdom has no native modal presentation; keep the public Dialog path active.
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
HTMLDialogElement.prototype.showModal = vi.fn(function (
|
|
10
|
+
this: HTMLDialogElement,
|
|
11
|
+
) {
|
|
12
|
+
this.setAttribute('open', '');
|
|
13
|
+
});
|
|
14
|
+
HTMLDialogElement.prototype.close = vi.fn(function (this: HTMLDialogElement) {
|
|
15
|
+
this.removeAttribute('open');
|
|
16
|
+
});
|
|
17
|
+
window.scrollTo = vi.fn();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function setup() {
|
|
21
|
+
const onAction = vi.fn();
|
|
22
|
+
const onOpenChange = vi.fn();
|
|
23
|
+
render(
|
|
24
|
+
<MobileSheetConfirmation
|
|
25
|
+
isOpen
|
|
26
|
+
onOpenChange={onOpenChange}
|
|
27
|
+
title="Discard changes?"
|
|
28
|
+
description="The draft will be removed."
|
|
29
|
+
actionLabel="Discard"
|
|
30
|
+
cancelLabel="Keep editing"
|
|
31
|
+
onAction={onAction}
|
|
32
|
+
/>,
|
|
33
|
+
);
|
|
34
|
+
const dialog = screen.getByRole('alertdialog', {name: 'Discard changes?'});
|
|
35
|
+
return {dialog, onAction, onOpenChange};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe('MobileSheetConfirmation', () => {
|
|
39
|
+
it('keeps the alert-dialog theme target and accessible copy', () => {
|
|
40
|
+
const {dialog} = setup();
|
|
41
|
+
expect(dialog).toHaveClass('astryx-alert-dialog');
|
|
42
|
+
expect(dialog).toHaveAccessibleDescription('The draft will be removed.');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('stacks full-width large actions with the secondary safe action focused', () => {
|
|
46
|
+
const {dialog} = setup();
|
|
47
|
+
const [destructive, safe] = within(dialog).getAllByRole('button');
|
|
48
|
+
expect(destructive).toHaveAccessibleName('Discard');
|
|
49
|
+
expect(destructive).toHaveAttribute('data-variant', 'destructive');
|
|
50
|
+
expect(safe).toHaveAccessibleName('Keep editing');
|
|
51
|
+
expect(safe).toHaveAttribute('data-variant', 'secondary');
|
|
52
|
+
for (const button of [destructive, safe]) {
|
|
53
|
+
expect(button).toHaveAttribute('data-size', 'lg');
|
|
54
|
+
expect(getComputedStyle(button).width).toBe('100%');
|
|
55
|
+
}
|
|
56
|
+
expect(getComputedStyle(safe.parentElement!).flexDirection).toBe('column');
|
|
57
|
+
expect(safe).toHaveFocus();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('reports action and safe dismissal independently without committing on cancel', () => {
|
|
61
|
+
const {dialog, onAction, onOpenChange} = setup();
|
|
62
|
+
fireEvent.click(within(dialog).getByRole('button', {name: 'Keep editing'}));
|
|
63
|
+
expect(onOpenChange).toHaveBeenCalledWith(false);
|
|
64
|
+
expect(onAction).not.toHaveBeenCalled();
|
|
65
|
+
fireEvent.click(within(dialog).getByRole('button', {name: 'Discard'}));
|
|
66
|
+
expect(onAction).toHaveBeenCalledTimes(1);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file MobileSheetConfirmation.tsx
|
|
7
|
+
* @input Public Core Dialog, layout, text and action primitives; caller-owned copy
|
|
8
|
+
* @output Private confirmation shared by MobileTokenizer and MobilePowerSearch
|
|
9
|
+
* @position Lab-only mobile sheet confirmation owner; not a public export
|
|
10
|
+
*
|
|
11
|
+
* Core AlertDialog fixes its purpose to form and its safe action to ghost.
|
|
12
|
+
* These Lab flows instead allow scrim dismissal and use separated, full-width
|
|
13
|
+
* large actions with the secondary safe action focused first. Keep that
|
|
14
|
+
* difference here, while preserving the existing alert-dialog theme target.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import {useId} from 'react';
|
|
18
|
+
import * as stylex from '@stylexjs/stylex';
|
|
19
|
+
import {Button} from '@astryxdesign/core/Button';
|
|
20
|
+
import {Dialog} from '@astryxdesign/core/Dialog';
|
|
21
|
+
import {Heading} from '@astryxdesign/core/Heading';
|
|
22
|
+
import {Layout, LayoutContent, LayoutFooter} from '@astryxdesign/core/Layout';
|
|
23
|
+
import {Stack} from '@astryxdesign/core/Stack';
|
|
24
|
+
import {Text} from '@astryxdesign/core/Text';
|
|
25
|
+
import {themeProps} from '@astryxdesign/core/utils';
|
|
26
|
+
|
|
27
|
+
interface MobileSheetConfirmationProps {
|
|
28
|
+
isOpen: boolean;
|
|
29
|
+
onOpenChange: (isOpen: boolean) => void;
|
|
30
|
+
title: string;
|
|
31
|
+
description: string;
|
|
32
|
+
cancelLabel: string;
|
|
33
|
+
actionLabel: string;
|
|
34
|
+
onAction: () => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const styles = stylex.create({
|
|
38
|
+
action: {width: '100%'},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export function MobileSheetConfirmation({
|
|
42
|
+
isOpen,
|
|
43
|
+
onOpenChange,
|
|
44
|
+
title,
|
|
45
|
+
description,
|
|
46
|
+
cancelLabel,
|
|
47
|
+
actionLabel,
|
|
48
|
+
onAction,
|
|
49
|
+
}: MobileSheetConfirmationProps) {
|
|
50
|
+
const titleId = useId();
|
|
51
|
+
const descriptionId = useId();
|
|
52
|
+
return (
|
|
53
|
+
<Dialog
|
|
54
|
+
{...themeProps('alert-dialog')}
|
|
55
|
+
isOpen={isOpen}
|
|
56
|
+
onOpenChange={onOpenChange}
|
|
57
|
+
purpose="info"
|
|
58
|
+
role="alertdialog"
|
|
59
|
+
aria-labelledby={titleId}
|
|
60
|
+
aria-describedby={descriptionId}
|
|
61
|
+
width={400}>
|
|
62
|
+
<Layout
|
|
63
|
+
content={
|
|
64
|
+
<LayoutContent>
|
|
65
|
+
<Heading level={2} id={titleId}>
|
|
66
|
+
{title}
|
|
67
|
+
</Heading>
|
|
68
|
+
<Text type="body" color="secondary" id={descriptionId}>
|
|
69
|
+
{description}
|
|
70
|
+
</Text>
|
|
71
|
+
</LayoutContent>
|
|
72
|
+
}
|
|
73
|
+
footer={
|
|
74
|
+
<LayoutFooter>
|
|
75
|
+
<Stack direction="vertical" gap={4} hAlign="stretch">
|
|
76
|
+
<Button
|
|
77
|
+
label={actionLabel}
|
|
78
|
+
variant="destructive"
|
|
79
|
+
size="lg"
|
|
80
|
+
onClick={onAction}
|
|
81
|
+
xstyle={styles.action}
|
|
82
|
+
/>
|
|
83
|
+
<Button
|
|
84
|
+
label={cancelLabel}
|
|
85
|
+
variant="secondary"
|
|
86
|
+
size="lg"
|
|
87
|
+
onClick={() => onOpenChange(false)}
|
|
88
|
+
data-autofocus
|
|
89
|
+
xstyle={styles.action}
|
|
90
|
+
/>
|
|
91
|
+
</Stack>
|
|
92
|
+
</LayoutFooter>
|
|
93
|
+
}
|
|
94
|
+
/>
|
|
95
|
+
</Dialog>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {useRef} from 'react';
|
|
4
|
+
import {fireEvent, render, screen} from '@testing-library/react';
|
|
5
|
+
import userEvent from '@testing-library/user-event';
|
|
6
|
+
import {describe, expect, it, vi} from 'vitest';
|
|
7
|
+
import {useDismissSearchOnTouchDrag} from './useDismissSearchOnTouchDrag';
|
|
8
|
+
|
|
9
|
+
function Harness({hasSecondSearch = false}: {hasSecondSearch?: boolean}) {
|
|
10
|
+
const firstRef = useRef<HTMLInputElement>(null);
|
|
11
|
+
const secondRef = useRef<HTMLInputElement>(null);
|
|
12
|
+
const dragProps = useDismissSearchOnTouchDrag(() => [
|
|
13
|
+
firstRef.current,
|
|
14
|
+
secondRef.current,
|
|
15
|
+
]);
|
|
16
|
+
return (
|
|
17
|
+
<>
|
|
18
|
+
<input ref={firstRef} aria-label="First search" />
|
|
19
|
+
{hasSecondSearch && <input ref={secondRef} aria-label="Second search" />}
|
|
20
|
+
<input aria-label="Unrelated field" />
|
|
21
|
+
<div role="group" aria-label="Results" {...dragProps} />
|
|
22
|
+
</>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const touches = (clientY: number) => [{clientY}];
|
|
27
|
+
|
|
28
|
+
function setup() {
|
|
29
|
+
render(<Harness hasSecondSearch />);
|
|
30
|
+
const search = screen.getByRole('textbox', {name: 'First search'});
|
|
31
|
+
const results = screen.getByRole('group', {name: 'Results'});
|
|
32
|
+
search.focus();
|
|
33
|
+
return {search, results};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe('useDismissSearchOnTouchDrag', () => {
|
|
37
|
+
it('preserves typing across programmatic result scrolling', async () => {
|
|
38
|
+
const {search, results} = setup();
|
|
39
|
+
fireEvent.scroll(results, {target: {scrollTop: 300}});
|
|
40
|
+
await userEvent.setup().type(search, 'Eng');
|
|
41
|
+
fireEvent.scroll(results, {target: {scrollTop: 0}});
|
|
42
|
+
expect(search).toHaveFocus();
|
|
43
|
+
expect(search).toHaveValue('Eng');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('blurs a focused owned search once at the direct vertical drag threshold', () => {
|
|
47
|
+
const {search, results} = setup();
|
|
48
|
+
const blur = vi.spyOn(search, 'blur');
|
|
49
|
+
fireEvent.touchStart(results, {touches: touches(100)});
|
|
50
|
+
fireEvent.touchMove(results, {touches: touches(107)});
|
|
51
|
+
expect(search).toHaveFocus();
|
|
52
|
+
fireEvent.touchMove(results, {touches: touches(108)});
|
|
53
|
+
expect(search).not.toHaveFocus();
|
|
54
|
+
fireEvent.touchMove(results, {touches: touches(120)});
|
|
55
|
+
expect(blur).toHaveBeenCalledTimes(1);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('does not blur on an unowned touch move, tap, or horizontal motion', () => {
|
|
59
|
+
const {search, results} = setup();
|
|
60
|
+
fireEvent.touchMove(results, {touches: touches(120)});
|
|
61
|
+
expect(search).toHaveFocus();
|
|
62
|
+
fireEvent.touchStart(results, {touches: [{clientY: 100, clientX: 0}]});
|
|
63
|
+
fireEvent.touchMove(results, {touches: [{clientY: 100, clientX: 100}]});
|
|
64
|
+
fireEvent.touchEnd(results);
|
|
65
|
+
fireEvent.touchMove(results, {touches: touches(120)});
|
|
66
|
+
expect(search).toHaveFocus();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('resets ownership on cancellation and multi-touch without dismissing', () => {
|
|
70
|
+
const {search, results} = setup();
|
|
71
|
+
fireEvent.touchStart(results, {touches: touches(100)});
|
|
72
|
+
fireEvent.touchCancel(results);
|
|
73
|
+
fireEvent.touchMove(results, {touches: touches(120)});
|
|
74
|
+
expect(search).toHaveFocus();
|
|
75
|
+
fireEvent.touchStart(results, {touches: touches(100)});
|
|
76
|
+
fireEvent.touchMove(results, {touches: [{clientY: 120}, {clientY: 140}]});
|
|
77
|
+
fireEvent.touchMove(results, {touches: touches(150)});
|
|
78
|
+
expect(search).toHaveFocus();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('can dismiss either current owned input, but never an unrelated field', () => {
|
|
82
|
+
const {results} = setup();
|
|
83
|
+
const secondSearch = screen.getByRole('textbox', {name: 'Second search'});
|
|
84
|
+
secondSearch.focus();
|
|
85
|
+
fireEvent.touchStart(results, {touches: touches(100)});
|
|
86
|
+
fireEvent.touchMove(results, {touches: touches(90)});
|
|
87
|
+
expect(secondSearch).not.toHaveFocus();
|
|
88
|
+
const unrelated = screen.getByRole('textbox', {name: 'Unrelated field'});
|
|
89
|
+
unrelated.focus();
|
|
90
|
+
fireEvent.touchStart(results, {touches: touches(100)});
|
|
91
|
+
fireEvent.touchMove(results, {touches: touches(120)});
|
|
92
|
+
expect(unrelated).toHaveFocus();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file useDismissSearchOnTouchDrag.ts
|
|
7
|
+
* @input Caller-owned search inputs and touch events from a separate results list
|
|
8
|
+
* @output Private touch handlers shared by the Lab mobile search sheets
|
|
9
|
+
* @position One owner for results-drag keyboard dismissal; not a public export
|
|
10
|
+
*
|
|
11
|
+
* A direct vertical touch drag dismisses only a focused caller-owned search.
|
|
12
|
+
* Scroll events are deliberately not observed: filtering can clamp scrollTop
|
|
13
|
+
* and fire scroll while someone is typing. Small moves, taps and multi-touch
|
|
14
|
+
* gestures leave focus alone. The hook acquires no external resource.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import {useRef, type TouchEvent} from 'react';
|
|
18
|
+
|
|
19
|
+
const DRAG_THRESHOLD_PX = 8;
|
|
20
|
+
|
|
21
|
+
type SearchInput = HTMLInputElement | null | undefined;
|
|
22
|
+
|
|
23
|
+
export function useDismissSearchOnTouchDrag(
|
|
24
|
+
getSearchInputs: () => readonly SearchInput[],
|
|
25
|
+
) {
|
|
26
|
+
const startYRef = useRef<number | null>(null);
|
|
27
|
+
const reset = () => {
|
|
28
|
+
startYRef.current = null;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
onTouchStart: (event: TouchEvent<HTMLElement>) => {
|
|
33
|
+
startYRef.current =
|
|
34
|
+
event.touches.length === 1 ? event.touches[0].clientY : null;
|
|
35
|
+
},
|
|
36
|
+
onTouchMove: (event: TouchEvent<HTMLElement>) => {
|
|
37
|
+
if (event.touches.length !== 1) {
|
|
38
|
+
reset();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const startY = startYRef.current;
|
|
42
|
+
if (
|
|
43
|
+
startY == null ||
|
|
44
|
+
Math.abs(event.touches[0].clientY - startY) < DRAG_THRESHOLD_PX
|
|
45
|
+
) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
reset();
|
|
49
|
+
const focusedSearch = getSearchInputs().find(
|
|
50
|
+
input => input != null && input === document.activeElement,
|
|
51
|
+
);
|
|
52
|
+
focusedSearch?.blur();
|
|
53
|
+
},
|
|
54
|
+
onTouchEnd: reset,
|
|
55
|
+
onTouchCancel: reset,
|
|
56
|
+
};
|
|
57
|
+
}
|