Separator
nswds-ui/separatorFreeComponent
A semantic or decorative divider built on the Base UI separator primitive.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/digitalnsw/nswds-ui/main/apps/registry/public/r/separator.jsonSource
1'use client'23import type * as React from 'react'45import { Separator as SeparatorPrimitive } from '@base-ui/react/separator'67import { cn } from '@/lib/utils'89type SeparatorProps = SeparatorPrimitive.Props & {10 /**11 * When true, the separator is purely presentational and is hidden from12 * assistive tech by setting `role="none"`. Defaults to `false`, in which13 * case Base UI's default `role="separator"` is left intact so AT users14 * hear it as a region boundary.15 */16 decorative?: boolean17}1819function Separator({20 className,21 orientation = 'horizontal',22 decorative = false,23 role,24 ref,25 ...props26}: SeparatorProps) {27 // Base UI's Separator emits `data-orientation="horizontal|vertical"` for28 // CSS targeting AND `aria-orientation` for assistive tech. The previous29 // `data-horizontal:` / `data-vertical:` selectors targeted non-existent30 // boolean attributes and never matched, leaving the separator with no31 // explicit axis sizing.32 const sharedClassName = cn(33 'shrink-0 bg-border data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:w-px data-[orientation=vertical]:self-stretch',34 className,35 )3637 // A consumer passing `role="none"` / `"presentation"` is asking for a38 // presentational separator just as `decorative` does — treat them the same.39 // Otherwise Base UI would still emit `aria-orientation` (which it sets from40 // the orientation prop regardless of role), recreating the axe41 // `aria-allowed-attr` violation that `decorative` exists to avoid.42 const isPresentational = decorative || role === 'none' || role === 'presentation'4344 if (isPresentational) {45 // Render a plain <div> for presentational separators. Bypass the46 // primitive so the rendered element carries no ARIA semantics at all47 // (no `aria-orientation`).48 return (49 <div50 ref={ref as React.Ref<HTMLDivElement>}51 data-slot='separator'52 data-orientation={orientation}53 role='none'54 className={sharedClassName}55 {...(props as React.HTMLAttributes<HTMLDivElement>)}56 />57 )58 }5960 return (61 <SeparatorPrimitive62 ref={ref}63 data-slot='separator'64 orientation={orientation}65 role={role ?? 'separator'}66 className={sharedClassName}67 {...props}68 />69 )70}7172export { Separator }73export type { SeparatorProps }
What it pulls in
npm packages
Other registry items
Files it writes
More from @nswds/ui
All 46 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Aspect Ratioaspect-ratio | @nswds/ui | Components | Free | 2 deps · 2 files | |
| Badgebadge | @nswds/ui | Components | Free | 4 deps · 2 files | |
| Buttonbutton | @nswds/ui | Components | Free | 4 deps · 2 files | |
| Cardcard | @nswds/ui | Components | Free | 2 deps · 2 files | |
| Collapsiblecollapsible | @nswds/ui | Components | Free | 1 dep | |
| Drawerdrawer | @nswds/ui | Components | Free | 3 deps · 2 files | |
| Expandable Searchexpandable-search | @nswds/ui | Components | Free | 3 deps · 2 files | |
| Fieldfield | @nswds/ui | Components | Free | 4 deps · 2 files |
