TapArea
TapArea allows components to be clickable and touchable in an accessible way.
Props
Basic TapArea

If you have a Link
or Button
inside of TapArea, you can apply e.stopPropagation()
so the onTap
doesn't get triggered.
Roles & Compress Behavior
Height & Width
Mouse Cursor
Rounding
ref
Accessibility: label, controls, expanded, & popup

Variants
This example illustrates two custom navigation implementations to externally control the link navigation behavior of TapArea: setting a default logic with OnLinkNavigationProvider and a custom component logic with the onClick
prop.
If onNavigation
prop is passed to OnLinkNavigationProvider, it's passed down to all children links and sets a custom default link navigation behavior. onLinkNavigation
is a higher-order function: it takes named arguments (href
and target
) and returns an event handler function. In the component's onClick
event handler, the onClick
prop gets called first, followed by the function passed down by the OnLinkNavigationProvider.
TapArea's onClick
prop is an event handler function. This callback takes 2 named parameters: 'event', the 'onClick' event, and disableOnNavigation
, a callback function that disables any default custom navigation logic set by OnLinkNavigationProvider. disableOnNavigation
is only accessible in OnLinkNavigationProvider's children components with link behavior.
In this example, TapArea has a parent OnLinkNavigationProvider setting a default custom navigation logic. We can compare three navigation behaviors: (a) the default TapArea behavior (by disabling the OnLinkNavigationProvider's inherited logic), (b) the default custom behavior set by OnLinkNavigationProvider and (c) a custom behavior set on TapArea.
onClick
is used to disable the default custom logic set in OnLinkNavigationProvider and implement custom behavior at the component level. disableOnNavigation
and customOnNavigation
are both called first during the 'onClick' event.
If onNavigation
is a custom hook function, it can contain complex logic, including React hooks, to perform side effects.
In this example, both onNavigation
and customOnNavigation
functions execute the following actions:
- Disable the default link behavior
- Show an alert message
- Open a different URL in a new window
Both onNavigationClick
, inside onNavigation
, and onClick
have event access to preventDefault(). It could also be used to stopPropagation().
Related
OnLinkNavigationProvider
Provider allows external link navigation control across all children components with link behavior.
See custom navigation variant for examples.