Skip to main content

SandboxedOnClick

A container that prevents the click event from bubbling out of it.

Each table row will trigger a window.alert() when clicked. The icon button is wrapped in SandboxedOnClick and navigates you to the ngrok docs.

A list of your recent invoices.
InvoiceStatusMethodAmountActions
INV001PaidCredit Card$250.00
INV002PendingPayPal$150.00
INV003UnpaidBank Transfer$350.00
INV004PaidCredit Card$450.00
INV005PaidPayPal$550.00
INV006PendingBank Transfer$200.00
INV007UnpaidCredit Card$300.00
Total$2,500.00
import { IconButton } from "@ngrok/mantle/button";import { SandboxedOnClick } from "@ngrok/mantle/sandboxed-on-click";import { Table } from "@ngrok/mantle/table";import { BookIcon } from "@phosphor-icons/react/Book"; <Table.Root>	<Table.Element>		<Table.Caption>A list of your recent invoices.</Table.Caption>		<Table.Head>			<Table.Row>				<Table.Header className="w-25">Invoice</Table.Header>				<Table.Header>Status</Table.Header>				<Table.Header>Method</Table.Header>				<Table.Header className="text-right">Amount</Table.Header>				<Table.Header className="text-right">Actions</Table.Header>			</Table.Row>		</Table.Head>		<Table.Body>			{invoices.map((invoice) => (				<Table.Row					key={invoice.invoice}					className="cursor-pointer"					onClick={() => {						window.alert(`Clicked on ${invoice.invoice}!`);					}}				>					<Table.Cell className="font-medium">{invoice.invoice}</Table.Cell>					<Table.Cell>{invoice.paymentStatus}</Table.Cell>					<Table.Cell>{invoice.paymentMethod}</Table.Cell>					<Table.Cell className="text-right">{invoice.totalAmount}</Table.Cell>					<Table.Cell className="text-right">						<SandboxedOnClick allowClickEventDefault>							<IconButton								appearance="ghost"								intent="neutral"								size="sm"								label="See ngrok docs"								icon={<BookIcon />}								asChild							>								<a href="https://ngrok.com/docs" target="_blank" rel="noopener noreferrer" />							</IconButton>						</SandboxedOnClick>					</Table.Cell>				</Table.Row>			))}		</Table.Body>		<Table.Foot>			<Table.Row>				<Table.Cell colSpan={3}>Total</Table.Cell>				<Table.Cell className="text-right">$2,500.00</Table.Cell>				<Table.Cell />			</Table.Row>		</Table.Foot>	</Table.Element></Table.Root>;

Polymorphism

SandboxedOnClick accepts an asChild prop. When true, it renders its single child instead of its default <div>, forwarding the sandboxed onClick handler and the ref onto that child. The child keeps its own role: the default <div> carries role="presentation" because it exists only to catch bubbled clicks, but a presentational role on a link or button is a conflict that user agents ignore. Reach for this when the sandboxed click behavior should live directly on a semantic element such as an anchor, without an extra wrapper <div>.

import { SandboxedOnClick } from "@ngrok/mantle/sandboxed-on-click"; <SandboxedOnClick asChild allowClickEventDefault>	<a href="https://ngrok.com/docs" target="_blank" rel="noopener noreferrer">		See ngrok docs	</a></SandboxedOnClick>;

API Reference

SandboxedOnClick

A container that prevents the click event from bubbling out of it. Good to use when you want action buttons inside of a table row or list item that navigates on click.

All props from div, plus:

PropTypeDefaultDescription
allowClickEventDefaultbooleanfalseWhether the click keeps its default behavior. When false, the onClick handler calls event.preventDefault(); propagation stops either way. Set it to true for links or buttons that must navigate or run an action on click.
asChildbooleanfalseUse the asChild prop to compose the SandboxedOnClick functionality onto alternative element types or your own React components. The child keeps its own role.

sandboxedOnClickProps

sandboxedOnClickProps({ allowClickEventDefault?, onClick? }) returns the role="presentation" and onClick props the default <div> uses. When the component does not fit, apply them to your own element. If that element already has a role, take only onClick: role="presentation" on a <td> removes the cell from the table.

import { sandboxedOnClickProps } from "@ngrok/mantle/sandboxed-on-click"; const { onClick } = sandboxedOnClickProps({ allowClickEventDefault: true }); <td onClick={onClick}>	<Anchor href="https://ngrok.com/docs">See ngrok docs</Anchor></td>;