Skip to content

ComponentsActions

SourceSource

Dropdown Menu

A menu that opens from a button, with icon, label and description items that highlight in brand color.

Use it for a list of actions that belong to one button: a server menu, the actions for a channel, a status picker. For a few controls or a short explanation use a Popover, and for a menu that opens on a right click use a Context Menu.

It is built on Radix Dropdown Menu in React and Reka UI Dropdown Menu in Vue. The primitive owns the behaviour; newt/ui owns the look. The menu opens below its trigger and start-aligned unless side and align say otherwise, and it flips when it would leave the viewport.

Root class newt-dropdown
import { buttonVariants } from "@/registry/bases/newt/ui/button"
import {
  Dropdown,
  DropdownContent,
  DropdownIcon,
  DropdownItem,
  DropdownItemDescription,
  DropdownItemLabel,
  DropdownItemText,
  DropdownSeparator,
  DropdownTrigger,
} from "@/registry/bases/newt/ui/dropdown"

export default function DropdownDemo() {
  return (
    <Dropdown>
      <DropdownTrigger className={buttonVariants({ variant: "secondary" })}>
        Options
      </DropdownTrigger>
      <DropdownContent>
        <DropdownItem>
          <DropdownIcon>{"⚡"}</DropdownIcon>
          <DropdownItemText>
            <DropdownItemLabel>Option label</DropdownItemLabel>
            <DropdownItemDescription>
              Option description
            </DropdownItemDescription>
          </DropdownItemText>
        </DropdownItem>
        <DropdownSeparator />
        <DropdownItem>
          <DropdownIcon>{"⚙"}</DropdownIcon>
          <DropdownItemText>
            <DropdownItemLabel>Another option</DropdownItemLabel>
            <DropdownItemDescription>Description</DropdownItemDescription>
          </DropdownItemText>
        </DropdownItem>
      </DropdownContent>
    </Dropdown>
  )
}
<script setup lang="ts">
import { buttonVariants } from "~~/registry/bases/newt/ui/button"
import {
  Dropdown,
  DropdownContent,
  DropdownIcon,
  DropdownItem,
  DropdownItemDescription,
  DropdownItemLabel,
  DropdownItemText,
  DropdownSeparator,
  DropdownTrigger,
} from "~~/registry/bases/newt/ui/dropdown"
</script>

<template>
  <Dropdown>
    <DropdownTrigger :class="buttonVariants({ variant: 'secondary' })">
      Options
    </DropdownTrigger>
    <DropdownContent>
      <DropdownItem>
        <DropdownIcon>&#x26A1;</DropdownIcon>
        <DropdownItemText>
          <DropdownItemLabel>Option label</DropdownItemLabel>
          <DropdownItemDescription>Option description</DropdownItemDescription>
        </DropdownItemText>
      </DropdownItem>
      <DropdownSeparator />
      <DropdownItem>
        <DropdownIcon>&#x2699;</DropdownIcon>
        <DropdownItemText>
          <DropdownItemLabel>Another option</DropdownItemLabel>
          <DropdownItemDescription>Description</DropdownItemDescription>
        </DropdownItemText>
      </DropdownItem>
    </DropdownContent>
  </Dropdown>
</template>

Installation

npx newtui@latest add dropdownnpx shadcn@latest add @newtui/dropdownnpx shadcn-vue@latest add @newtui/dropdownpnpm dlx newtui@latest add dropdownpnpm dlx shadcn@latest add @newtui/dropdownpnpm dlx shadcn-vue@latest add @newtui/dropdownyarn dlx newtui@latest add dropdownyarn dlx shadcn@latest add @newtui/dropdownyarn dlx shadcn-vue@latest add @newtui/dropdownbunx newtui@latest add dropdownbunx shadcn@latest add @newtui/dropdownbunx shadcn-vue@latest add @newtui/dropdowndeno run -A npm:newtui@latest add dropdowndeno run -A npm:shadcn@latest add @newtui/dropdowndeno run -A npm:shadcn-vue@latest add @newtui/dropdownvlx newtui@latest add dropdownvlx shadcn@latest add @newtui/dropdownvlx shadcn-vue@latest add @newtui/dropdownvp dlx newtui@latest add dropdownvp dlx shadcn@latest add @newtui/dropdownvp dlx shadcn-vue@latest add @newtui/dropdownnubx newtui@latest add dropdownnubx shadcn@latest add @newtui/dropdownnubx shadcn-vue@latest add @newtui/dropdownnlx newtui@latest add dropdownnlx shadcn@latest add @newtui/dropdownnlx shadcn-vue@latest add @newtui/dropdownupx newtui@latest add dropdownupx shadcn@latest add @newtui/dropdownupx shadcn-vue@latest add @newtui/dropdown

The shadcn CLI needs the @newtui registry in your components.json. Set it up.

