RadixUI Primitives Cheatsheet

Table of Contents

Taken from: https://github.com/tone-row/radix-primitives-cheatsheet

1. Accordion

https://www.radix-ui.com/docs/primitives/components/accordion

A vertically stacked set of interactive headings that each reveal an associated section of content.

Features

  • Full keyboard navigation.
  • Can expand one or multiple items.
  • Can be controlled or uncontrolled.
export default function App() {
  return (
    <Accordion.Root type="single" defaultValue="option-2">
      <Accordion.Item value="option-1">
        <Accordion.Header asChild>
          <Accordion.Trigger>Option 1</Accordion.Trigger>
        </Accordion.Header>
        <Accordion.Content>
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Quod
          voluptates ea aspernatur! Nesciunt culpa officiis, assumenda sequi,
          odit debitis, eos natus minima doloremque nemo vel sunt iste id at
          cupiditate.
        </Accordion.Content>
      </Accordion.Item>
      <Accordion.Item value="option-2">
        <Accordion.Header asChild>
          <Accordion.Trigger>Option 2</Accordion.Trigger>
        </Accordion.Header>
        <Accordion.Content>
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Quod
          voluptates ea aspernatur! Nesciunt culpa officiis, assumenda sequi,
          odit debitis, eos natus minima doloremque nemo vel sunt iste id at
          cupiditate.
        </Accordion.Content>
      </Accordion.Item>
    </Accordion.Root>
  );
}

2. AlertDialog

https://www.radix-ui.com/docs/primitives/components/alert-dialog

A modal dialog that interrupts the user with important content and expects a response.

Features

  • Focus is automatically trapped.
  • Can be controlled or uncontrolled.
  • Manages screen reader announcements with Title and Description components.
  • Esc closes the component automatically.
import * as AlertDialog from "@radix-ui/react-alert-dialog";

export default function App() {
  return (
    <AlertDialog.Root>
      <AlertDialog.Trigger>Click Me</AlertDialog.Trigger>
      <AlertDialog.Portal>
        <AlertDialog.Overlay
          style={{
            position: "fixed",
            top: 0,
            left: 0,
            right: 0,
            bottom: 0,
            background: "rgba(0, 0, 0, 0.5)",
          }}
        />
        <AlertDialog.Content
          style={{
            position: "fixed",
            top: "50%",
            left: "50%",
            transform: "translate(-50%, -50%)",
            background: "white",
          }}
        >
          <AlertDialog.Title>Hello World</AlertDialog.Title>
          <AlertDialog.Description>
            Lorem ipsum dolor sit amet consectetur, adipisicing elit. In
            exercitationem animi qui laudantium cum accusamus nulla nostrum.
            Quisquam natus voluptatibus rem laudantium accusamus, magnam atque
            quasi sunt officia quaerat ullam!
          </AlertDialog.Description>
          <AlertDialog.Cancel>Cancel</AlertDialog.Cancel>
          <AlertDialog.Action>OK</AlertDialog.Action>
        </AlertDialog.Content>
      </AlertDialog.Portal>
    </AlertDialog.Root>
  );
}

3. AspectRatio

https://www.radix-ui.com/docs/primitives/components/aspect-ratio

Displays content within a desired ratio.

Features

  • Accepts any custom ratio.
import * as AspectRatio from "@radix-ui/react-aspect-ratio";

export default function App() {
  return (
    <div style={{ width: "300px" }}>
      <AspectRatio.Root ratio={4 / 3} asChild>
        <img
          src="http://placekitten.com/400/400"
          alt="Kitten"
          style={{ width: "100%", height: "100%", objectFit: "cover" }}
        />
      </AspectRatio.Root>
    </div>
  );
}

4. Avatar

https://www.radix-ui.com/docs/primitives/components/avatar

An image element with a fallback for representing the user.

Features

  • Automatic and manual control over when the image renders.
  • Fallback part accepts any children.
  • Optionally delay fallback rendering to avoid content flashing.
import * as Avatar from "@radix-ui/react-avatar";

export default function App() {
  return (
    <Avatar.Root>
      <Avatar.Image
        src="http://placekitten.com/100/100"
        style={{ borderRadius: "50%" }}
      />
      <Avatar.Fallback>Kitten</Avatar.Fallback>
    </Avatar.Root>
  );
}

