Skip to content

fix(website): Make custom tooltips clickable on mobile#6427

Open
tombch wants to merge 8 commits into
mainfrom
multifieldsearch-tooltip-clickable
Open

fix(website): Make custom tooltips clickable on mobile#6427
tombch wants to merge 8 commits into
mainfrom
multifieldsearch-tooltip-clickable

Conversation

@tombch
Copy link
Copy Markdown
Collaborator

@tombch tombch commented May 13, 2026

  • Updates the CustomTooltip component to be clickable on touchscreen only, and hover-able otherwise.
  • This PR was opened because I noticed the tooltip for multi field search and the date range field was not clickable on mobile, and sometimes flickered into view, due to being triggered by the hovering event.

PR Checklist

  • All necessary documentation has been adapted.
  • The implemented feature is covered by appropriate, automated tests.
  • Any manual testing that has been done is documented (i.e. what exactly was tested?)

🚀 Preview: https://multifieldsearch-tooltip.loculus.org

@tombch tombch added the preview Triggers a deployment to argocd label May 13, 2026
@claude claude Bot added the website Tasks related to the web application label May 13, 2026
@tombch tombch changed the title fix(website): Make multi field search tooltip clickable and focusable fix(website): Make custom tooltips clickable on mobile May 18, 2026
@tombch tombch marked this pull request as ready for review May 18, 2026 11:33
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 18, 2026

Claude finished @tombch's task in 2m 5s —— View job


Code Review

  • Read changed files and gather context
  • Analyze code quality, security, performance, and accessibility

Good fix overall. The approach of using window.matchMedia('(pointer: coarse)') to distinguish touch-only devices is sensible. A few issues worth addressing:

SSR/Hydration mismatch — the most significant concern. isTouchOnly is computed inline during render. In Astro with SSR, window is undefined server-side, so the server always renders with isTouchOnly = false. On a touch device, the client re-renders with isTouchOnly = true, creating a mismatch. Between SSR render and hydration, hover events may briefly fire on touch devices. The fix is to use useState + useEffect:

const [isTouchOnly, setIsTouchOnly] = useState(false);
useEffect(() => {
    setIsTouchOnly(window.matchMedia('(pointer: coarse)').matches);
}, []);

Accessibility — the help icon Button in MultiFieldSearchField.tsx has no aria-label, so screen readers will announce an unlabeled button. Add aria-label="Field information" (or similar).

DateRangeField interactionDateRangeField.tsx wasn't changed, but the tooltip anchor there is a <label> wrapping a checkbox. On mobile with click as the open event, tapping the label will both toggle the checkbox and open the tooltip simultaneously, which may be surprising. Worth checking that this works as intended, or moving the tooltip anchor to a separate element.

Fix hydration issue in CustomTooltip →


export const CustomTooltip: FC<ComponentProps<typeof Tooltip>> = ({ className, ...props }) => (
export const CustomTooltip: FC<ComponentProps<typeof Tooltip>> = ({ className, ...props }) => {
const isTouchOnly = typeof window !== 'undefined' && window.matchMedia('(pointer: coarse)').matches;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runs during render and causes an SSR/hydration mismatch in Astro — the server renders with isTouchOnly = false (no window), but a touch client re-renders with true. Between SSR and hydration, hover events briefly fire on touch devices. Prefer useState(false) + useEffect:

Suggested change
const isTouchOnly = typeof window !== 'undefined' && window.matchMedia('(pointer: coarse)').matches;
const [isTouchOnly, setIsTouchOnly] = useState(false);
useEffect(() => {
setIsTouchOnly(window.matchMedia('(pointer: coarse)').matches);
}, []);

And update the import to import { type ComponentProps, type FC, useEffect, useState } from 'react';

Copy link
Copy Markdown
Collaborator Author

@tombch tombch May 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't cause a SSR issue as far as I understand, as isTouchOnly doesn't affect the rendered DOM. So I think adding state and an effect here is unnecessary. I also tested this with firefox's mobile browsing simulator and it didn't come up with any hydration errors

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think it's because the tooltip isn't rendered until you mouseover

Comment thread website/src/components/SearchPage/fields/MultiFieldSearchField.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Triggers a deployment to argocd website Tasks related to the web application

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants