// Copyright (c) Meta Platforms, Inc. and affiliates. 'use client'; /** * @file DropdownMenuRadioGroup.tsx * @output DropdownMenuRadioGroup — a single-select group of menu items. * @position Sub-component; wraps DropdownMenuRadioItem inside a DropdownMenu. * * Owns single-selection state (value/onChange) for its child * DropdownMenuRadioItems and exposes it via context. Renders role="group" with * an accessible name so the radios are announced as a set. Keyboard navigation * comes from the parent DropdownMenu's useListFocus, which matches * menuitemradio rows. */ import { useMemo, type ReactNode } from 'react'; import * as stylex from "../style-runtime.js"; import "../theme/tokens.stylex.js"; import { spacingVars } from "../theme/tokens.stylex.js"; import { mergeProps } from "../utils/index.js"; import type { BaseProps } from "../BaseProps.js"; import { DropdownMenuRadioGroupContext, type DropdownMenuRadioGroupContextValue } from "./DropdownMenuContext.js"; const styles = { group: { k1xSpc: "x78zum5", kXwgrk: "xdt5ytf", kOIVth: "x1lsbc85", $$css: true as const } }; export interface DropdownMenuRadioGroupProps extends Omit { /** * The currently selected value in the group. Pass `undefined` when nothing * is selected yet. */ value: string | undefined; /** * Callback fired when the selected value changes. */ onChange: (value: string) => void; /** * Accessible name for the group, announced by screen readers so the radios * read as a named set (e.g. "Sort by"). Applied as the group's `aria-label`. * Required -- an unnamed radio group is an accessibility defect. Pass * `aria-labelledby` (via base props) instead if the name already exists as a * visible element on the page. */ label: string; /** * Whether selecting a value closes the menu. Radio items default to closing * on selection (a single-choice commit), unlike checkbox items which stay * open. * @default true */ hasCloseOnSelect?: boolean; /** * The `DropdownMenuRadioItem`s that make up the group. */ children: ReactNode; } /** * A single-select group of radio menu items (role="group" of menuitemradio). * * @example * ``` * import { * DropdownMenuRadioGroup, * DropdownMenuRadioItem, * } from '@astryxdesign/core/DropdownMenu'; * * * * * * * ``` */ export function DropdownMenuRadioGroup({ value, onChange, label, hasCloseOnSelect = true, children, xstyle, className, style, ...rest }: DropdownMenuRadioGroupProps) { const contextValue = useMemo(() => ({ value, onChange, hasCloseOnSelect }), [value, onChange, hasCloseOnSelect]); return
{children}
; } DropdownMenuRadioGroup.displayName = 'DropdownMenuRadioGroup';