Skip to content

@backstage/ui: Migrate all components from useStyles to useDefinition - #33050

Merged
Naycon merged 51 commits into
masterfrom
bui-migrate-to-use-definition
Feb 27, 2026
Merged

Naycon merged 51 commits into
masterfrom
bui-migrate-to-use-definition

Conversation

@Naycon

@Naycon Naycon commented Feb 27, 2026 •

Copy link
Copy Markdown
Collaborator

Hey, I just made a Pull Request!

Migrates all 58 components in packages/ui from the legacy useStyles hook
(backed by ComponentDefinition) to the useDefinition hook (backed by
defineComponent()). This unifies every component on the richer prop-resolution
pattern that provides automatic CSS module class merging, declarative defaults,
clean prop separation (ownProps/restProps), and background system integration.

After migration, the now-unused useStyles hook and legacy types
(ComponentDefinition, ClassNamesMap, DataAttributesMap,
DataAttributeValues) are deleted.

Breaking changes

  • Removed deprecated types ComponentDefinition, ClassNamesMap,
    DataAttributeValues, and DataAttributesMap from the public API.
  • Data attributes rendered by components are now always lowercase
    (data-startCollapsed → data-startcollapsed).

Bug fixes uncovered during migration

  • Fixed Link variant default from 'body' to 'body-medium' to match
    actual CSS selectors.
  • Fixed isRequired not being forwarded to React Aria field components
    in TextField, SearchField, and PasswordField.

✔️ Checklist

  • A changeset describing the change and affected packages.
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message.

Replace ComponentDefinition with defineComponent pattern, move CSS
module import and prop defaults into the definition, and switch the
component to useDefinition hook.

Signed-off-by: Johan Persson <[email protected]>
Make AvatarOwnProps the source of truth with inline type definitions,
and have AvatarProps extend it. This follows the established pattern
used by Button, Checkbox, and Alert components. Export AvatarOwnProps
from the package entry point.

Signed-off-by: Johan Persson <[email protected]>
Fix pre-existing variant default from 'body' to 'body-medium' to match
actual CSS selectors. Add missing 'info' color to docs-ui props definition.

Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
…xtension, useDefinition first

- Add label to PasswordFieldOwnProps and propDefs
- Remove Omit<FieldLabelProps, ...> from PasswordFieldProps
- Move useDefinition call to top of component
- Access aria-label/aria-labelledby from restProps instead of props

Signed-off-by: Johan Persson <[email protected]>
isRequired was consumed locally for the secondary label but never
forwarded to the underlying AriaTextField/AriaSearchField, resulting
in missing aria-required attribute and no built-in validation.

Signed-off-by: Johan Persson <[email protected]>
Split shared TagGroupDefinition into TagGroupDefinition (root) and
TagDefinition (tag sub-component). Tag's size prop now uses dataAttribute
with default in propDefs instead of manual data-size and default spreading.

Signed-off-by: Johan Persson <[email protected]>
Split monolithic MenuDefinition (17 classNames) into 9 per-sub-component
definitions (Menu, MenuListBox, MenuAutocomplete, MenuAutocompleteListbox,
MenuItem, MenuListBoxItem, MenuSection, MenuSeparator, MenuEmptyState).
MenuItem color prop uses dataAttribute with default in propDefs. Defaults
for placement, virtualized, selectionMode moved to propDefs.

Signed-off-by: Johan Persson <[email protected]>
Address review feedback: extract MenuPopoverOwnProps shared type for
common props (placement, virtualized, maxWidth, maxHeight, style,
className). Extract menuPopoverClassNames and menuPopoverPropDefs in
definition.ts to ensure shared values stay in sync across Menu variants.

Signed-off-by: Johan Persson <[email protected]>
Children was in propDefs (extracted to ownProps by useDefinition) but
the component only spread restProps on a self-closing div, silently
dropping children. Now explicitly renders children from ownProps.

Signed-off-by: Johan Persson <[email protected]>
Children was incorrectly added to OwnProps/propDefs during migration,
causing useDefinition to extract it from restProps. Since neither
component consumes children directly, children should flow through
restProps to the underlying div element.

Signed-off-by: Johan Persson <[email protected]>
All components have been migrated to useDefinition. Remove the now-unused
useStyles hook and its associated types (ComponentDefinition, ClassNamesMap,
DataAttributeValues, DataAttributesMap) from the public API.

Signed-off-by: Johan Persson <[email protected]>
Signed-off-by: Johan Persson <[email protected]>
@backstage-goalie