5. Checkbox

https://www.radix-ui.com/docs/primitives/components/checkbox

A control that allows the user to toggle between checked and not checked.

Features

  • Supports indeterminate state.
  • Full keyboard navigation.
  • Can be controlled or uncontrolled.
import * as Checkbox from "@radix-ui/react-checkbox";

export default function App() {
  return (
    <Checkbox.Root>
      <Checkbox.Indicator
        style={{
          width: 10,
          height: 10,
          backgroundColor: "black",
          display: "inline-block",
        }}
      />
      Checkbox Item
    </Checkbox.Root>
  );
}

6. Collapsible

https://www.radix-ui.com/docs/primitives/components/collapsible

An interactive component which expands/collapses a panel.

Features

  • Full keyboard navigation.
  • Can be controlled or uncontrolled.
import * as Collapsible from "@radix-ui/react-collapsible";

export default function App() {
  return (
    <Collapsible.Root>
      <Collapsible.Trigger>Collapsible Trigger</Collapsible.Trigger>
      <Collapsible.Content>
        Lorem ipsum dolor sit amet consectetur, adipisicing elit. Sequi
        temporibus, magni enim aspernatur repudiandae consequatur recusandae
        illo labore deleniti a necessitatibus aliquam ipsum. Molestias
        consequatur ut maiores veritatis. Voluptatum, optio.
      </Collapsible.Content>
    </Collapsible.Root>
  );
}

7. ContextMenu

https://www.radix-ui.com/docs/primitives/components/context-menu

Displays a menu located at the pointer, triggered by a right-click or a long-press.

Features

  • Supports submenus with configurable reading direction.
  • Supports items, labels, groups of items.
  • Supports checkable items (single or multiple).
  • Supports modal and non-modal modes.
  • Customize side, alignment, offsets, collision handling.
  • Focus is fully managed.
  • Full keyboard navigation.
  • Typeahead support.
  • Dismissing and layering behavior is highly customizable.
  • Triggers with a long-press on touch devices
import * as ContextMenu from "@radix-ui/react-context-menu";

export default function App() {
  return (
    <ContextMenu.Root>
      <ContextMenu.Trigger>
        Right-click this text to open a Context Menu
      </ContextMenu.Trigger>
      <ContextMenu.Content style={{ backgroundColor: "white" }}>
        <ContextMenu.Label>Items Label</ContextMenu.Label>
        <ContextMenu.Item>Item One</ContextMenu.Item>
        <ContextMenu.Item>Item Two</ContextMenu.Item>
        <ContextMenu.Item>Item Three</ContextMenu.Item>
        <ContextMenu.Separator
          style={{ height: "1px", backgroundColor: "black" }}
        />
        <ContextMenu.Label>Items Label</ContextMenu.Label>
        <ContextMenu.Item>Item Four</ContextMenu.Item>
        <ContextMenu.Item>Item Five</ContextMenu.Item>
        <ContextMenu.Item>Item Six</ContextMenu.Item>
      </ContextMenu.Content>
    </ContextMenu.Root>
  );
}

8. Dialog

https://www.radix-ui.com/docs/primitives/components/dialog

A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.

Features

  • Supports modal and non-modal modes.
  • Focus is automatically trapped when modal.
  • Can be controlled or uncontrolled.
  • Manages screen reader announcements with Title and Description components.
  • Esc closes the component automatically.
import * as Dialog from "@radix-ui/react-dialog";

export default function App() {
  return (
    <Dialog.Root>
      <Dialog.Trigger>Open a Dialog</Dialog.Trigger>
      <Dialog.Portal>
        <Dialog.Overlay
          style={{
            position: "fixed",
            top: 0,
            left: 0,
            right: 0,
            bottom: 0,
            background: "rgba(0, 0, 0, 0.5)",
          }}
        />
        <Dialog.Content
          style={{
            position: "fixed",
            top: "50%",
            left: "50%",
            transform: "translate(-50%, -50%)",
            background: "white",
          }}
        >
          <Dialog.Title>Dialog Title</Dialog.Title>
          <Dialog.Description>Dialog Description</Dialog.Description>
          <Dialog.Close>Close</Dialog.Close>
        </Dialog.Content>
      </Dialog.Portal>
    </Dialog.Root>
  );
}

9. DropdownMenu

https://www.radix-ui.com/docs/primitives/components/dropdown-menu

Displays a menu to the user—such as a set of actions or functions—triggered by a button.

Features

  • Can be controlled or uncontrolled.
  • Supports submenus with configurable reading direction.
  • Supports items, labels, groups of items.
  • Supports checkable items (single or multiple).
  • Supports modal and non-modal modes.
  • Customize side, alignment, offsets, collision handling.
  • Optionally render a pointing arrow.
  • Focus is fully managed.
  • Full keyboard navigation.
  • Typeahead support.
  • Dismissing and layering behavior is highly customizable.
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";

export default function App() {
  return (
    <DropdownMenu.Root>
      <DropdownMenu.Trigger>Open Dropdown Menu</DropdownMenu.Trigger>
      <DropdownMenu.Content>
        <DropdownMenu.Item>Item 1</DropdownMenu.Item>
        <DropdownMenu.Item>Item 2</DropdownMenu.Item>
      </DropdownMenu.Content>
    </DropdownMenu.Root>
  );
}

10. HoverCard

https://www.radix-ui.com/docs/primitives/components/hover-card

For sighted users to preview content available behind a link.

Features

  • Can be controlled or uncontrolled.
  • Customize side, alignment, offsets, collision handling.
  • Optionally render a pointing arrow.
  • Supports custom open and close delays.
  • Opens on hover only.
  • Ignored by screen readers.
import * as HoverCard from "@radix-ui/react-hover-card";

const cardBackgroundColor = "#ddd";

export default function App() {
  return (
    <HoverCard.Root>
      <HoverCard.Trigger>Trigger Hover Card</HoverCard.Trigger>
      <HoverCard.Content style={{ backgroundColor: cardBackgroundColor }}>
        Hover Card Content
        <HoverCard.Arrow style={{ fill: cardBackgroundColor }} />
      </HoverCard.Content>
    </HoverCard.Root>
  );
}

11. Label

https://www.radix-ui.com/docs/primitives/components/label

Renders an accessible label associated with controls.

Features

  • Text selection is prevented when double clicking label.
  • Supports nested controls.
  • Supports custom controls.
import * as Label from "@radix-ui/react-label";

export default function App() {
  return (
    <Label.Root htmlFor="firstName">
      First Name <input id="firstName" type="text" defaultValue="Robert" />
    </Label.Root>
  );
}

12. NavigationMenu

https://www.radix-ui.com/docs/primitives/components/navigation-menu

A collection of links for navigating websites.

Features

  • Can be controlled or uncontrolled.
  • Flexible layout structure with managed tab focus.
  • Supports submenus.
  • Optional active item indicator.
  • Full keyboard navigation.
  • Exposes CSS variables for advanced animation.
import * as NavigationMenu from "@radix-ui/react-navigation-menu";

export default function App() {
  return (
    <NavigationMenu.Root>
      <NavigationMenu.List>
        <NavigationMenu.Item>
          <NavigationMenu.Trigger>Trigger</NavigationMenu.Trigger>
          <NavigationMenu.Content>
            <NavigationMenu.List>
              <NavigationMenu.Item>
                <NavigationMenu.Link>Item 1</NavigationMenu.Link>
              </NavigationMenu.Item>
            </NavigationMenu.List>
          </NavigationMenu.Content>
        </NavigationMenu.Item>
        <NavigationMenu.Indicator />
      </NavigationMenu.List>
      <NavigationMenu.Viewport />
    </NavigationMenu.Root>
  );
}

13. Popover

https://www.radix-ui.com/docs/primitives/components/popover

Displays rich content in a portal, triggered by a button.

Features

  • Can be controlled or uncontrolled.
  • Customize side, alignment, offsets, collision handling.
  • Optionally render a pointing arrow.
  • Focus is fully managed and customizable.
  • Supports modal and non-modal modes.
  • Dismissing and layering behavior is highly customizable.
import * as Popover from "@radix-ui/react-popover";

const popoverBackgroundColor = "#ddd";

export default function App() {
  return (
    <Popover.Root modal>
      <Popover.Trigger>Trigger</Popover.Trigger>
      <Popover.Content style={{ backgroundColor: popoverBackgroundColor }}>
        This is the content
        <Popover.Close>Close</Popover.Close>
        <Popover.Arrow style={{ fill: popoverBackgroundColor }} />
      </Popover.Content>
    </Popover.Root>
  );
}

14. Progress

https://www.radix-ui.com/docs/primitives/components/progress

Displays an indicator showing the completion progress of a task, typically displayed as a progress bar.

Features

  • Provides context for assistive technology to read the progress of a task.
import * as Progress from "@radix-ui/react-progress";

const value = 75;

export default function App() {
  return (
    <Progress.Root
      value={value}
      max={100}
      style={{
        position: "relative",
        width: 300,
        height: 25,
        backgroundColor: "lightgrey",
      }}
    >
      <Progress.Indicator
        style={{ height: "100%", backgroundColor: "grey", width: value + "%" }}
      />
    </Progress.Root>
  );
}

15. RadioGroup

https://www.radix-ui.com/docs/primitives/components/radio-group

A set of checkable buttons—known as radio buttons—where no more than one of the buttons can be checked at a time.

Features

  • Full keyboard navigation.
  • Supports horizontal/vertical orientation.
  • Can be controlled or uncontrolled.
import * as RadioGroup from "@radix-ui/react-radio-group";
import { styled } from "@stitches/react";

const RadioGroupIndicator = styled(RadioGroup.Indicator, {
  width: "10px",
  height: "10px",
  display: "inline-block",
  backgroundColor: "black",
  borderRadius: "50%",
});

export default function App() {
  return (
    <RadioGroup.Root defaultValue="one">
      <RadioGroup.Item value="one">
        <RadioGroupIndicator />
        One
      </RadioGroup.Item>
      <RadioGroup.Item value="two">
        <RadioGroupIndicator />
        Two
      </RadioGroup.Item>
    </RadioGroup.Root>
  );
}

16. ScrollArea

https://www.radix-ui.com/docs/primitives/components/scroll-area

Augments native scroll functionality for custom, cross-browser styling.

Features

  • Scrollbar sits on top of the scrollable content, taking up no space.
  • Scrolling is native; no underlying position movements via CSS transformations.
  • Shims pointer behaviors only when interacting with the controls, so keyboard controls are unaffected.
  • Supports RTL
import * as ScrollArea from "@radix-ui/react-scroll-area";

export default function App() {
  return (
    <ScrollArea.Root
      style={{ width: "200px", height: "200px", overflow: "hidden" }}
    >
      <ScrollArea.Viewport style={{ width: "100%", height: "100%" }}>
        Lorem ipsum dolor sit amet consectetur, adipisicing elit. Amet aut
        sapiente possimus quisquam. Obcaecati eaque reprehenderit, dolor culpa
        recusandae delectus, inventore, libero voluptates sed a consequuntur
        natus repudiandae praesentium est? Lorem ipsum dolor sit amet
        consectetur, adipisicing elit. Amet aut sapiente possimus quisquam.
        Obcaecati eaque reprehenderit, dolor culpa recusandae delectus,
        inventore, libero voluptates sed a consequuntur natus repudiandae
        praesentium est?
      </ScrollArea.Viewport>
      <ScrollArea.Scrollbar
        orientation="vertical"
        style={{
          position: "absolute",
          top: 0,
          right: 0,
          width: 10,
          bottom: "var(--radix-scroll-area-corner-height)",
          backgroundColor: "lightgrey",
        }}
      >
        <ScrollArea.Thumb style={{ background: "darkgrey" }} />
      </ScrollArea.Scrollbar>
      <ScrollArea.Corner />
    </ScrollArea.Root>
  );
}

17. Select

https://www.radix-ui.com/docs/primitives/components/select

Displays a list of options for the user to pick from—triggered by a button.

Features

  • Can be controlled or uncontrolled.
  • Supports items, labels, groups of items.
  • Focus is fully managed.
  • Full keyboard navigation.
  • Typeahead support.
  • Supports Right to Left direction.
import * as Select from "@radix-ui/react-select";

