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 - Dark Mode.default.chromium.png 1107 Changed
vr-tests-react-components/CalendarCompat.multiDayView - High Contrast.default.chromium.png 1236 Changed
vr-tests-react-components/CalendarCompat.multiDayView - RTL.default.chromium.png 495 Changed
vr-tests-react-components/CalendarCompat.multiDayView.default.chromium_1.png 403 Changed
vr-tests-react-components/Positioning 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Positioning.Positioning end.chromium.png 611 Changed
vr-tests-react-components/Positioning.Positioning end.updated 2 times.chromium.png 193 Changed
vr-tests-react-components/TagPicker 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/TagPicker.disabled - RTL.disabled input hover.chromium.png 635 Changed
vr-tests-react-components/TagPicker.disabled.disabled input hover.chromium.png 677 Changed

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

"type": "minor",
"comment": "feat: add base hooks for Checkbox",
"packageName": "@fluentui/react-checkbox",
"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 { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';
import { ComponentProps, ComponentState, DistributiveOmit, Slot } from '@fluentui/react-utilities';

export type CheckboxSlots = {
/**
Expand Down Expand Up @@ -100,3 +100,7 @@ export interface CheckboxOnChangeData {
*/
export type CheckboxState = ComponentState<CheckboxSlots> &
Required<Pick<CheckboxProps, 'checked' | 'disabled' | 'labelPosition' | 'shape' | 'size'>>;

export type CheckboxBaseProps = DistributiveOmit<CheckboxProps, 'shape' | 'size'>;

export type CheckboxBaseState = DistributiveOmit<CheckboxState, 'shape' | 'size'>;
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
export { Checkbox } from './Checkbox';
export type { CheckboxOnChangeData, CheckboxProps, CheckboxSlots, CheckboxState } from './Checkbox.types';
export type {
CheckboxBaseProps,
CheckboxBaseState,
CheckboxOnChangeData,
CheckboxProps,
CheckboxSlots,
CheckboxState,
} from './Checkbox.types';
export { renderCheckbox_unstable } from './renderCheckbox';
export { useCheckbox_unstable } from './useCheckbox';
export { useCheckbox_unstable, useCheckboxBase_unstable } from './useCheckbox';
export { checkboxClassNames, useCheckboxStyles_unstable } from './useCheckboxStyles.styles';
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
useMergedRefs,
slot,
} from '@fluentui/react-utilities';
import { CheckboxProps, CheckboxState } from './Checkbox.types';
import { CheckboxBaseProps, CheckboxBaseState, CheckboxProps, CheckboxState } from './Checkbox.types';
import {
Checkmark12Filled,
Checkmark16Filled,
Expand All @@ -37,7 +37,48 @@ export const useCheckbox_unstable = (props: CheckboxProps, ref: React.Ref<HTMLIn
// Merge props from surrounding <Field>, if any
props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });

const { disabled = false, required, shape = 'square', size = 'medium', labelPosition = 'after', onChange } = props;
const { shape = 'square', size = 'medium', ...checkboxProps } = props;

const state = useCheckboxBase_unstable(checkboxProps, ref);

// Override indicator children with size+shape-appropriate icon
const mixed = state.checked === 'mixed';
let checkmarkIcon;
if (mixed) {
if (shape === 'circular') {
checkmarkIcon = <CircleFilled />;
} else {
checkmarkIcon = size === 'large' ? <Square16Filled /> : <Square12Filled />;
}
} else if (state.checked) {
checkmarkIcon = size === 'large' ? <Checkmark16Filled /> : <Checkmark12Filled />;
}

if (state.indicator) {
state.indicator.children = checkmarkIcon;
}

return {
...state,
shape,
size,
};
};

/**
* Base hook for Checkbox component, which manages state related to checked state, ARIA attributes,
* focus management, and slot structure without design props.
*
* @param props - props from this instance of Checkbox
* @param ref - reference to `<input>` element of Checkbox
*/
export const useCheckboxBase_unstable = (
props: CheckboxBaseProps,
ref: React.Ref<HTMLInputElement>,
): CheckboxBaseState => {
'use no memo';

const { disabled = false, required, labelPosition = 'after', onChange } = props;

const [checked, setChecked] = useControllableState({
defaultState: props.defaultChecked,
Expand All @@ -48,28 +89,23 @@ export const useCheckbox_unstable = (props: CheckboxProps, ref: React.Ref<HTMLIn
const nativeProps = getPartitionedNativeProps({
props,
primarySlotTagName: 'input',
excludedPropNames: ['checked', 'defaultChecked', 'size', 'onChange'],
excludedPropNames: ['checked', 'defaultChecked', 'onChange'],
});

const mixed = checked === 'mixed';
const id = useId('checkbox-', nativeProps.primary.id);

// Use medium size as default for icon selection in base hook
let checkmarkIcon;
if (mixed) {
if (shape === 'circular') {
checkmarkIcon = <CircleFilled />;
} else {
checkmarkIcon = size === 'large' ? <Square16Filled /> : <Square12Filled />;
}
checkmarkIcon = <Square12Filled />;
} else if (checked) {
checkmarkIcon = size === 'large' ? <Checkmark16Filled /> : <Checkmark12Filled />;
checkmarkIcon = <Checkmark12Filled />;
}

const state: CheckboxState = {
shape,
const state: CheckboxBaseState = {
checked,
disabled,
size,
labelPosition,
components: {
root: 'span',
Expand Down Expand Up @@ -99,7 +135,7 @@ export const useCheckbox_unstable = (props: CheckboxProps, ref: React.Ref<HTMLIn
htmlFor: id,
disabled,
required,
size: 'medium', // Even if the checkbox itself is large
size: 'medium',
},
elementType: Label,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ export {
useCheckbox_unstable,
} from './Checkbox';
export type { CheckboxOnChangeData, CheckboxProps, CheckboxSlots, CheckboxState } from './Checkbox';

// Experimental APIs - will be uncommented in the experimental release branch
// export { useCheckboxBase_unstable } from './Checkbox';
// export type { CheckboxBaseProps, CheckboxBaseState } from './Checkbox';
Loading