Copy link
Copy Markdown
Contributor

Important

This PR includes changes that affect public-facing API. Please ensure you are adding/updating documentation for new features or behavior.

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage/ui packages/ui minor v0.12.1-next.0

@backstage-goalie backstage-goalie Bot added size:huge Huge pull requests receive a lower priority for reviews. waiting-for:review The PR needs a review and will be visible in the review queue unless already assigned an owner. labels Feb 27, 2026
@github-actions

github-actions Bot commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

🎨 Visual Testing with Chromatic

Signed-off-by: Johan Persson <[email protected]>
orientation was listed in propDefs with dataAttribute: true, which
caused useDefinition to extract it from restProps. React Aria's
ToggleButtonGroup never received it and defaulted to horizontal.

Remove orientation from propDefs and OwnProps so it flows through
restProps to React Aria, which handles data-orientation itself.

Signed-off-by: Johan Persson <[email protected]>
@Naycon Naycon changed the title Bui migrate to use definition @backstage/ui: Migrate all components from useStyles to useDefinition Feb 27, 2026
@Naycon
Naycon marked this pull request as ready for review February 27, 2026 15:03
@Naycon
Naycon requested a review from a team as a code owner February 27, 2026 15:03
Copilot AI review requested due to automatic review settings February 27, 2026 15:03
@Naycon
Naycon requested a review from a team as a code owner February 27, 2026 15:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request performs a comprehensive migration of all 58 UI components from the legacy useStyles hook to the modern useDefinition hook backed by defineComponent(). The migration unifies component prop resolution, enables automatic CSS module class merging, and provides cleaner prop separation through ownProps and restProps.

Changes:

  • Migrated all 58 components from useStyles to useDefinition hook
  • Removed deprecated types (ComponentDefinition, ClassNamesMap, DataAttributesMap, DataAttributeValues) and deleted the useStyles hook
  • Fixed two bugs: Link variant default ('body' → 'body-medium') and isRequired prop forwarding in TextField/SearchField/PasswordField

Reviewed changes

Copilot reviewed 135 out of 135 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/ui/src/types.ts Removed deprecated public types for component definitions
packages/ui/src/hooks/useStyles.ts Deleted legacy styling hook
packages/ui/src/components/*/types.ts Added OwnProps types for all components
packages/ui/src/components/*/definition.ts Migrated from object literals to defineComponent()
packages/ui/src/components/*/Component.tsx Updated to use useDefinition with ownProps/restProps pattern
packages/ui/src/components/SearchField/SearchField.module.css Updated data attribute selector to lowercase
.changeset/*.md Added changesets documenting breaking changes and bug fixes
packages/ui/report.api.md Updated API surface to reflect type changes

@cdedreuille cdedreuille left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks a lot @Naycon 🙏 It would be hard to review every component but from the look of it the migration seems to have worked pretty well. I can see there was some visual regressions on the Link component though. I could not really tell what was wrong in the diff but and code change but just wanted to make sure we're good here.


```diff
- [data-startCollapsed='true'] { ... }
+ [data-startcollapsed='true'] { ... }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to do data-start-collapsed ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It could, but I thought this was more in line with what html does in general (e.g. aria-describedby or tabindex, so therefore I went this route.

@Naycon

Naycon commented Feb 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

@cdedreuille there's no visual regression on Link, there's a visual progression. 😁 This is why (from the PR description):

Bug fixes uncovered during migration

  • Fixed Link variant default from 'body' to 'body-medium' to match
    actual CSS selectors.

There's no body variant for Link, so they all rendered with the default font size, which looks like it was slightly smaller or larger.

@cdedreuille

Copy link
Copy Markdown
Collaborator

Ah perfect. Sorry for the confusion. I'm glad you fought this bug 🤗

@backstage-goalie backstage-goalie Bot added waiting-for:merge The PR has been approved and is awaiting merge. and removed waiting-for:review The PR needs a review and will be visible in the review queue unless already assigned an owner. labels Feb 27, 2026
@Naycon
Naycon merged commit 1b3dea2 into master Feb 27, 2026
34 checks passed
@Naycon
Naycon deleted the bui-migrate-to-use-definition branch February 27, 2026 16:18
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for contributing to Backstage! The changes in this pull request will be part of the 1.49.0 release, scheduled for Tue, 17 Mar 2026.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:huge Huge pull requests receive a lower priority for reviews. waiting-for:merge The PR has been approved and is awaiting merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants