UNPKG

@base-ui/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.

48 lines (46 loc) 1.43 kB
'use client'; import * as React from 'react'; import { useSelectRootContext } from "../root/SelectRootContext.js"; import { useSelectItemContext } from "../item/SelectItemContext.js"; import { useRenderElement } from "../../internals/useRenderElement.js"; /** * A text label of the select item. * Renders a `<div>` element. * * Documentation: [Base UI Select](https://base-ui.com/react/components/select) */ export const SelectItemText = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef(function SelectItemText(componentProps, forwardedRef) { const { index, textRef, selectedByFocus, hasRegistered } = useSelectItemContext(); const { firstItemTextRef, selectedItemTextRef } = useSelectRootContext(); const { render, className, style, ...elementProps } = componentProps; const localRef = React.useCallback(node => { if (!node) { return; } if (hasRegistered && index === 0) { firstItemTextRef.current = node; } if (hasRegistered && selectedByFocus) { selectedItemTextRef.current = node; } }, [firstItemTextRef, selectedItemTextRef, index, selectedByFocus, hasRegistered]); const element = useRenderElement('div', componentProps, { ref: [localRef, forwardedRef, textRef], props: elementProps }); return element; })); if (process.env.NODE_ENV !== "production") SelectItemText.displayName = "SelectItemText";