UNPKG

@base-ui-components/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

45 lines (43 loc) 1.34 kB
'use client'; import * as React from 'react'; import { useRenderElement } from "../../utils/useRenderElement.js"; import { ComboboxGroupContext } from "./ComboboxGroupContext.js"; import { GroupCollectionProvider } from "../collection/GroupCollectionContext.js"; /** * Groups related items with the corresponding label. * Renders a `<div>` element. */ import { jsx as _jsx } from "react/jsx-runtime"; export const ComboboxGroup = /*#__PURE__*/React.forwardRef(function ComboboxGroup(componentProps, forwardedRef) { const { render, className, items, ...elementProps } = componentProps; const [labelId, setLabelId] = React.useState(); const contextValue = React.useMemo(() => ({ labelId, setLabelId, items }), [labelId, setLabelId, items]); const element = useRenderElement('div', componentProps, { ref: forwardedRef, props: [{ role: 'group', 'aria-labelledby': labelId }, elementProps] }); const wrappedElement = /*#__PURE__*/_jsx(ComboboxGroupContext.Provider, { value: contextValue, children: element }); if (items) { return /*#__PURE__*/_jsx(GroupCollectionProvider, { items: items, children: wrappedElement }); } return wrappedElement; }); if (process.env.NODE_ENV !== "production") ComboboxGroup.displayName = "ComboboxGroup";