Native Solid 2 fork. Original documentation and designs © WorkOS; historical posts retain their original context.

Getting started

A quick tutorial to get you up and running with Radix Primitives.

Implementing a Popover

In this quick tutorial, we will install and style the Popover component.

1. Install the primitive

Primitives is published on npm as 0.1.0-rc.4 (release candidate, dist-tag next): @wsagency/radix2solid-primitives@0.1.0-rc.4. The earlier published rc.2 does not include the new families. The npm latest tag still points to rc.1 for this package, so pin the version explicitly. The published release requires solid-js and @solidjs/web 2.0.0-rc.15 compiled by @solidjs/vite-plugin 3.0.0-next.50:

npm install -E @wsagency/radix2solid-primitives@0.1.0-rc.4
pnpm add -E @wsagency/radix2solid-primitives@0.1.0-rc.4

Pin the complete Solid RC15 graph using the workspace setup. The runnable Combobox sandbox includes exact npm package versions, Solid overrides, build tool configuration, and license files.

2. Import the parts

Import and structure the parts.

// index.tsx
import { Popover } from "@wsagency/radix2solid-primitives";
const PopoverDemo = () => <Popover.Root>
<Popover.Trigger>More info</Popover.Trigger>
<Popover.Portal>
<Popover.Content aria-label="More info" aria-describedby={undefined}>
Some more info…
<Popover.Arrow />
</Popover.Content>
</Popover.Portal>
</Popover.Root>;
export default PopoverDemo;

Each primitive is also available from its own entrypoint. Importing from the subpath can help some bundlers tree-shake more effectively:

import * as Popover from "@wsagency/radix2solid-primitives/popover";

3. Add your styles

Add styles where desired.

// index.tsx
import { Popover } from "@wsagency/radix2solid-primitives";
import "./styles.css";
const PopoverDemo = () => <Popover.Root>
<Popover.Trigger class="PopoverTrigger">Show info</Popover.Trigger>
<Popover.Portal>
<Popover.Content class="PopoverContent" aria-label="Show info" aria-describedby={undefined}>
Some content
<Popover.Arrow class="PopoverArrow" />
</Popover.Content>
</Popover.Portal>
</Popover.Root>;
export default PopoverDemo;
/* styles.css */
.PopoverTrigger {
background-color: white;
border-radius: 4px;
}
.PopoverContent {
border-radius: 4px;
padding: 20px;
width: 260px;
background-color: white;
}
.PopoverArrow {
fill: white;
}

Demo

Here's a complete demo.

Download runnable sandbox
import { Popover } from "@wsagency/radix2solid-primitives";
import "./styles.css";
const PopoverDemo = () => <Popover.Root>
<Popover.Trigger class="PopoverTrigger">More info</Popover.Trigger>
<Popover.Portal>
<Popover.Content class="PopoverContent" sideOffset={5} aria-label="More info" aria-describedby={undefined}>
Some more info…
<Popover.Arrow class="PopoverArrow" />
</Popover.Content>
</Popover.Portal>
</Popover.Root>;
export default PopoverDemo;

Summary

The steps above outline briefly what's involved in using a Radix Primitive in your application.

These components are low-level enough to give you control over how you want to wrap them. You're free to introduce your own high-level API to better suit the needs of your team and product.

In a few simple steps, we've implemented a fully accessible Popover component, without having to worry about many of its complexities.

  • Adheres to WAI-ARIA design pattern.
  • Can be controlled or uncontrolled.
  • Customize side, alignment, offsets, collision handling.
  • Optionally render a pointing arrow.
  • Focus is fully managed and customizable.
  • Dismissing and layering behavior is highly customizable.