Documentation Index
Fetch the complete documentation index at: https://anvil.servicetitan.com/llms.txt
Use this file to discover all available pages before exploring further.
Beta FeatureThis feature is currently in beta, and needs to be imported from
@servicetitan/anvil2/beta.While we hope to minimize breaking changes, they may occur due to feedback we receive or other improvements. These will always be documented in the changelog and communicated in Slack.Please reach out in the #ask-designsystem channel with any questions or feedback!Overview
useAdaptiveView determines the optimal UI pattern (e.g., Dialog vs Popover) by combining two factors:
- Screen size: Viewport width relative to the
mdbreakpoint (768px) - Pointer precision: Whether the device has a coarse (touch) or fine (mouse/trackpad) primary pointer
| Device Type | Screen Size | Pointer | Result |
|---|---|---|---|
| Mobile phones | Small | Coarse (touch) | Mobile view |
| iPads/tablets | Large | Coarse (touch) | Desktop view |
| Touch laptops | Large | Fine (trackpad) | Desktop view |
| Desktop | Large | Fine (mouse) | Desktop view |
Import
Return Value
The hook returns an object with the following properties:| Property | Type | Description |
|---|---|---|
view | "mobile" | "desktop" | The current adaptive view type |
isMobile | boolean | true when the device should use mobile-optimized UI |
isDesktop | boolean | true when the device should use desktop-optimized UI |
Basic Usage
UseuseAdaptiveView to conditionally render different UI components based on the device:
Use Cases
Adaptive Selection Components
Components likeSelectField use this hook internally to render a full-screen dialog on mobile devices and a popover dropdown on desktop:
Form Input Optimization
Adjust form interactions based on device capabilities:Technical Details
Detection Method
The hook uses two browser APIs to detect device characteristics:useBreakpoint: Monitors viewport width against Anvil2 breakpoint tokens- CSS Media Query: Uses
(pointer: coarse)to detect touch-primary devices
Dynamic Updates
The hook automatically updates when:- The viewport is resized (e.g., browser window resized, device rotation)
- The pointer capability changes (e.g., connecting/disconnecting a mouse on a touch device)
SSR Compatibility
During server-side rendering, the hook defaults todesktop view since browser APIs are unavailable. The correct view is determined on the client after hydration.