Repository navigation
fix(ui): adapt console interactions for touch - #3262
RemiBonnet wants to merge 8 commits into
Conversation
|
View your CI Pipeline Execution ↗ for commit 9e8f60d
💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗ ☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
9 issues found and verified against the latest diff
Confidence score: 3/5
- Touch taps on
Button-wrapped tooltips can open the tooltip while also running the button action. Update the interactive-ancestor check intooltip.tsx. - Eligible non-interactive touch triggers can open and then immediately close their tooltip in
tooltip.tsx. Prevent the click default before opening the tooltip. - Closing the mobile list in
sidebar.tsxcan leave keyboard and screen-reader users focused in hidden content. Move focus to the menu button when the list closes. - On narrow screens,
Navbar.Item activecan remain off-screen innavbar.tsx. Track the rendered active item and rerun the scroll effect when it changes.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="libs/shared/util-hooks/src/lib/use-horizontal-overflow-fade/use-horizontal-overflow-fade.spec.tsx">
<violation number="1" location="libs/shared/util-hooks/src/lib/use-horizontal-overflow-fade/use-horizontal-overflow-fade.spec.tsx:53">
P2: This fit test does not establish a realistic fitting geometry because both scroll dimensions remain jsdom’s default `0`. Set `clientWidth` and `scrollWidth` to equal nonzero values so the test catches incorrect overflow calculations for content that fits.</violation>
</file>
<file name="libs/shared/ui/src/lib/components/tooltip/tooltip.tsx">
<violation number="1" location="libs/shared/ui/src/lib/components/tooltip/tooltip.tsx:41">
P2: Interactive ancestors are not excluded, so touch taps on existing `Button`-wrapped tooltip compositions open the tooltip while the button action runs. Check the interactive match without requiring it to be inside the trigger.</violation>
<violation number="2" location="libs/shared/ui/src/lib/components/tooltip/tooltip.tsx:42">
P2: Touch tooltips close immediately after this handler opens them because Radix’s `TooltipTrigger` runs `context.onClose` after the consumer `onClick`. Prevent the default click for eligible non-interactive triggers before setting `isTapOpen`, so Radix skips its close handler.</violation>
</file>
<file name="libs/shared/ui/src/lib/components/navbar/navbar.tsx">
<violation number="1" location="libs/shared/ui/src/lib/components/navbar/navbar.tsx:167">
P2: This lookup ignores the supported `Navbar.Item active` override, so an active item can remain off-screen and unreachable on narrow screens. Track the rendered active item in the root and rerun this effect when that active state changes.</violation>
<violation number="2" location="libs/shared/ui/src/lib/components/navbar/navbar.tsx:228">
P2: The both-edge overflow cue is invalid once a user scrolls to the middle: `FADE_BOTH_CLASS_NAME` generates `calc(100%-24px)`, which the browser rejects because `calc()` subtraction needs surrounding whitespace. Update the shared class to generate `calc(100% - 24px)` so the fade remains visible on both edges.</violation>
</file>
<file name="libs/shared/ui/src/lib/components/sidebar/sidebar.tsx">
<violation number="1" location="libs/shared/ui/src/lib/components/sidebar/sidebar.tsx:160">
P3: The mobile button label depends on a test ID to strip badge text, so a test-selector refactor can silently leak badge values into the user-facing label. Add a dedicated production marker (for example `data-sidebar-badge`) to `SidebarBadge` and query that marker here instead.</violation>
<violation number="2" location="libs/shared/ui/src/lib/components/sidebar/sidebar.tsx:183">
P3: The new mobile navigation toggle is missing `cursor-pointer`, so it does not expose the repository’s pointer affordance for this clickable navigation surface; add the class.
(Based on your team's feedback about pointer affordances to clickable items.)</violation>
<violation number="3" location="libs/shared/ui/src/lib/components/sidebar/sidebar.tsx:196">
P2: Closing the mobile list while its link still owns focus causes keyboard and screen-reader users to lose their place in a hidden subtree. Move focus to the menu button when closing the list, or to the destination page’s heading.</violation>
</file>
<file name="libs/shared/util-tests/src/lib/mock-pointer-coarse.ts">
<violation number="1" location="libs/shared/util-tests/src/lib/mock-pointer-coarse.ts:4">
P3: `mockPointerCoarse` overrides every media query, forcing non-pointer queries to `false`; tests that use it alongside viewport or other media-query behavior can silently exercise the wrong branch. Delegate unmatched queries to the original `matchMedia` implementation.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| it('applies nothing when the content fits', () => { | ||
| function Fits() { | ||
| const { ref, fadeClassName } = useHorizontalOverflowFade<HTMLDivElement>() | ||
| return <div data-testid="fits" ref={ref} className={fadeClassName} /> |
There was a problem hiding this comment.
P2: This fit test does not establish a realistic fitting geometry because both scroll dimensions remain jsdom’s default 0. Set clientWidth and scrollWidth to equal nonzero values so the test catches incorrect overflow calculations for content that fits.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At libs/shared/util-hooks/src/lib/use-horizontal-overflow-fade/use-horizontal-overflow-fade.spec.tsx, line 53:
<comment>This fit test does not establish a realistic fitting geometry because both scroll dimensions remain jsdom’s default `0`. Set `clientWidth` and `scrollWidth` to equal nonzero values so the test catches incorrect overflow calculations for content that fits.</comment>
<file context>
@@ -0,0 +1,58 @@
+ it('applies nothing when the content fits', () => {
+ function Fits() {
+ const { ref, fadeClassName } = useHorizontalOverflowFade<HTMLDivElement>()
+ return <div data-testid="fits" ref={ref} className={fadeClassName} />
+ }
+ renderWithProviders(<Fits />)
</file context>
| return <div data-testid="fits" ref={ref} className={fadeClassName} /> | |
| return ( | |
| <div | |
| data-testid="fits" | |
| ref={(node) => { | |
| if (node) { | |
| Object.defineProperty(node, 'clientWidth', { configurable: true, value: 100 }) | |
| Object.defineProperty(node, 'scrollWidth', { configurable: true, value: 100 }) | |
| } | |
| ref.current = node | |
| }} | |
| className={fadeClassName} | |
| /> | |
| ) |
| const handleTriggerClick = (event: MouseEvent<HTMLElement>) => { | ||
| if (!isTapControlled || isTapOpen || !(event.target instanceof Element)) return | ||
| const interactiveElement = event.target.closest(INTERACTIVE_SELECTOR) | ||
| if (interactiveElement && event.currentTarget.contains(interactiveElement)) return |
There was a problem hiding this comment.
P2: Interactive ancestors are not excluded, so touch taps on existing Button-wrapped tooltip compositions open the tooltip while the button action runs. Check the interactive match without requiring it to be inside the trigger.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At libs/shared/ui/src/lib/components/tooltip/tooltip.tsx, line 41:
<comment>Interactive ancestors are not excluded, so touch taps on existing `Button`-wrapped tooltip compositions open the tooltip while the button action runs. Check the interactive match without requiring it to be inside the trigger.</comment>
<file context>
@@ -29,16 +31,31 @@ export const Tooltip = forwardRef<ElementRef<typeof TooltipPrimitive.Trigger>, T
+ const handleTriggerClick = (event: MouseEvent<HTMLElement>) => {
+ if (!isTapControlled || isTapOpen || !(event.target instanceof Element)) return
+ const interactiveElement = event.target.closest(INTERACTIVE_SELECTOR)
+ if (interactiveElement && event.currentTarget.contains(interactiveElement)) return
+ setIsTapOpen(true)
+ onOpenChange?.(true)
</file context>
| if (interactiveElement && event.currentTarget.contains(interactiveElement)) return | |
| if (interactiveElement) return |
|
|
||
| useEffect(() => { | ||
| const container = scrollRef.current | ||
| const activeItem = activeId ? items.get(activeId) : undefined |
There was a problem hiding this comment.
P2: This lookup ignores the supported Navbar.Item active override, so an active item can remain off-screen and unreachable on narrow screens. Track the rendered active item in the root and rerun this effect when that active state changes.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At libs/shared/ui/src/lib/components/navbar/navbar.tsx, line 167:
<comment>This lookup ignores the supported `Navbar.Item active` override, so an active item can remain off-screen and unreachable on narrow screens. Track the rendered active item in the root and rerun this effect when that active state changes.</comment>
<file context>
@@ -154,6 +155,22 @@ const NavbarRoot = forwardRef<ElementRef<'div'>, NavbarRootProps>(function Navba
+
+ useEffect(() => {
+ const container = scrollRef.current
+ const activeItem = activeId ? items.get(activeId) : undefined
+ if (container && activeItem) {
+ scrollIntoViewHorizontally(container, activeItem, { align: 'nearest', margin: 16 })
</file context>
| ref={listRef} | ||
| id={listId} | ||
| onClick={(event) => { | ||
| if (event.target instanceof Element && event.target.closest('a[href]')) setMobileOpen(false) |
There was a problem hiding this comment.
P2: Closing the mobile list while its link still owns focus causes keyboard and screen-reader users to lose their place in a hidden subtree. Move focus to the menu button when closing the list, or to the destination page’s heading.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At libs/shared/ui/src/lib/components/sidebar/sidebar.tsx, line 196:
<comment>Closing the mobile list while its link still owns focus causes keyboard and screen-reader users to lose their place in a hidden subtree. Move focus to the menu button when closing the list, or to the destination page’s heading.</comment>
<file context>
@@ -135,10 +144,61 @@ const SidebarRoot = forwardRef<ElementRef<'div'>, SidebarRootProps>(function Sid
+ ref={listRef}
+ id={listId}
+ onClick={(event) => {
+ if (event.target instanceof Element && event.target.closest('a[href]')) setMobileOpen(false)
+ }}
+ className={twMerge('contents', mobileOpen ? 'max-md:mt-2 max-md:block' : 'max-md:hidden')}
</file context>
| if (!isTapControlled || isTapOpen || !(event.target instanceof Element)) return | ||
| const interactiveElement = event.target.closest(INTERACTIVE_SELECTOR) | ||
| if (interactiveElement && event.currentTarget.contains(interactiveElement)) return | ||
| setIsTapOpen(true) |
There was a problem hiding this comment.
P2: Touch tooltips close immediately after this handler opens them because Radix’s TooltipTrigger runs context.onClose after the consumer onClick. Prevent the default click for eligible non-interactive triggers before setting isTapOpen, so Radix skips its close handler.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At libs/shared/ui/src/lib/components/tooltip/tooltip.tsx, line 42:
<comment>Touch tooltips close immediately after this handler opens them because Radix’s `TooltipTrigger` runs `context.onClose` after the consumer `onClick`. Prevent the default click for eligible non-interactive triggers before setting `isTapOpen`, so Radix skips its close handler.</comment>
<file context>
@@ -29,16 +31,31 @@ export const Tooltip = forwardRef<ElementRef<typeof TooltipPrimitive.Trigger>, T
+ if (!isTapControlled || isTapOpen || !(event.target instanceof Element)) return
+ const interactiveElement = event.target.closest(INTERACTIVE_SELECTOR)
+ if (interactiveElement && event.currentTarget.contains(interactiveElement)) return
+ setIsTapOpen(true)
+ onOpenChange?.(true)
+ }
</file context>
| setIsTapOpen(true) | |
| event.preventDefault() | |
| setIsTapOpen(true) |
| onScroll={updateOverflow} | ||
| className={twMerge( | ||
| 'relative -my-1 -ml-3 -mr-1 flex touch-pan-x flex-row items-center justify-start overflow-x-auto px-1 py-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden', | ||
| overflowFadeClassName |
There was a problem hiding this comment.
P2: The both-edge overflow cue is invalid once a user scrolls to the middle: FADE_BOTH_CLASS_NAME generates calc(100%-24px), which the browser rejects because calc() subtraction needs surrounding whitespace. Update the shared class to generate calc(100% - 24px) so the fade remains visible on both edges.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At libs/shared/ui/src/lib/components/navbar/navbar.tsx, line 228:
<comment>The both-edge overflow cue is invalid once a user scrolls to the middle: `FADE_BOTH_CLASS_NAME` generates `calc(100%-24px)`, which the browser rejects because `calc()` subtraction needs surrounding whitespace. Update the shared class to generate `calc(100% - 24px)` so the fade remains visible on both edges.</comment>
<file context>
@@ -203,7 +220,14 @@ const NavbarRoot = forwardRef<ElementRef<'div'>, NavbarRootProps>(function Navba
+ onScroll={updateOverflow}
+ className={twMerge(
+ 'relative -my-1 -ml-3 -mr-1 flex touch-pan-x flex-row items-center justify-start overflow-x-auto px-1 py-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden',
+ overflowFadeClassName
+ )}
+ >
</file context>
| aria-expanded={mobileOpen} | ||
| aria-controls={listId} | ||
| onClick={() => setMobileOpen(!mobileOpen)} | ||
| className="mx-4 flex items-center gap-2 rounded-md border border-neutral bg-surface-neutral px-3 py-2 text-sm font-medium text-neutral md:hidden" |
There was a problem hiding this comment.
P3: The new mobile navigation toggle is missing cursor-pointer, so it does not expose the repository’s pointer affordance for this clickable navigation surface; add the class.
(Based on your team's feedback about pointer affordances to clickable items.)
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At libs/shared/ui/src/lib/components/sidebar/sidebar.tsx, line 183:
<comment>The new mobile navigation toggle is missing `cursor-pointer`, so it does not expose the repository’s pointer affordance for this clickable navigation surface; add the class.
(Based on your team's feedback about pointer affordances to clickable items.) </comment>
<file context>
@@ -135,10 +144,61 @@ const SidebarRoot = forwardRef<ElementRef<'div'>, SidebarRootProps>(function Sid
+ aria-expanded={mobileOpen}
+ aria-controls={listId}
+ onClick={() => setMobileOpen(!mobileOpen)}
+ className="mx-4 flex items-center gap-2 rounded-md border border-neutral bg-surface-neutral px-3 py-2 text-sm font-medium text-neutral md:hidden"
+ >
+ <Icon iconName="bars" iconStyle="regular" className="text-neutral-subtle" />
</file context>
| className="mx-4 flex items-center gap-2 rounded-md border border-neutral bg-surface-neutral px-3 py-2 text-sm font-medium text-neutral md:hidden" | |
| className="mx-4 flex cursor-pointer items-center gap-2 rounded-md border border-neutral bg-surface-neutral px-3 py-2 text-sm font-medium text-neutral md:hidden" |
| const updateLabel = () => { | ||
| const current = list.querySelector('[aria-current="page"]')?.cloneNode(true) | ||
| if (!(current instanceof HTMLElement)) return setCurrentLabel('') | ||
| current.querySelectorAll('[data-testid="sidebar-badge"]').forEach((badge) => badge.remove()) |
There was a problem hiding this comment.
P3: The mobile button label depends on a test ID to strip badge text, so a test-selector refactor can silently leak badge values into the user-facing label. Add a dedicated production marker (for example data-sidebar-badge) to SidebarBadge and query that marker here instead.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At libs/shared/ui/src/lib/components/sidebar/sidebar.tsx, line 160:
<comment>The mobile button label depends on a test ID to strip badge text, so a test-selector refactor can silently leak badge values into the user-facing label. Add a dedicated production marker (for example `data-sidebar-badge`) to `SidebarBadge` and query that marker here instead.</comment>
<file context>
@@ -135,10 +144,61 @@ const SidebarRoot = forwardRef<ElementRef<'div'>, SidebarRootProps>(function Sid
+ const updateLabel = () => {
+ const current = list.querySelector('[aria-current="page"]')?.cloneNode(true)
+ if (!(current instanceof HTMLElement)) return setCurrentLabel('')
+ current.querySelectorAll('[data-testid="sidebar-badge"]').forEach((badge) => badge.remove())
+ setCurrentLabel(current.textContent?.trim() ?? '')
+ }
</file context>
| // Makes `matchMedia('(pointer: coarse)')` match, as on a touch screen. Returns a function restoring the original. | ||
| export function mockPointerCoarse(coarse = true) { | ||
| const originalMatchMedia = window.matchMedia | ||
| window.matchMedia = jest.fn().mockImplementation((query: string) => ({ |
There was a problem hiding this comment.
P3: mockPointerCoarse overrides every media query, forcing non-pointer queries to false; tests that use it alongside viewport or other media-query behavior can silently exercise the wrong branch. Delegate unmatched queries to the original matchMedia implementation.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At libs/shared/util-tests/src/lib/mock-pointer-coarse.ts, line 4:
<comment>`mockPointerCoarse` overrides every media query, forcing non-pointer queries to `false`; tests that use it alongside viewport or other media-query behavior can silently exercise the wrong branch. Delegate unmatched queries to the original `matchMedia` implementation.</comment>
<file context>
@@ -0,0 +1,15 @@
+// Makes `matchMedia('(pointer: coarse)')` match, as on a touch screen. Returns a function restoring the original.
+export function mockPointerCoarse(coarse = true) {
+ const originalMatchMedia = window.matchMedia
+ window.matchMedia = jest.fn().mockImplementation((query: string) => ({
+ matches: coarse && query === '(pointer: coarse)',
+ media: query,
</file context>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## fix/console-mobile-responsive #3262 +/- ##
=================================================================
+ Coverage 55.08% 55.45% +0.36%
=================================================================
Files 1470 1473 +3
Lines 33441 33543 +102
Branches 9994 10028 +34
=================================================================
+ Hits 18421 18600 +179
+ Misses 12291 12188 -103
- Partials 2729 2755 +26
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Issue: Original work in #3257 and #3258
This is the second PR of the revised mobile Console split from #3257 and #3258. It is stacked on #3261; retarget it to
stagingafter the responsive PR is merged.Review touch interactions, keyboard navigation, and overflow handling.
Screenshots / Recordings
The responsive layout and the source preview are linked in the first PR.
Testing
60 targeted Jest tests passed. ESLint reported zero errors on the changed files.
yarn testoryarn test -u(if you need to regenerate snapshots)yarn lintPR Checklist
.cursor/rules)feat(service): add new Terraform service) - required for semantic-releaseOpen in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Summary by cubic
Adapts console interactions for touch screens: tooltips open on tap, virtual keyboards stay closed until needed, and scrollable areas keep their active item and overflow visible.
mdthat shows the current section, while keeping arrow-key navigation between the actual links.isTouchScreen,scrollIntoViewHorizontally,useHorizontalOverflowFade) with unit coverage.Written for commit 9e8f60d. Summary will update on new commits.