"use client"; import { type ReactElement, type ReactNode, type Ref } from "react"; import { type ListElement, type ListProps } from "../list/List.js"; import { ListSubheader, type ListSubheaderProps, } from "../list/ListSubheader.js"; import { MenuItemGroup } from "../menu/MenuItemGroup.js"; import { type PropsWithRef } from "../types.js"; import { useEnsuredId } from "../useEnsuredId.js"; /** @since 6.0.0 */ export interface OptGroupProps extends Omit { ref?: Ref; /** * This is really the `children` to display in a `ListSubheader` that * describes the optgroup. It was named `label` to match the native * `` element. * * @see {@link labelProps} for additional styling and options. */ label: ReactNode; /** * This can be used to apply any additional props to the `ListSubheader` that * describes the group of options. */ labelProps?: PropsWithRef>; /** * This should be any `Option`s to display within the group. */ children: ReactNode; } /** * **Client Component** * * This component is more of a "convenience component" to help enforce the * correct accessibility when creating an `` with the `Select` * component. * * @example Simple Example * ```tsx * import { Select } from "@react-md/core/form/Select"; * import { OptGroup } from "@react-md/core/form/OptGroup"; * import { Option } from "@react-md/core/form/Option"; * import FavoriteIcon from "@react-md/material-icons/FavoriteIcon"; * import type { ReactElement } from "react"; * * function Example(): ReactElement { * return ( * * * ); * } * ``` * * @see {@link https://react-md.dev/components/select | Select Demos} * @since 6.0.0 */ export function OptGroup(props: OptGroupProps): ReactElement { const { ref, children, label, labelProps, ...remaining } = props; const labelId = useEnsuredId(labelProps?.id, "optgroup"); return ( {label} {children} ); }