An open source design system that's fully customizable and agent ready
TypeScript
chore(core): Core's internal touch entry re-exports the action-group tracking hook, extended for Lab's TabBar, and a tab-bar string joins the catalog (#9699)
Christopher Chedeaua8195e032904
diff --git a/.changeset/core-internal-entries-lab-tabbar.md b/.changeset/core-internal-entries-lab-tabbar.mdnew file mode 100644index 0000000000..62d4eff726--- /dev/null+++ b/.changeset/core-internal-entries-lab-tabbar.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[chore] Internal: Core's internal touch entry re-exports the action-group tracking hook, which gains a no-paint option and press callbacks for Lab's TabBar. A tab-bar string joins Core's message catalog. Apps import nothing new.++@vjeuxdiff --git a/packages/core/locales/en.json b/packages/core/locales/en.jsonindex b79518a646..3232a95f69 100644--- a/packages/core/locales/en.json+++ b/packages/core/locales/en.json@@ -943,6 +943,10 @@"defaultMessage": "Maximum value","description": "Accessible name of the upper thumb of a range Slider (two thumbs), announced together with the Slider's own label, for example \"Price range, Maximum value, 80\". Never shown on screen."},+ "@astryx.tabBar.badgedItem": {+ "defaultMessage": "{label}, {badge}",+ "description": "Screen-reader name of a bottom tab bar item that shows a badge (\"Library, 3\"). {label} is the tab's visible name; {badge} is the badge's count or its own label (\"3 unread\"). Translators may reorder the two or change the separator."+ },"@astryx.tabList.label": {"defaultMessage": "Tabs","description": "Screen-reader-only fallback name for a horizontal tab bar. Plural noun; \"Tabs\" here = UI tab panels, not browser tabs or the Tab key."diff --git a/packages/core/src/hooks/useActionGroupTracking.test.tsx b/packages/core/src/hooks/useActionGroupTracking.test.tsxindex 3d7fd52668..e28a57b272 100644--- a/packages/core/src/hooks/useActionGroupTracking.test.tsx+++ b/packages/core/src/hooks/useActionGroupTracking.test.tsx@@ -12,7 +12,7 @@* action is skipped; a second finger or the window losing focus cancels;* inside a scroller a flick is left to the scroller; a mouse under a fine* pointer is tracked like a finger; the shared tracker does the tracking;- * no render per move+ * a caller's no-paint option and press callbacks; no render per move* @position jsdom tests of packages/core/src/hooks/useActionGroupTracking.ts*/@@ -313,6 +313,96 @@ describe('useActionGroupTracking', () => {expect(onDelete).not.toHaveBeenCalled();});+ describe('a group that draws its own highlight (Lab TabBar)', () => {+ const nameOf = (element: Element | null) => element?.textContent ?? 'none';++ it('paints nothing with paintsHighlight off, and still runs the action it lifts on', () => {+ const {cancel, del, onCancel} = mount({+ options: {paintsHighlight: false},+ });+ const f = finger();+ f.down(cancel, centerOf(CANCEL));+ expect(paintOf(cancel)).toBeNull();+ f.move(cancel, centerOf(DELETE));+ expect(paintOf(del)).toBeNull();+ f.move(cancel, centerOf(CANCEL));+ f.up(cancel, centerOf(CANCEL));+ expect(paintOf(cancel)).toBeNull();+ expect(onCancel).toHaveBeenCalledTimes(1);+ });++ it('reports the press around the tracker: the action at the begin and after each move, then the lift before its action runs', () => {+ const log: string[] = [];+ const {cancel} = mount({+ options: {+ onPressBegin: (_x, _y, action) => log.push(`begin ${nameOf(action)}`),+ onPressMove: (_x, _y, action) => log.push(`move ${nameOf(action)}`),+ onPressEnd: action => log.push(`end ${nameOf(action)}`),+ onPressCancel: () => log.push('cancel'),+ onActivate: action => log.push(`activate ${nameOf(action)}`),+ },+ });+ const f = finger();+ f.down(cancel, centerOf(CANCEL));+ f.move(cancel, {x: 104, y: 124});+ f.move(cancel, centerOf(DELETE));+ f.up(cancel, centerOf(DELETE));+ expect(log).toEqual([+ 'begin Cancel',+ 'move none',+ 'move Delete',+ 'end Delete',+ 'activate Delete',+ ]);+ });++ it('reports a press that a second finger ends as a cancel, and runs nothing (family:action-groups FR3)', () => {+ const log: string[] = [];+ const {cancel, del} = mount({+ options: {+ onPressBegin: (_x, _y, action) => log.push(`begin ${nameOf(action)}`),+ onPressEnd: () => log.push('end'),+ onPressCancel: () => log.push('cancel'),+ onActivate: () => log.push('activate'),+ },+ });+ const first = {id: nextTouchId++, ...centerOf(CANCEL)};+ const second = {id: nextTouchId++, ...centerOf(DELETE)};+ time += 1000;+ touch('touchstart', cancel, first, time);+ time += 30;+ touch('touchstart', del, second, time, [first]);+ time += 16;+ touch('touchend', del, second, time, [first]);+ time += 16;+ touch('touchend', cancel, first, time);+ expect(log).toEqual(['begin Cancel', 'cancel']);+ });++ it('reports a press that turning tracking off ends as a cancel, and runs nothing', () => {+ const log: string[] = [];+ const options: Partial<ActionGroupTrackingOptions> = {+ paintsHighlight: false,+ onPressBegin: (_x, _y, action) => log.push(`begin ${nameOf(action)}`),+ onPressEnd: () => log.push('end'),+ onPressCancel: () => log.push('cancel'),+ onActivate: () => log.push('activate'),+ };+ const view = mount({options});+ const f = finger();+ f.down(view.cancel, centerOf(CANCEL));+ view.rerender(+ <Group+ onCancel={view.onCancel}+ onDelete={view.onDelete}+ options={{...options, isEnabled: false}}+ />,+ );+ f.up(view.cancel, centerOf(CANCEL));+ expect(log).toEqual(['begin Cancel', 'cancel']);+ });+ });+it('ends the gesture with nothing acting when the window loses focus (family:action-groups FR3)', () => {const {cancel, onCancel} = mount();const f = finger();diff --git a/packages/core/src/hooks/useActionGroupTracking.ts b/packages/core/src/hooks/useActionGroupTracking.tsindex 15a8fc0073..50f6d87e64 100644--- a/packages/core/src/hooks/useActionGroupTracking.ts+++ b/packages/core/src/hooks/useActionGroupTracking.ts@@ -12,7 +12,8 @@* @position Internal hook, not exported from the hooks entry. A long press* drives the shared action-group tracker (hooks/actionGroupTracker.ts) for* a group that a held pointer slides across. AlertDialog and- * useGroupPressTracking consume it.+ * useGroupPressTracking consume it, and Lab components through the internal+ * touch entry.** SYNC: When modified, update useActionGroupTracking.test.tsx*/@@ -71,6 +72,22 @@ export interface ActionGroupTrackingOptions {manageStyle?: boolean;/** Runs the action under the finger at the lift. @default its own click */onActivate?: (item: HTMLElement) => void;+ /**+ * Paint the tracked action with the press attribute. Off, the group draws+ * its own highlight. @default true+ */+ paintsHighlight?: boolean;+ /** A press began at viewport (x, y) on `action` (null: none). */+ onPressBegin?: (x: number, y: number, action: HTMLElement | null) => void;+ /** The press moved to viewport (x, y), now on `action` (null: none). */+ onPressMove?: (x: number, y: number, action: HTMLElement | null) => void;+ /** The lift, before its action runs, with the tracked action (null: none). */+ onPressEnd?: (action: HTMLElement | null) => void;+ /**+ * The press ended with nothing acting: a cancel, a second finger, or+ * tracking turned off.+ */+ onPressCancel?: () => void;}const PRESS = UIKIT_PRESS;@@ -185,6 +202,7 @@ export function useActionGroupTracking(optionsRef.current.resolveTarget,neighboursRef.current,),+ paintsHighlight: optionsRef.current.paintsHighlight,onActivate: optionsRef.current.onActivate,// The browser's own click for a press the group ran is taken, so the// action runs once. The gesture host swallows it for a press it claims.@@ -196,11 +214,16 @@ export function useActionGroupTracking(// Synchronizes the tracker with tracking on and mounted. Turning tracking// off, or unmounting, drops a tracked press and ends its release fades.// The host reports no cancellation to a disabled recognizer, and the lift- // that runs an action often closes the owner before its fade ends.+ // that runs an action often closes the owner before its fade ends. The+ // group hears the dropped press as a cancel, so its own highlight goes out.useEffect(() => () => {+ const wasTracking = tracker.isTracking;tracker.cancel();tracker.dispose();+ if (wasTracking) {+ optionsRef.current.onPressCancel?.();+ }},[tracker, isEnabled],);@@ -238,14 +261,17 @@ export function useActionGroupTracking(? measureNeighbours(ref.current, optionsRef.current): NO_TARGETS;tracker.begin(x, y, {landed: landedRef.current});+ optionsRef.current.onPressBegin?.(x, y, tracker.highlighted);break;}case 'changed': {const {x, y} = recognizer.location();tracker.move(x, y);+ optionsRef.current.onPressMove?.(x, y, tracker.highlighted);break;}case 'ended': {+ optionsRef.current.onPressEnd?.(tracker.highlighted);const doc = ref.current?.ownerDocument;const focusedBefore = doc?.activeElement ?? null;const beganOn = tracker.beganOn;@@ -278,6 +304,7 @@ export function useActionGroupTracking(case 'cancelled':neighboursRef.current = NO_TARGETS;tracker.cancel();+ optionsRef.current.onPressCancel?.();break;case 'possible':case 'failed':diff --git a/packages/core/src/internal/touch.test.ts b/packages/core/src/internal/touch.test.tsindex 781e603e1f..2496d07b82 100644--- a/packages/core/src/internal/touch.test.ts+++ b/packages/core/src/internal/touch.test.ts@@ -176,6 +176,18 @@ describe('internal/touch', () => {}});+ it('re-exports the action-group tracking hook by name', async () => {+ const entry: Record<string, unknown> = await import('./touch');+ // Identity alone passes when both sides are undefined.+ expect(typeof entry.useActionGroupTracking).toBe('function');+ const modules: Record<string, Record<string, unknown>> = {+ useActionGroupTracking: await import('../hooks/useActionGroupTracking'),+ };+ for (const [name, module] of Object.entries(modules)) {+ expect(entry[name], name).toBe(module[name]);+ }+ });+it('attaches no window or document listeners when it loads', async () => {vi.resetModules();const onWindow = vi.spyOn(window, 'addEventListener');diff --git a/packages/core/src/internal/touch.ts b/packages/core/src/internal/touch.tsindex f74dfe63c4..17a46322c9 100644--- a/packages/core/src/internal/touch.ts+++ b/packages/core/src/internal/touch.ts@@ -113,3 +113,7 @@ export {animatorFor} from '../motion/animator';export {reducedMotionFade} from '../motion/reducedMotion';export {useTouchHitArea} from '../utils/touchHitArea';export {touchHitAreaStyles} from './touchHitArea.stylex';++// Lab's TabBar tracks its press with the shared action-group tracker.+export {useActionGroupTracking} from '../hooks/useActionGroupTracking';+export type {ActionGroupTrackingOptions} from '../hooks/useActionGroupTracking';