Install the dependencies

npm install class-variance-authority radix-uipnpm add class-variance-authority radix-uiyarn add class-variance-authority radix-uibun add class-variance-authority radix-uideno add npm:class-variance-authority npm:radix-uivlt install class-variance-authority radix-uivp add class-variance-authority radix-uinub add class-variance-authority radix-uini class-variance-authority radix-uiupm add class-variance-authority radix-ui
npm install class-variance-authority reka-uipnpm add class-variance-authority reka-uiyarn add class-variance-authority reka-uibun add class-variance-authority reka-uideno add npm:class-variance-authority npm:reka-uivlt install class-variance-authority reka-uivp add class-variance-authority reka-uinub add class-variance-authority reka-uini class-variance-authority reka-uiupm add class-variance-authority reka-ui

Copy the source into your project

"use client"

import { cva, type VariantProps } from "class-variance-authority"
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui"
import * as React from "react"

import { cn } from "@/lib/utils"

/*
 * Radix owns the behaviour: open state, Escape and outside press, focus
 * return to the trigger, arrow keys, Home and End, typeahead, and
 * collision-aware placement. Only the look is newt/ui's.
 */
const Dropdown = DropdownMenuPrimitive.Root

/*
 * It has no look of its own. Pass `asChild` to put the state on your own
 * button, or the classes of the button it should be, for example
 * `className={buttonVariants({ variant: "secondary" })}`.
 */
const DropdownTrigger = DropdownMenuPrimitive.Trigger

const DropdownGroup = DropdownMenuPrimitive.Group

const DropdownRadioGroup = DropdownMenuPrimitive.RadioGroup

const DropdownContent = React.forwardRef<
  React.ComponentRef<typeof DropdownMenuPrimitive.Content>,
  React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content> & {
    /**
     * The element the menu is portalled into. Defaults to `document.body`;
     * pass the enclosing native `<dialog>` or a themed wrapper to keep it there.
     */
    container?: React.ComponentProps<
      typeof DropdownMenuPrimitive.Portal
    >["container"]
  }
>(
  (
    { className, align = "start", sideOffset = 4, container, ...props },
    ref
  ) => (
    <DropdownMenuPrimitive.Portal container={container}>
      <DropdownMenuPrimitive.Content
        ref={ref}
        align={align}
        sideOffset={sideOffset}
        className={cn(
          "z-[110] w-60 rounded-[var(--newt-radius-md)] border border-newt-border bg-newt-bg-floating p-1.5 text-newt-text-primary shadow-elevation-high outline-none",
          className
        )}
        {...props}
      />
    </DropdownMenuPrimitive.Portal>
  )
)
DropdownContent.displayName = "DropdownContent"

/*
 * `data-highlighted` is the primitive's one state for the pointer and the
 * keyboard, so it takes the place of the old `:hover` rule.
 */
const dropdownItemVariants = cva(
  "group flex cursor-pointer select-none items-center gap-2.5 rounded-[var(--newt-radius-sm)] px-2.5 py-2 outline-none transition-colors duration-fast ease-newt data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
  {
    variants: {
      variant: {
        default: "data-[highlighted]:bg-newt-brand",
        danger:
          "text-newt-danger data-[highlighted]:bg-newt-danger data-[highlighted]:text-newt-on-accent",
      },
    },
    defaultVariants: {
      variant: "default",
    },
  }
)

export interface DropdownItemProps
  extends
    React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item>,
    VariantProps<typeof dropdownItemVariants> {}

const DropdownItem = React.forwardRef<
  React.ComponentRef<typeof DropdownMenuPrimitive.Item>,
  DropdownItemProps
>(({ className, variant, ...props }, ref) => (
  <DropdownMenuPrimitive.Item
    ref={ref}
    className={cn(dropdownItemVariants({ variant }), className)}
    {...props}
  />
))
DropdownItem.displayName = "DropdownItem"

export interface DropdownRadioItemProps
  extends
    React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>,
    VariantProps<typeof dropdownItemVariants> {}

/*
 * The checked item keeps the brand fill, so the highlight on it is an inset
 * outline: without it the keyboard position is lost on the chosen item.
 */
const DropdownRadioItem = React.forwardRef<
  React.ComponentRef<typeof DropdownMenuPrimitive.RadioItem>,
  DropdownRadioItemProps
>(({ className, variant, ...props }, ref) => (
  <DropdownMenuPrimitive.RadioItem
    ref={ref}
    className={cn(
      dropdownItemVariants({ variant }),
      "data-[state=checked]:bg-newt-brand",
      "data-[state=checked]:data-[highlighted]:outline data-[state=checked]:data-[highlighted]:outline-2 data-[state=checked]:data-[highlighted]:-outline-offset-2 data-[state=checked]:data-[highlighted]:outline-newt-on-accent",
      className
    )}
    {...props}
  />
))
DropdownRadioItem.displayName = "DropdownRadioItem"

