Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
Copy link

@github-actions github-actions bot Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵🏾‍♀️ visual changes to review in the Visual Change Report

vr-tests-react-components/CalendarCompat 4 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/CalendarCompat.multiDayView - High Contrast.default.chromium.png 1236 Changed
vr-tests-react-components/CalendarCompat.multiDayView - Dark Mode.default.chromium.png 1107 Changed
vr-tests-react-components/CalendarCompat.multiDayView.default.chromium.png 495 Changed
vr-tests-react-components/CalendarCompat.multiDayView.default.chromium_1.png 403 Changed
vr-tests-react-components/Charts-DonutChart 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Charts-DonutChart.Dynamic.default.chromium.png 5581 Changed
vr-tests-react-components/Charts-DonutChart.Dynamic - RTL.default.chromium.png 5570 Changed
vr-tests-react-components/Positioning 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Positioning.Positioning end.chromium.png 609 Changed
vr-tests-react-components/Positioning.Positioning end.updated 2 times.chromium.png 507 Changed
vr-tests-react-components/Skeleton converged 1 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Skeleton converged.Opaque Skeleton with circle - High Contrast.default.chromium.png 1 Changed
vr-tests-react-components/TagPicker 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/TagPicker.disabled - Dark Mode.disabled input hover.chromium.png 658 Changed
vr-tests-react-components/TagPicker.disabled - RTL.disabled input hover.chromium.png 635 Changed

There were 3 duplicate changes discarded. Check the build logs for more information.

"type": "minor",
"comment": "feat: add base hooks for Field",
"packageName": "@fluentui/react-field",
"email": "dmytrokirpa@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { Label } from '@fluentui/react-label';
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';
import type { ComponentProps, ComponentState, DistributiveOmit, Slot } from '@fluentui/react-utilities';

/**
* The props added to the control inside the Field.
Expand Down Expand Up @@ -111,6 +111,10 @@ export type FieldState = ComponentState<Required<FieldSlots>> &
generatedControlId: string;
};

export type FieldBaseProps = DistributiveOmit<FieldProps, 'orientation' | 'size'>;

export type FieldBaseState = DistributiveOmit<FieldState, 'orientation' | 'size'>;

export type FieldContextValue = Readonly<
Pick<FieldState, 'generatedControlId' | 'orientation' | 'required' | 'size' | 'validationState'> & {
/** The label's for prop. Undefined if there is no label. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export type {
FieldBaseProps,
FieldBaseState,
FieldContextValue,
FieldContextValues,
FieldControlProps,
Expand All @@ -8,5 +10,5 @@ export type {
} from './Field.types';
export { Field } from './Field';
export { renderField_unstable } from './renderField';
export { useField_unstable } from './useField';
export { useField_unstable, useFieldBase_unstable } from './useField';
export { fieldClassNames, useFieldStyles_unstable } from './useFieldStyles.styles';
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use client';

import * as React from 'react';

import { CheckmarkCircle12Filled, ErrorCircle12Filled, Warning12Filled } from '@fluentui/react-icons';
import { Label } from '@fluentui/react-label';
import { getIntrinsicElementProps, useId, slot } from '@fluentui/react-utilities';
import type { FieldProps, FieldState } from './Field.types';
import type { FieldBaseProps, FieldBaseState, FieldProps, FieldState } from './Field.types';

const validationMessageIcons = {
error: <ErrorCircle12Filled />,
Expand All @@ -22,13 +24,29 @@ const validationMessageIcons = {
* @param ref - Ref to the root
*/
export const useField_unstable = (props: FieldProps, ref: React.Ref<HTMLDivElement>): FieldState => {
const {
children,
orientation = 'vertical',
required = false,
validationState = props.validationMessage ? 'error' : 'none',
size = 'medium',
} = props;
const { orientation = 'vertical', size = 'medium', ...fieldProps } = props;
const state = useFieldBase_unstable(fieldProps, ref);

// Merge the size design prop into the label slot (which already has htmlFor, id, required)
const label = state.label ? { ...state.label, size } : state.label;

return {
...state,
label,
orientation,
size,
};
};

/**
* Base hook for Field component, which manages state related to validation, ARIA attributes,
* ID generation, and slot structure without design props.
*
* @param props - Props passed to this field
* @param ref - Ref to the root
*/
export const useFieldBase_unstable = (props: FieldBaseProps, ref: React.Ref<HTMLDivElement>): FieldBaseState => {
const { children, required = false, validationState = props.validationMessage ? 'error' : 'none' } = props;

const baseId = useId('field-');
const generatedControlId = baseId + '__control';
Expand All @@ -37,7 +55,7 @@ export const useField_unstable = (props: FieldProps, ref: React.Ref<HTMLDivEleme
elementType: 'div',
});
const label = slot.optional(props.label, {
defaultProps: { htmlFor: generatedControlId, id: baseId + '__label', required, size },
defaultProps: { htmlFor: generatedControlId, id: baseId + '__label', required },
elementType: Label,
});
const validationMessage = slot.optional(props.validationMessage, {
Expand All @@ -58,9 +76,7 @@ export const useField_unstable = (props: FieldProps, ref: React.Ref<HTMLDivEleme
return {
children,
generatedControlId,
orientation,
required,
size,
validationState,
components: { root: 'div', label: Label, validationMessage: 'div', validationMessageIcon: 'span', hint: 'div' },
root,
Expand Down
4 changes: 4 additions & 0 deletions packages/react-components/react-field/library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ export {
useFieldControlProps_unstable,
} from './contexts/index';
export type { FieldControlPropsOptions } from './contexts/index';

// Experimental APIs - will be uncommented in the experimental release branch
// export { useFieldBase_unstable } from './Field';
// export type { FieldBaseProps, FieldBaseState } from './Field';