-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add getSlotClassNameProp to allow custom style hooks to preserve the original className while overriding the component default className. #34166
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
Add getSlotClassNameProp to allow custom style hooks to preserve the original className while overriding the component default className. #34166
Conversation
…override the default styles while preserving any user-provided classes.
📊 Bundle size reportUnchanged fixtures
|
Pull request demo site: URL |
packages/react-components/react-utilities/src/compose/overrideSlotClasses.ts
Outdated
Show resolved
Hide resolved
apps/vr-tests-react-components/src/stories/CustomStyleHooks.stories.tsx
Outdated
Show resolved
Hide resolved
packages/react-components/react-utilities/src/compose/overrideSlotClasses.ts
Outdated
Show resolved
Hide resolved
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 think other than the overrideslots stuff it looks good. I like this approach since we keep it very internal aside from the function which we can deprecate later in the future
The biggest issue with the current approach is that there's no good package for the new
-- There is also another solution where we could build in this function "automatically" into |
Before this goes in, we should be sure to update this doc: https://react.fluentui.dev/?path=/docs/concepts-developer-advanced-styling-techniques--docs |
packages/react-components/react-utilities/src/compose/overrideDefaultSlotClasses.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-utilities/src/compose/getSlotClassNameProp.ts
Show resolved
Hide resolved
…ustom-style-hook-user-classname
…ustom-style-hook-user-classname
…original className while overriding the component default className. (microsoft#34166) Save each slot's user-provided class name (the `className` prop) in a metadata field on the slot object. This allows it to be accessed later, even after the default styles are applied. Provide a new function `getSlotClassNameProp_unstable` to access this value. Each custom style hook will need to be updated to append a call to `getSlotClassNameProp_unstable` at the end of each call to `mergeClasses`.
…original className while overriding the component default className. (microsoft#34166) Save each slot's user-provided class name (the `className` prop) in a metadata field on the slot object. This allows it to be accessed later, even after the default styles are applied. Provide a new function `getSlotClassNameProp_unstable` to access this value. Each custom style hook will need to be updated to append a call to `getSlotClassNameProp_unstable` at the end of each call to `mergeClasses`.
Previous Behavior
More details are available in #34144 which describes the issue. In short: custom style hooks currently have no way to override the component's base styles while still respecting styles added via the
className
prop on the component itself.New Behavior
Save each slot's user-provided class name (the
className
prop) in a metadata field on the slot object. This allows it to be accessed later, even after the default styles are applied. Provide a new functiongetSlotClassNameProp_unstable
to access this value.Each custom style hook will need to be updated to append a call to
getSlotClassNameProp_unstable
at the end of each call tomergeClasses
. This refactoring can be done with the following copilot prompt:Related Issue(s)