export default function App() {
  return (
    <Select.Root defaultValue="Hello World">
      <Select.Trigger aria-label="Options">
        <Select.Value />
        <Select.Icon style={{ fontFamily: "sans-serif" }} />
      </Select.Trigger>
      <Select.Content style={{ background: "white" }}>
        <Select.ScrollUpButton />
        <Select.Viewport>
          <Select.Item value="Hello World">
            <Select.ItemText>Hello World</Select.ItemText>
            <Select.ItemIndicator />
          </Select.Item>
          <Select.Item value="Goodbye World">
            <Select.ItemText>Goodbye World</Select.ItemText>
            <Select.ItemIndicator />
          </Select.Item>
          <Select.Separator />
        </Select.Viewport>
        <Select.ScrollDownButton />
      </Select.Content>
    </Select.Root>
  );
}

18. Separator

https://www.radix-ui.com/docs/primitives/components/separator

Visually or semantically separates content.

Features

  • Supports horizontal and vertical orientations.
import * as Separator from "@radix-ui/react-separator";

export default function App() {
  return (
    <div>
      <span>Thing One</span>
      <Separator.Root asChild>
        <span>-</span>
      </Separator.Root>
      <span>Thing Two</span>
    </div>
  );
}

19. Slider

https://www.radix-ui.com/docs/primitives/components/slider

An input where the user selects a value from within a given range.

Features

  • Can be controlled or uncontrolled.
  • Supports multiple thumbs.
  • Supports a minimum value between thumbs.
  • Supports touch or click on track to update value.
  • Supports Right to Left direction.
  • Full keyboard navigation.
import * as Slider from "@radix-ui/react-slider";

export default function App() {
  return (
    <Slider.Root
      defaultValue={[50]}
      max={100}
      step={1}
      aria-label="Volume"
      style={{
        position: "relative",
        height: 10,
        background: "lightgrey",
        width: 300,
        display: "block",
      }}
    >
      <Slider.Track>
        <Slider.Range
          style={{
            position: "absolute",
            height: "100%",
            backgroundColor: "#666",
          }}
        />
      </Slider.Track>
      <Slider.Thumb
        style={{
          width: 10,
          height: 10,
          backgroundColor: "black",
          display: "block",
        }}
      />
    </Slider.Root>
  );
}

20. Switch

https://www.radix-ui.com/docs/primitives/components/switch

A control that allows the user to toggle between checked and not checked.

Features

  • Full keyboard navigation.
  • Can be controlled or uncontrolled.
import * as Switch from "@radix-ui/react-switch";
import { styled } from "@stitches/react";

const SwitchThumb = styled(Switch.Thumb, {
  width: "50%",
  background: "darkgrey",
  height: "100%",
  display: "block",
  position: "absolute",
  top: 0,
  left: 0,
  "&[data-state=checked]": {
    left: "50%",
  },
});

export default function App() {
  return (
    <Switch.Root style={{ width: 60, height: 30, position: "relative" }}>
      <SwitchThumb />
    </Switch.Root>
  );
}

21. Tabs

https://www.radix-ui.com/docs/primitives/components/tabs

A set of layered sections of content—known as tab panels—that are displayed one at a time.

Features

  • Can be controlled or uncontrolled.
  • Supports horizontal/vertical orientation.
  • Supports automatic/manual activation.
  • Full keyboard navigation.
import * as Tabs from "@radix-ui/react-tabs";

export default function App() {
  return (
    <Tabs.Root defaultValue="One">
      <Tabs.List>
        <Tabs.Trigger value="One">One</Tabs.Trigger>
        <Tabs.Trigger value="Two">Two</Tabs.Trigger>
      </Tabs.List>
      <Tabs.Content value="One">I am "One" content</Tabs.Content>
      <Tabs.Content value="Two">I am "Two" content</Tabs.Content>
    </Tabs.Root>
  );
}

22. Toast

https://www.radix-ui.com/docs/primitives/components/toast

A succinct message that is displayed temporarily.

Features

  • Automatically closes.
  • Pauses closing on hover, focus and window blur.
  • Supports hotkey to jump to toast viewport.
  • Supports closing via swipe gesture.
  • Exposes CSS variables for swipe gesture animations.
  • Can be controlled or uncontrolled.
import * as Toast from "@radix-ui/react-toast";
import { useState } from "react";

