-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(react-checkbox): add motion to Checkbox #35380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat(react-checkbox): add motion to Checkbox #35380
Conversation
|
Pull request demo site: URL |
change/@fluentui-react-checkbox-efe8019d-5ed0-4eec-ae6d-674f97612c48.json
Show resolved
Hide resolved
📊 Bundle size reportUnchanged fixtures
|
packages/react-components/react-checkbox/library/etc/react-checkbox.api.md
Show resolved
Hide resolved
| }, | ||
| }, | ||
|
|
||
| unchecked: {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need empty style rule?
| // Validate visual state by checking computed opacity (0 -> unchecked, 1 -> checked) | ||
| cy.get(`[data-test="list-item-${index + 1}"] .fui-Checkbox__indicator > svg`).should($svg => { | ||
| // Read computed opacity and coerce to number for robust comparison | ||
| const opacity = Number(window.getComputedStyle($svg[0]).opacity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should probably be aria-hidden or some other data-* attribute, we shouldn't rely on computed styles in tests
| }, | ||
| elementType: 'div', | ||
| }), | ||
| checkmarkIcon: slot.optional(props.checkmarkIcon, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I maybe missing something, but what's the main idea behind having this as a separate slot?
|
For some reason checkmark icon doesn't render on PR docsite preview https://fluentuipr.z22.web.core.windows.net/pull/35380/public-docsite-v9/react/index.html?path=/docs/components-checkbox--docs#default Screen.Recording.2025-10-24.at.15.30.55.mov |
| ); | ||
| // Checkbox now keeps the checkmark SVG in the DOM for motion/animation. | ||
| // Validate visual state by checking computed opacity (0 -> unchecked, 1 -> checked) | ||
| cy.get(`[data-test="list-item-${index + 1}"] .fui-Checkbox__indicator > svg`).should($svg => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you import and interpolate css checkbox className here instead of hardcoded string?
| checked === 'mixed' ? rootStyles.mixed : checked ? rootStyles.checked : rootStyles.unchecked, | ||
| checked === 'mixed' ? motionScaleStyles.mixed : checked ? motionScaleStyles.checked : motionScaleStyles.unchecked, | ||
| !disabled && | ||
| (checked === 'mixed' | ||
| ? motionColorStyles.mixed | ||
| : checked | ||
| ? motionColorStyles.checked | ||
| : motionColorStyles.unchecked), | ||
| disabled && rootStyles.disabled, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would avoid nested ternaries, looks shorter, but harder to read (https://eslint.org/docs/latest/rules/no-nested-ternary)
consider to abstract this to a function, something like that (just an example):
type checkState = 'checked' | 'unchecked' | 'mixed';
const checkMap: Record<boolean | 'mixed', checkState> = {
true: 'checked',
false: 'unchecked',
mixed: 'mixed',
};
const collectCheckStateClasses = (
checked: boolean | 'mixed',
disabled: boolean,
rootStyles: ReturnType<typeof useRootStyles>,
motionScaleStyles: ReturnType<typeof useMotionScaleStyles>,
motionColorStyles: ReturnType<typeof useMotionColorStyles>,
) => {
const state = checkMap[checked];
return [
rootStyles[state],
motionScaleStyles[state],
!disabled && motionColorStyles[state],
].filter(Boolean);
};| 'use client'; | ||
|
|
||
| import { makeResetStyles, makeStyles, mergeClasses } from '@griffel/react'; | ||
| import { GriffelStyle, makeResetStyles, makeStyles, mergeClasses } from '@griffel/react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import { GriffelStyle, makeResetStyles, makeStyles, mergeClasses } from '@griffel/react'; | |
| import { type GriffelStyle, makeResetStyles, makeStyles, mergeClasses } from '@griffel/react'; |

Previous Behavior
Checkboxes didn't have any transition between states.
New Behavior
Checkboxes now have transition between all states, according to the specs
Related Issue(s)