const DropdownLabel = React.forwardRef<
  React.ComponentRef<typeof DropdownMenuPrimitive.Label>,
  React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label>
>(({ className, ...props }, ref) => (
  <DropdownMenuPrimitive.Label
    ref={ref}
    className={cn(
      "px-2.5 py-1.5 text-xs font-bold uppercase tracking-[0.02em] text-newt-text-muted",
      className
    )}
    {...props}
  />
))
DropdownLabel.displayName = "DropdownLabel"

const DropdownSeparator = React.forwardRef<
  React.ComponentRef<typeof DropdownMenuPrimitive.Separator>,
  React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
>(({ className, ...props }, ref) => (
  <DropdownMenuPrimitive.Separator
    ref={ref}
    className={cn("mx-1.5 my-1 h-px bg-newt-border", className)}
    {...props}
  />
))
DropdownSeparator.displayName = "DropdownSeparator"

const DropdownIcon = React.forwardRef<
  HTMLSpanElement,
  React.HTMLAttributes<HTMLSpanElement>
>(({ className, ...props }, ref) => (
  <span
    ref={ref}
    aria-hidden="true"
    className={cn(
      "w-5 shrink-0 text-center text-newt-text-muted group-data-[highlighted]:text-newt-on-accent group-data-[state=checked]:text-newt-on-accent",
      className
    )}
    {...props}
  />
))
DropdownIcon.displayName = "DropdownIcon"

const DropdownItemText = React.forwardRef<
  HTMLDivElement,
  React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
  <div ref={ref} className={cn("min-w-0", className)} {...props} />
))
DropdownItemText.displayName = "DropdownItemText"

const DropdownItemLabel = React.forwardRef<
  HTMLDivElement,
  React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
  <div ref={ref} className={cn("text-sm font-medium", className)} {...props} />
))
DropdownItemLabel.displayName = "DropdownItemLabel"

const DropdownItemDescription = React.forwardRef<
  HTMLDivElement,
  React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
  <div
    ref={ref}
    className={cn(
      "text-xs text-newt-text-muted group-data-[highlighted]:text-[color-mix(in_srgb,var(--newt-on-accent)_75%,transparent)] group-data-[state=checked]:text-[color-mix(in_srgb,var(--newt-on-accent)_75%,transparent)]",
      className
    )}
    {...props}
  />
))
DropdownItemDescription.displayName = "DropdownItemDescription"

export {
  Dropdown,
  DropdownTrigger,
  DropdownContent,
  DropdownGroup,
  DropdownLabel,
  DropdownItem,
  DropdownRadioGroup,
  DropdownRadioItem,
  DropdownSeparator,
  DropdownIcon,
  DropdownItemText,
  DropdownItemLabel,
  DropdownItemDescription,
  dropdownItemVariants,
}
<script setup lang="ts">
import {
  DropdownMenuRoot,
  useForwardPropsEmits,
  type DropdownMenuRootEmits,
  type DropdownMenuRootProps,
} from "reka-ui"

/*
 * Reka owns the behaviour: open state, Escape and outside press, focus return
 * to the trigger, arrow keys, Home and End, typeahead, and collision-aware
 * placement. Use `v-model:open` to control it; without one the menu owns its
 * state. Only the look is newt/ui's.
 */
const props = defineProps<DropdownMenuRootProps>()
const emits = defineEmits<DropdownMenuRootEmits>()

const forwarded = useForwardPropsEmits(props, emits)
</script>

<template>
  <DropdownMenuRoot v-bind="forwarded">
    <slot />
  </DropdownMenuRoot>
</template>
<script setup lang="ts">
import { DropdownMenuTrigger, type DropdownMenuTriggerProps } from "reka-ui"

/*
 * It has no look of its own. Pass `as-child` to put the state on your own
 * button, or the classes of the button it should be, for example
 * `:class="buttonVariants({ variant: 'secondary' })"`.
 */
const props = defineProps<DropdownMenuTriggerProps>()
</script>

<template>
  <DropdownMenuTrigger v-bind="props">
    <slot />
  </DropdownMenuTrigger>