export default function App() {
  const [showToast, setShowToast] = useState(false);

  return (
    <Toast.Provider swipeDirection="right">
      <button onClick={() => setShowToast(true)}>Show 5 Second Toast</button>
      <Toast.Root open={showToast} onOpenChange={setShowToast}>
        <Toast.Title>Toast Title</Toast.Title>
        <Toast.Description>
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Quod saepe
          porro eius harum, rem eos voluptatem? Labore ipsum sed cumque fuga,
          veniam perferendis quo accusamus esse ab illo sint reiciendis!
        </Toast.Description>
        <Toast.Action>Action</Toast.Action>
        <Toast.Close>Close</Toast.Close>
      </Toast.Root>
      <Toast.Viewport style={{ position: "fixed", bottom: 20, right: 20 }} />
    </Toast.Provider>
  );
}

23. Toggle

https://www.radix-ui.com/docs/primitives/components/toggle

A two-state button that can be either on or off.

Features

  • Full keyboard navigation.
  • Can be controlled or uncontrolled.
import * as Toggle from "@radix-ui/react-toggle";
import { styled } from "@stitches/react";

const ToggleRoot = styled(Toggle.Root, {
  "&[aria-pressed=true]": {
    fontWeight: "bold",
    fontSize: "1.2em",
  },
});

export default function App() {
  return <ToggleRoot>This is a toggle</ToggleRoot>;
}

24. ToggleGroup

https://www.radix-ui.com/docs/primitives/components/toggle-group

A set of two-state buttons that can be toggled on or off.

Features

  • Full keyboard navigation.
  • Supports horizontal/vertical orientation.
  • Support single and multiple pressed buttons.
  • Can be controlled or uncontrolled.
import * as ToggleGroup from "@radix-ui/react-toggle-group";
import { styled } from "@stitches/react";

const ToggleGroupItem = styled(ToggleGroup.Item, {
  "&[aria-pressed=true]": {
    fontWeight: "bold",
    fontSize: "1.2em",
  },
});

export default function App() {
  return (
    <ToggleGroup.Root type="multiple" defaultValue={["a", "c"]}>
      <ToggleGroupItem value="a">Item A</ToggleGroupItem>
      <ToggleGroupItem value="b">Item B</ToggleGroupItem>
      <ToggleGroupItem value="c">Item C</ToggleGroupItem>
    </ToggleGroup.Root>
  );
}

25. Toolbar

https://www.radix-ui.com/docs/primitives/components/toolbar

A container for grouping a set of controls, such as buttons, toggle groups or dropdown menus.

Features

  • Full keyboard navigation.
import * as Toolbar from "@radix-ui/react-toolbar";

export default function App() {
  return (
    <Toolbar.Root style={{ display: "flex" }}>
      <Toolbar.Button>Toolbar Button</Toolbar.Button>
      <Toolbar.Separator />
      <Toolbar.Link>Some Link</Toolbar.Link>
      <Toolbar.ToggleGroup type="single">
        <Toolbar.ToggleItem value="a">Item A</Toolbar.ToggleItem>
        <Toolbar.ToggleItem value="b">Item B</Toolbar.ToggleItem>
        <Toolbar.ToggleItem value="c">Item C</Toolbar.ToggleItem>
      </Toolbar.ToggleGroup>
    </Toolbar.Root>
  );
}

26. Tooltip

https://www.radix-ui.com/docs/primitives/components/tooltip

A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.

Features

  • Provider to control display delay globally.
  • Opens when the trigger is focused or hovered.
  • Closes when the trigger is activated or when pressing escape.
  • Supports custom timings.
import * as Tooltip from "@radix-ui/react-tooltip";

const cardBackgroundColor = "#ddd";

export default function App() {
  return (
    <Tooltip.Provider>
      <Tooltip.Root>
        <Tooltip.Trigger>A Nice Tooltip</Tooltip.Trigger>
        <Tooltip.Content style={{ backgroundColor: cardBackgroundColor }}>
          <Tooltip.Arrow style={{ fill: cardBackgroundColor }} />
          Good News!
        </Tooltip.Content>
      </Tooltip.Root>
    </Tooltip.Provider>
  );
}

Author: Muhammad Ridho

Created: 2022-04-10 Sun 07:12

Validate