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.

44 lines (43 loc) 1.32 kB
'use client'; import * as React from 'react'; import { useIsoLayoutEffect } from '@base-ui-components/utils/useIsoLayoutEffect'; import { useBaseUiId } from "../../utils/useBaseUiId.js"; import { useRenderElement } from "../../utils/useRenderElement.js"; import { useFieldsetRootContext } from "../root/FieldsetRootContext.js"; /** * An accessible label that is automatically associated with the fieldset. * Renders a `<div>` element. * * Documentation: [Base UI Fieldset](https://base-ui.com/react/components/fieldset) */ export const FieldsetLegend = /*#__PURE__*/React.forwardRef(function FieldsetLegend(componentProps, forwardedRef) { const { render, className, id: idProp, ...elementProps } = componentProps; const { disabled, setLegendId } = useFieldsetRootContext(); const id = useBaseUiId(idProp); useIsoLayoutEffect(() => { setLegendId(id); return () => { setLegendId(undefined); }; }, [setLegendId, id]); const state = React.useMemo(() => ({ disabled: disabled ?? false }), [disabled]); const element = useRenderElement('div', componentProps, { state, ref: forwardedRef, props: [{ id }, elementProps] }); return element; }); if (process.env.NODE_ENV !== "production") FieldsetLegend.displayName = "FieldsetLegend";