</template>
<script setup lang="ts">
import {
  DropdownMenuContent,
  DropdownMenuPortal,
  useForwardPropsEmits,
  type DropdownMenuContentEmits,
  type DropdownMenuContentProps,
} from "reka-ui"
import { computed, type HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

defineOptions({ inheritAttrs: false })

const props = withDefaults(
  defineProps<
    DropdownMenuContentProps & {
      class?: HTMLAttributes["class"]
      /**
       * The element it is portalled into. Defaults to `body`; pass the
       * enclosing native `<dialog>` or a themed wrapper to keep it there.
       */
      container?: string | HTMLElement
    }
  >(),
  { align: "start", sideOffset: 4 }
)
const emits = defineEmits<DropdownMenuContentEmits>()

const delegated = computed(() => {
  const { class: _class, container: _container, ...rest } = props
  return rest
})
const forwarded = useForwardPropsEmits(delegated, emits)
</script>

<template>
  <DropdownMenuPortal :to="props.container">
    <DropdownMenuContent
      v-bind="{ ...forwarded, ...$attrs }"
      :class="
        cn(
          'z-[110] w-60 rounded-[var(--newt-radius-md)] border border-newt-border bg-newt-bg-floating p-1.5 text-newt-text-primary shadow-elevation-high outline-none',
          props.class
        )
      "
    >
      <slot />
    </DropdownMenuContent>
  </DropdownMenuPortal>
</template>
<script setup lang="ts">
import { DropdownMenuGroup, type DropdownMenuGroupProps } from "reka-ui"

const props = defineProps<DropdownMenuGroupProps>()
</script>

<template>
  <DropdownMenuGroup v-bind="props">
    <slot />
  </DropdownMenuGroup>
</template>
<script setup lang="ts">
import {
  DropdownMenuLabel,
  useForwardProps,
  type DropdownMenuLabelProps,
} from "reka-ui"
import { computed, type HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<
  DropdownMenuLabelProps & { class?: HTMLAttributes["class"] }
>()

const delegated = computed(() => {
  const { class: _class, ...rest } = props
  return rest
})
const forwarded = useForwardProps(delegated)
</script>

<template>
  <DropdownMenuLabel
    v-bind="forwarded"
    :class="
      cn(
        'px-2.5 py-1.5 text-xs font-bold uppercase tracking-[0.02em] text-newt-text-muted',
        props.class
      )
    "
  >
    <slot />
  </DropdownMenuLabel>
</template>
<script setup lang="ts">
import {
  DropdownMenuItem,
  useForwardPropsEmits,
  type DropdownMenuItemEmits,
  type DropdownMenuItemProps,
} from "reka-ui"
import { computed, type HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

import { dropdownItemVariants, type DropdownItemVariants } from "."

const props = defineProps<
  DropdownMenuItemProps & {
    class?: HTMLAttributes["class"]
    variant?: DropdownItemVariants["variant"]
  }
>()
const emits = defineEmits<DropdownMenuItemEmits>()

const delegated = computed(() => {
  const { class: _class, variant: _variant, ...rest } = props
  return rest
})
const forwarded = useForwardPropsEmits(delegated, emits)
</script>

<template>
  <DropdownMenuItem
    v-bind="forwarded"
    :class="cn(dropdownItemVariants({ variant: props.variant }), props.class)"
  >
    <slot />
  </DropdownMenuItem>
</template>
<script setup lang="ts">
import {
  DropdownMenuRadioGroup,
  useForwardPropsEmits,
  type DropdownMenuRadioGroupEmits,
  type DropdownMenuRadioGroupProps,
} from "reka-ui"

/* Use `v-model` for the chosen value. */
const props = defineProps<DropdownMenuRadioGroupProps>()
const emits = defineEmits<DropdownMenuRadioGroupEmits>()

const forwarded = useForwardPropsEmits(props, emits)
</script>

<template>
  <DropdownMenuRadioGroup v-bind="forwarded">
    <slot />
  </DropdownMenuRadioGroup>
</template>
<script setup lang="ts">
import {
  DropdownMenuRadioItem,
  useForwardPropsEmits,
  type DropdownMenuRadioItemEmits,
  type DropdownMenuRadioItemProps,
} from "reka-ui"
import { computed, type HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

import { dropdownItemVariants, type DropdownItemVariants } from "."

/*
 * The checked item keeps the brand fill, so the highlight on it is an inset
 * outline: without it the keyboard position is lost on the chosen item.
 */
const props = defineProps<
  DropdownMenuRadioItemProps & {
    class?: HTMLAttributes["class"]
    variant?: DropdownItemVariants["variant"]
  }
>()
const emits = defineEmits<DropdownMenuRadioItemEmits>()

const delegated = computed(() => {
  const { class: _class, variant: _variant, ...rest } = props
  return rest
})
const forwarded = useForwardPropsEmits(delegated, emits)
</script>

<template>
  <DropdownMenuRadioItem
    v-bind="forwarded"
    :class="
      cn(
        dropdownItemVariants({ variant: props.variant }),
        'data-[state=checked]:bg-newt-brand',
        'data-[state=checked]:data-[highlighted]:outline data-[state=checked]:data-[highlighted]:outline-2 data-[state=checked]:data-[highlighted]:-outline-offset-2 data-[state=checked]:data-[highlighted]:outline-newt-on-accent',
        props.class
      )
    "
  >
    <slot />
  </DropdownMenuRadioItem>
</template>
<script setup lang="ts">
import {
  DropdownMenuSeparator,
  useForwardProps,
  type DropdownMenuSeparatorProps,
} from "reka-ui"
import { computed, type HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<
  DropdownMenuSeparatorProps & { class?: HTMLAttributes["class"] }
>()

const delegated = computed(() => {
  const { class: _class, ...rest } = props
  return rest
})
const forwarded = useForwardProps(delegated)
</script>

<template>
  <DropdownMenuSeparator
    v-bind="forwarded"
    :class="cn('mx-1.5 my-1 h-px bg-newt-border', props.class)"
  />
</template>
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>

<template>
  <span
    aria-hidden="true"
    :class="
      cn(
        'w-5 shrink-0 text-center text-newt-text-muted group-data-[highlighted]:text-newt-on-accent group-data-[state=checked]:text-newt-on-accent',
        props.class
      )
    "
  >
    <slot />
  </span>
</template>
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>

<template>
  <div :class="cn('min-w-0', props.class)">
    <slot />
  </div>
</template>
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>

<template>
  <div :class="cn('text-sm font-medium', props.class)">
    <slot />
  </div>
</template>
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>

<template>
  <div
    :class="
      cn(
        'text-xs text-newt-text-muted group-data-[highlighted]:text-[color-mix(in_srgb,var(--newt-on-accent)_75%,transparent)] group-data-[state=checked]:text-[color-mix(in_srgb,var(--newt-on-accent)_75%,transparent)]',
        props.class
      )
    "
  >
    <slot />
  </div>
</template>
import { cva, type VariantProps } from "class-variance-authority"

export { default as Dropdown } from "./Dropdown.vue"
export { default as DropdownTrigger } from "./DropdownTrigger.vue"
export { default as DropdownContent } from "./DropdownContent.vue"
export { default as DropdownGroup } from "./DropdownGroup.vue"
export { default as DropdownLabel } from "./DropdownLabel.vue"
export { default as DropdownItem } from "./DropdownItem.vue"
export { default as DropdownRadioGroup } from "./DropdownRadioGroup.vue"
export { default as DropdownRadioItem } from "./DropdownRadioItem.vue"
export { default as DropdownSeparator } from "./DropdownSeparator.vue"
export { default as DropdownIcon } from "./DropdownIcon.vue"
export { default as DropdownItemText } from "./DropdownItemText.vue"
export { default as DropdownItemLabel } from "./DropdownItemLabel.vue"
export { default as DropdownItemDescription } from "./DropdownItemDescription.vue"

/*
 * `data-highlighted` is the primitive's one state for the pointer and the
 * keyboard, so it takes the place of the old `:hover` rule.
 */
export const dropdownItemVariants = cva(
  "group flex cursor-pointer select-none items-center gap-2.5 rounded-[var(--newt-radius-sm)] px-2.5 py-2 outline-none transition-colors duration-fast ease-newt data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
  {
    variants: {
      variant: {
        default: "data-[highlighted]:bg-newt-brand",
        danger:
          "text-newt-danger data-[highlighted]:bg-newt-danger data-[highlighted]:text-newt-on-accent",
      },
    },
    defaultVariants: {
      variant: "default",
    },
  }
)

export type DropdownItemVariants = VariantProps<typeof dropdownItemVariants>

Update the import paths

The files import @/lib/utils and sibling components through the aliases in your components.json. Point them at wherever those live in your project.

No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Dropdown Menu to your React project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.

No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Dropdown Menu to your Vue project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.

Usage

import { Dropdown } from "@/components/ui/dropdown"

export function Example() {
  return <Dropdown />
}
<script setup lang="ts">
import { Dropdown, DropdownTrigger, DropdownContent, DropdownGroup, DropdownLabel, DropdownItem, DropdownRadioGroup, DropdownRadioItem, DropdownSeparator, DropdownIcon, DropdownItemText, DropdownItemLabel, DropdownItemDescription } from "@/components/ui/dropdown"
</script>

<template>
  <Dropdown />
</template>

DropdownTrigger is a plain button that carries the state and has no look of its own. Give it the classes of the button it should be (buttonVariants({ variant: "secondary" }) in the example), or use asChild (as-child in Vue) to put the state on your own button.

An item holds a DropdownIcon, then a DropdownItemText with a DropdownItemLabel and a DropdownItemDescription. Listen to onSelect (@select in Vue) for the choice. The menu closes after a choice; call event.preventDefault() in the handler to keep it open.

Examples

Labels only

DropdownIcon and DropdownItemDescription are optional. A label alone makes a compact action menu. Give the destructive action variant="danger" and keep it last, below a DropdownSeparator.

Root class newt-dropdown
import { buttonVariants } from "@/registry/bases/newt/ui/button"
import {
  Dropdown,
  DropdownContent,
  DropdownItem,
  DropdownItemLabel,
  DropdownSeparator,
  DropdownTrigger,
} from "@/registry/bases/newt/ui/dropdown"

/*
 * The icon and the description are optional: a label alone makes a compact
 * action menu. The destructive action sits last, apart, in the danger variant.
 */
export default function DropdownSimpleDemo() {
  return (
    <Dropdown>
      <DropdownTrigger className={buttonVariants({ variant: "secondary" })}>
        Channel actions
      </DropdownTrigger>
      <DropdownContent className="w-52">
        <DropdownItem>
          <DropdownItemLabel>Mark as read</DropdownItemLabel>
        </DropdownItem>
        <DropdownItem>
          <DropdownItemLabel>Mute channel</DropdownItemLabel>
        </DropdownItem>
        <DropdownItem>
          <DropdownItemLabel>Copy link</DropdownItemLabel>
        </DropdownItem>
        <DropdownSeparator />
        <DropdownItem variant="danger">
          <DropdownItemLabel>Leave server</DropdownItemLabel>
        </DropdownItem>
      </DropdownContent>
    </Dropdown>
  )
}
<script setup lang="ts">
import { buttonVariants } from "~~/registry/bases/newt/ui/button"
import {
  Dropdown,
  DropdownContent,
  DropdownItem,
  DropdownItemLabel,
  DropdownSeparator,
  DropdownTrigger,
} from "~~/registry/bases/newt/ui/dropdown"

/*
 * The icon and the description are optional: a label alone makes a compact
 * action menu. The destructive action sits last, apart, in the danger variant.
 */
</script>

<template>
  <Dropdown>
    <DropdownTrigger :class="buttonVariants({ variant: 'secondary' })">
      Channel actions
    </DropdownTrigger>
    <DropdownContent class="w-52">
      <DropdownItem>
        <DropdownItemLabel>Mark as read</DropdownItemLabel>
      </DropdownItem>
      <DropdownItem>
        <DropdownItemLabel>Mute channel</DropdownItemLabel>
      </DropdownItem>
      <DropdownItem>
        <DropdownItemLabel>Copy link</DropdownItemLabel>
      </DropdownItem>
      <DropdownSeparator />
      <DropdownItem variant="danger">
        <DropdownItemLabel>Leave server</DropdownItemLabel>
      </DropdownItem>
    </DropdownContent>
  </Dropdown>
</template>

One choice

DropdownRadioGroup holds one value, and each DropdownRadioItem names its own. The checked item keeps the brand fill, and a screen reader hears it as a checked radio item.

Root class newt-dropdown
"use client"

import * as React from "react"

import { buttonVariants } from "@/registry/bases/newt/ui/button"
import {
  Dropdown,
  DropdownContent,
  DropdownIcon,
  DropdownItemDescription,
  DropdownItemLabel,
  DropdownItemText,
  DropdownRadioGroup,
  DropdownRadioItem,
  DropdownTrigger,
} from "@/registry/bases/newt/ui/dropdown"

const STATUSES = [
  { value: "online", label: "Online", dot: "bg-newt-online" },
  { value: "idle", label: "Idle", dot: "bg-newt-idle" },
  {
    value: "dnd",
    label: "Do not disturb",
    description: "You will not get desktop notifications.",
    dot: "bg-newt-dnd",
  },
  {
    value: "invisible",
    label: "Invisible",
    description: "You appear offline but keep full access.",
    dot: "bg-newt-offline",
  },
]

/*
 * The radio group holds the choice: the parent keeps the value and the group
 * reports each change. The checked item keeps the brand fill.
 */
export default function DropdownStatusDemo() {
  const [status, setStatus] = React.useState("online")
  const current = STATUSES.find((item) => item.value === status)

  return (
    <Dropdown>
      <DropdownTrigger className={buttonVariants({ variant: "secondary" })}>
        Status: {current?.label}
      </DropdownTrigger>
      <DropdownContent>
        <DropdownRadioGroup value={status} onValueChange={setStatus}>
          {STATUSES.map((item) => (
            <DropdownRadioItem key={item.value} value={item.value}>
              <DropdownIcon>
                <span
                  className={`inline-block h-2.5 w-2.5 rounded-full ${item.dot}`}
                />
              </DropdownIcon>
              <DropdownItemText>
                <DropdownItemLabel>{item.label}</DropdownItemLabel>
                {item.description && (
                  <DropdownItemDescription>
                    {item.description}
                  </DropdownItemDescription>
                )}
              </DropdownItemText>
            </DropdownRadioItem>
          ))}
        </DropdownRadioGroup>
      </DropdownContent>
    </Dropdown>
  )
}
<script setup lang="ts">
import { computed, ref } from "vue"
import { buttonVariants } from "~~/registry/bases/newt/ui/button"
import {
  Dropdown,
  DropdownContent,
  DropdownIcon,
  DropdownItemDescription,
  DropdownItemLabel,
  DropdownItemText,
  DropdownRadioGroup,
  DropdownRadioItem,
  DropdownTrigger,
} from "~~/registry/bases/newt/ui/dropdown"

/*
 * The radio group holds the choice: the parent keeps the value and the group
 * reports each change. The checked item keeps the brand fill.
 */
const status = ref("online")

const statuses: {
  value: string
  label: string
  description?: string
  dot: string
}[] = [
  { value: "online", label: "Online", dot: "bg-newt-online" },
  { value: "idle", label: "Idle", dot: "bg-newt-idle" },
  {
    value: "dnd",
    label: "Do not disturb",
    description: "You will not get desktop notifications.",
    dot: "bg-newt-dnd",
  },
  {
    value: "invisible",
    label: "Invisible",
    description: "You appear offline but keep full access.",
    dot: "bg-newt-offline",
  },
]

const current = computed(() =>
  statuses.find((item) => item.value === status.value)
)
</script>

<template>
  <Dropdown>
    <DropdownTrigger :class="buttonVariants({ variant: 'secondary' })">
      Status: {{ current?.label }}
    </DropdownTrigger>
    <DropdownContent>
      <DropdownRadioGroup v-model="status">
        <DropdownRadioItem
          v-for="item in statuses"
          :key="item.value"
          :value="item.value"
        >
          <DropdownIcon>
            <span
              :class="['inline-block h-2.5 w-2.5 rounded-full', item.dot]"
            />
          </DropdownIcon>
          <DropdownItemText>
            <DropdownItemLabel>{{ item.label }}</DropdownItemLabel>
            <DropdownItemDescription v-if="item.description">
              {{ item.description }}
            </DropdownItemDescription>
          </DropdownItemText>
        </DropdownRadioItem>
      </DropdownRadioGroup>
    </DropdownContent>
  </Dropdown>
</template>

Your own button, groups and controlled state

asChild puts the menu state on a Button. DropdownGroup with a DropdownLabel names a set of items. Control the menu with open and onOpenChange in React, or v-model:open in Vue.

Root class newt-dropdown
"use client"

import * as React from "react"

import { Button } from "@/registry/bases/newt/ui/button"
import {
  Dropdown,
  DropdownContent,
  DropdownGroup,
  DropdownItem,
  DropdownItemLabel,
  DropdownLabel,
  DropdownSeparator,
  DropdownTrigger,
} from "@/registry/bases/newt/ui/dropdown"

const ACTIONS = ["Invite people", "Create channel", "Server settings"]

/*
 * `asChild` puts the menu state on your own button, and `open` with
 * `onOpenChange` lets the parent own it. `onSelect` reports the chosen item;
 * the menu then closes and hands focus back to the button by itself.
 */
export default function DropdownTriggerDemo() {
  const [open, setOpen] = React.useState(false)
  const [last, setLast] = React.useState("nothing yet")

  return (
    <div className="flex flex-col items-start gap-3">
      <Dropdown open={open} onOpenChange={setOpen}>
        <DropdownTrigger asChild>
          <Button variant="secondary">Server menu</Button>
        </DropdownTrigger>
        <DropdownContent>
          <DropdownGroup>
            <DropdownLabel>Server</DropdownLabel>
            {ACTIONS.map((action) => (
              <DropdownItem key={action} onSelect={() => setLast(action)}>
                <DropdownItemLabel>{action}</DropdownItemLabel>
              </DropdownItem>
            ))}
          </DropdownGroup>
          <DropdownSeparator />
          <DropdownItem
            variant="danger"
            onSelect={() => setLast("Leave server")}
          >
            <DropdownItemLabel>Leave server</DropdownItemLabel>
          </DropdownItem>
        </DropdownContent>
      </Dropdown>
      <p className="m-0 text-sm text-newt-text-muted" aria-live="polite">
        The menu is {open ? "open" : "closed"}. Last choice: {last}.
      </p>
    </div>
  )
}
<script setup lang="ts">
import { ref } from "vue"
import { Button } from "~~/registry/bases/newt/ui/button"
import {
  Dropdown,
  DropdownContent,
  DropdownGroup,
  DropdownItem,
  DropdownItemLabel,
  DropdownLabel,
  DropdownSeparator,
  DropdownTrigger,
} from "~~/registry/bases/newt/ui/dropdown"

/*
 * `as-child` puts the menu state on your own button, and `v-model:open` lets
 * the parent own it. `@select` reports the chosen item; the menu then closes
 * and hands focus back to the button by itself.
 */
const open = ref(false)
const last = ref("nothing yet")

const actions = ["Invite people", "Create channel", "Server settings"]
</script>

<template>
  <div class="flex flex-col items-start gap-3">
    <Dropdown v-model:open="open">
      <DropdownTrigger as-child>
        <Button variant="secondary">Server menu</Button>
      </DropdownTrigger>
      <DropdownContent>
        <DropdownGroup>
          <DropdownLabel>Server</DropdownLabel>
          <DropdownItem
            v-for="action in actions"
            :key="action"
            @select="last = action"
          >
            <DropdownItemLabel>{{ action }}</DropdownItemLabel>
          </DropdownItem>
        </DropdownGroup>
        <DropdownSeparator />
        <DropdownItem variant="danger" @select="last = 'Leave server'">
          <DropdownItemLabel>Leave server</DropdownItemLabel>
        </DropdownItem>
      </DropdownContent>
    </Dropdown>
    <p class="m-0 text-sm text-newt-text-muted" aria-live="polite">
      The menu is {{ open ? "open" : "closed" }}. Last choice: {{ last }}.
    </p>
  </div>
</template>

API reference

Dropdown

PropType
open / v-model:open?boolean

Whether the menu is shown. In React, leave it undefined and pass `defaultOpen` to let the menu own it.

Typeboolean
onOpenChange?(open: boolean) => void

React only. Called when the menu opens or closes; Vue emits `update:open`.

Type(open: boolean) => void
modal?boolean

When true, the page outside the menu does not react to the pointer while the menu is open.

Typeboolean
Defaulttrue

DropdownContent

PropType
side?"top" | "right" | "bottom" | "left"

Which side of the trigger the menu opens on. It flips when there is no room.

Type"top" | "right" | "bottom" | "left"
Default"bottom"
align?"start" | "center" | "end"

Which edge of the trigger the menu lines up with.

Type"start" | "center" | "end"
Default"start"
sideOffset?number

The gap between the trigger and the menu, in pixels.

Typenumber
Default4
loop?boolean

When true, the arrow keys move from the last item to the first and back.

Typeboolean
Defaultfalse
container?HTMLElement

Element the menu is portalled into. Pass the enclosing native `<dialog>` or a themed wrapper to keep it there.

TypeHTMLElement
Defaultdocument.body

DropdownItem

PropType
variant?"default" | "danger"

`danger` marks a destructive action.

Type"default" | "danger"
Default"default"
disabled?boolean

Dims the item. The pointer and the arrow keys then skip it.

Typeboolean
onSelect / @select?(event: Event) => void

Called when the item is chosen. Call `event.preventDefault()` to keep the menu open.

Type(event: Event) => void
textValue?string

The text typeahead matches. Set it when the item content is not plain text.

Typestring

DropdownRadioGroup

PropType
value / v-model?string

The value of the checked item.

Typestring
onValueChange?(value: string) => void

React only. Called when the choice changes; Vue emits `update:modelValue`.

Type(value: string) => void

DropdownRadioItem

PropType
value?string

The value this item gives to the group. Required.

Typestring
variant?"default" | "danger"

The same variants as `DropdownItem`.

Type"default" | "danger"
Default"default"
disabled?boolean

Dims the item. The pointer and the arrow keys then skip it.

Typeboolean

The registry exports Dropdown, DropdownTrigger, DropdownContent, DropdownGroup, DropdownLabel, DropdownItem, DropdownRadioGroup, DropdownRadioItem, DropdownSeparator, DropdownIcon, DropdownItemText, DropdownItemLabel, DropdownItemDescription and dropdownItemVariants. Parts without a table accept the props of the primitive part or the native element they render. React uses className; Vue uses class and fallthrough attributes.

Accessibility

The trigger carries aria-haspopup="menu", aria-expanded and, while the menu is open, aria-controls pointing at it. The panel is a role="menu" named by its trigger. Items are role="menuitem", and radio items are role="menuitemradio" with aria-checked. DropdownGroup is a role="group"; put a DropdownLabel inside it as its heading. DropdownIcon is hidden from screen readers, so the label must carry the meaning.

Enter, Space or ArrowDown on the trigger opens the menu and moves focus into it. The arrow keys, Home and End move between items. A typed letter moves to the next item that starts with it. Enter or Space chooses the focused item. Escape closes the menu, and so does a press outside. Focus returns to the trigger when the menu closes.

Tokens

Dropdown Menu reads its colours, radii and motion from the --newt-* tokens installed with the library. Override a token and every component that reads it follows, including this one — see the token layer. In the plain HTML and CSS distribution the same component is newt-dropdown.

  • --newt-bg-floating
  • --newt-border
  • --newt-radius-md
  • --newt-shadow-elevation-high
  • --newt-radius-sm
  • --newt-duration-fast
  • --newt-ease
  • --newt-brand
  • --newt-text-muted
  • --newt-on-accent