/** * Convention used across Base UI: given a root id, the field's label id is * `${id}-label`. Returns `undefined` when the root id is absent so callers * can feed the result directly into an optional `aria-labelledby`. */ export function getDefaultLabelId( id: string | null | undefined, ): string | undefined { return id == null ? undefined : `${id}-label`; } /** * Prefers the field-provided label id (when the component is inside a * ``) over the locally-registered one. Mirrors React's rule: * if both are present, the field wins because its label wraps the entire * control, while the local label might just be ancillary. */ export function resolveAriaLabelledBy( fieldLabelId: string | undefined, localLabelId: string | undefined, ): string | undefined { return fieldLabelId ?? localLabelId; }