Popover
A small panel anchored to the button that opens it, closed by Escape or a press outside.
Use it for a few controls or a short explanation that belong to one button: notification settings for a channel, a filter, a confirmation that does not deserve a modal. For a list of actions use a Dropdown Menu, and for anything the reader must answer before going on use a Modal.
It is built on Radix Popover in React and Reka UI Popover in Vue. The panel opens below its trigger and start-aligned unless side and align say otherwise, and it flips when it would leave the viewport.
newt-popover"use client"
import * as React from "react"
import { Button, buttonVariants } from "@/registry/bases/newt/ui/button"
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/registry/bases/newt/ui/popover"
export default function PopoverDemo() {
const [open, setOpen] = React.useState(false)
const [muted, setMuted] = React.useState(false)
return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger className={buttonVariants({ variant: "secondary" })}>
Notification settings
</PopoverTrigger>
<PopoverContent aria-label="Notification settings">
<p className="m-0 font-semibold text-newt-text-primary">
{muted ? "This channel is muted" : "Mute this channel"}
</p>
<p className="m-0">
You will not be notified unless you are mentioned.
</p>
<Button
size="sm"
variant={muted ? "secondary" : "primary"}
onClick={() => {
setMuted(!muted)
setOpen(false)
}}
>
{muted ? "Unmute" : "Mute for 1 hour"}
</Button>
</PopoverContent>
</Popover>
)
}<script setup lang="ts">
import { ref } from "vue"
import { Button, buttonVariants } from "~~/registry/bases/newt/ui/button"
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "~~/registry/bases/newt/ui/popover"
const open = ref(false)
const muted = ref(false)
function toggleMute() {
muted.value = !muted.value
open.value = false
}
</script>
<template>
<Popover v-model:open="open">
<PopoverTrigger :class="buttonVariants({ variant: 'secondary' })">
Notification settings
</PopoverTrigger>
<PopoverContent aria-label="Notification settings">
<p class="m-0 font-semibold text-newt-text-primary">
{{ muted ? "This channel is muted" : "Mute this channel" }}
</p>
<p class="m-0">You will not be notified unless you are mentioned.</p>
<Button
size="sm"
:variant="muted ? 'secondary' : 'primary'"
@click="toggleMute"
>
{{ muted ? "Unmute" : "Mute for 1 hour" }}
</Button>
</PopoverContent>
</Popover>
</template>Installation
npx newtui@latest add popovernpx shadcn@latest add @newtui/popovernpx shadcn-vue@latest add @newtui/popoverpnpm dlx newtui@latest add popoverpnpm dlx shadcn@latest add @newtui/popoverpnpm dlx shadcn-vue@latest add @newtui/popoveryarn dlx newtui@latest add popoveryarn dlx shadcn@latest add @newtui/popoveryarn dlx shadcn-vue@latest add @newtui/popoverbunx newtui@latest add popoverbunx shadcn@latest add @newtui/popoverbunx shadcn-vue@latest add @newtui/popoverdeno run -A npm:newtui@latest add popoverdeno run -A npm:shadcn@latest add @newtui/popoverdeno run -A npm:shadcn-vue@latest add @newtui/popovervlx newtui@latest add popovervlx shadcn@latest add @newtui/popovervlx shadcn-vue@latest add @newtui/popovervp dlx newtui@latest add popovervp dlx shadcn@latest add @newtui/popovervp dlx shadcn-vue@latest add @newtui/popovernubx newtui@latest add popovernubx shadcn@latest add @newtui/popovernubx shadcn-vue@latest add @newtui/popovernlx newtui@latest add popovernlx shadcn@latest add @newtui/popovernlx shadcn-vue@latest add @newtui/popoverupx newtui@latest add popoverupx shadcn@latest add @newtui/popoverupx shadcn-vue@latest add @newtui/popover- newtui
- shadcn
- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
The shadcn CLI needs the @newtui registry in your components.json. Set it up.
Install the dependencies
npm install radix-uipnpm add radix-uiyarn add radix-uibun add radix-uideno add npm:radix-uivlt install radix-uivp add radix-uinub add radix-uini radix-uiupm add radix-ui- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
npm install reka-uipnpm add reka-uiyarn add reka-uibun add reka-uideno add npm:reka-uivlt install reka-uivp add reka-uinub add reka-uini reka-uiupm add reka-ui- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
Copy the source into your project
"use client"
import { Popover as PopoverPrimitive } 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, and collision-aware placement. Only the look is
* newt/ui's.
*/
const Popover = PopoverPrimitive.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 PopoverTrigger = PopoverPrimitive.Trigger
const PopoverAnchor = PopoverPrimitive.Anchor
const PopoverContent = React.forwardRef<
React.ComponentRef<typeof PopoverPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content> & {
/**
* The element the panel is portalled into. Defaults to `document.body`;
* pass the enclosing native `<dialog>` or a themed wrapper to keep it there.
*/
container?: React.ComponentProps<
typeof PopoverPrimitive.Portal
>["container"]
}
>(
(
{ className, align = "start", sideOffset = 8, container, ...props },
ref
) => (
<PopoverPrimitive.Portal container={container}>
<PopoverPrimitive.Content
ref={ref}
align={align}
sideOffset={sideOffset}
className={cn(
"z-[110] flex w-[280px] max-w-[90vw] flex-col items-start gap-2 rounded-[var(--newt-radius-md)] border border-newt-border bg-newt-bg-floating p-3 text-sm leading-5 text-newt-text-secondary shadow-elevation-high outline-none",
className
)}
{...props}
/>
</PopoverPrimitive.Portal>
)
)
PopoverContent.displayName = "PopoverContent"
export { Popover, PopoverTrigger, PopoverAnchor, PopoverContent }<script setup lang="ts">
import {
PopoverRoot,
useForwardPropsEmits,
type PopoverRootEmits,
type PopoverRootProps,
} from "reka-ui"
/*
* Reka owns the behaviour: open state, Escape and outside press, focus return
* to the trigger, and collision-aware placement. Use `v-model:open` to control
* it; without one the popover owns its state. Only the look is newt/ui's.
*/
const props = defineProps<PopoverRootProps>()
const emits = defineEmits<PopoverRootEmits>()
const forwarded = useForwardPropsEmits(props, emits)
</script>
<template>
<PopoverRoot v-bind="forwarded">
<slot />
</PopoverRoot>
</template><script setup lang="ts">
import { PopoverAnchor, type PopoverAnchorProps } from "reka-ui"
const props = defineProps<PopoverAnchorProps>()
</script>
<template>
<PopoverAnchor v-bind="props">
<slot />
</PopoverAnchor>
</template><script setup lang="ts">
import { PopoverTrigger, type PopoverTriggerProps } 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<PopoverTriggerProps>()
</script>
<template>
<PopoverTrigger v-bind="props">
<slot />
</PopoverTrigger>
</template><script setup lang="ts">
import {
PopoverContent,
PopoverPortal,
useForwardPropsEmits,
type PopoverContentEmits,
type PopoverContentProps,
} from "reka-ui"
import { computed, type HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
defineOptions({ inheritAttrs: false })
const props = withDefaults(
defineProps<
PopoverContentProps & {
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: 8 }
)
const emits = defineEmits<PopoverContentEmits>()
const delegated = computed(() => {
const { class: _class, container: _container, ...rest } = props
return rest
})
const forwarded = useForwardPropsEmits(delegated, emits)
</script>
<template>
<PopoverPortal :to="props.container">
<PopoverContent
v-bind="{ ...forwarded, ...$attrs }"
:class="
cn(
'z-[110] flex w-[280px] max-w-[90vw] flex-col items-start gap-2 rounded-[var(--newt-radius-md)] border border-newt-border bg-newt-bg-floating p-3 text-sm leading-5 text-newt-text-secondary shadow-elevation-high outline-none',
props.class
)
"
>
<slot />
</PopoverContent>
</PopoverPortal>
</template>export { default as Popover } from "./Popover.vue"
export { default as PopoverTrigger } from "./PopoverTrigger.vue"
export { default as PopoverAnchor } from "./PopoverAnchor.vue"
export { default as PopoverContent } from "./PopoverContent.vue"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 Popover 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 Popover 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 { Popover } from "@/components/ui/popover"
export function Example() {
return <Popover />
}<script setup lang="ts">
import { Popover, PopoverAnchor, PopoverTrigger, PopoverContent } from "@/components/ui/popover"
</script>
<template>
<Popover />
</template>API reference
Popover
open / v-model:open?boolean
Whether the panel is shown. In React, leave it undefined and pass `defaultOpen` to let the popover own it.
booleanonOpenChange?(open: boolean) => void
React only. Called when the popover opens or closes; Vue emits `update:open`.
(open: boolean) => voidPopoverContent
side?"top" | "right" | "bottom" | "left"
Which side of the trigger the panel opens on. It flips when there is no room.
"top" | "right" | "bottom" | "left""bottom"align?"start" | "center" | "end"
Which edge of the trigger the panel lines up with.
"start" | "center" | "end""start"container?HTMLElement
Element the panel is portalled into. Pass the enclosing native `<dialog>` or a themed wrapper to keep it there.
HTMLElementdocument.bodyPopoverTrigger 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. PopoverAnchor places the panel against another element than the trigger.
Accessibility
The trigger carries aria-expanded and, while the panel is open, aria-controls pointing at it. The panel is a role="dialog" and needs a name: pass aria-label to PopoverContent, or aria-labelledby naming a heading inside it. Focus moves into the panel when it opens and returns to the trigger when it closes. Escape closes it, and so does a press anywhere outside. Inside a drawer or a modal, Escape closes the popover first and the dialog on the next press.
Tokens
Popover 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-popover.
--newt-border--newt-radius-md--newt-bg-floating--newt-shadow-elevation-high--newt-text-secondary--newt-dir--newt-text-primary