Skip to content

fix(menu): convert menu icon stories to class-based components for proper theme rendering #5402

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

Merged
merged 17 commits into from
May 12, 2025

Conversation

Rajdeepc
Copy link
Contributor

@Rajdeepc Rajdeepc commented Apr 25, 2025

Description

This PR addresses an issue where icons in menu components weren't rendering correctly when used in functional stories. The solution converts functional story components to class-based components that extend LitElement.

Why this works with a class based approach

The LitElement class creates a proper rendering context. In contrast, functional stories don't create their own component boundaries and can struggle with proper slot assignment and theme inheritance when dealing with complex nesting of web components.

Changes

  1. Converted menuItemWithDescription from a functional component to a class-based component
  2. Converted headersAndIcons from a functional component to a class-based component
  3. Modified WithIcons component structure to properly render icons

Issue

Previously, icons in menu components weren't properly responding to theme changes and occasionally failed to render when used in slotted contexts in functional stories. This was due to lifecycle timing issues and lack of proper shadow DOM encapsulation in functional components.

Root cause TODO

Icon components require proper component lifecycle hooks and shadow DOM contexts to initialize correctly. Functional stories lack the component lifecycle methods (connectedCallback, updated, etc.) needed for proper icon registration and theme context propagation.

Related issue(s)

  • fixes SWC - 725

How has this been tested?

  • Menu with Description

    1. Go here
    2. Switch between system
    3. Check the icons with the menu items are changing based on system
  • Menu with Icons

    1. Go here
    2. Switch between system
    3. Check the icons with the menu items are changing based on system
  • Selects with Icons

    1. Go here
    2. Switch between system
    3. Check the icons with the menu items are changing based on system
  • Did it pass in Desktop?

  • Did it pass in Mobile?

  • Did it pass in iPad?

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (minor updates related to the tooling or maintenance of the repository, does not impact compiled assets)

Checklist

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • If my change required a change to the documentation, I have updated the documentation in this pull request.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have reviewed at the Accessibility Practices for this feature, see: Aria Practices

Best practices

This repository uses conventional commit syntax for each commit message; note that the GitHub UI does not use this by default so be cautious when accepting suggested changes. Avoid the "Update branch" button on the pull request and opt instead for rebasing your branch against main.

@Rajdeepc Rajdeepc self-assigned this Apr 25, 2025
Copy link

changeset-bot bot commented Apr 25, 2025

🦋 Changeset detected

Latest commit: d51fb1a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 84 packages
Name Type
@spectrum-web-components/menu Patch
@spectrum-web-components/breadcrumbs Patch
@spectrum-web-components/combobox Patch
@spectrum-web-components/picker Patch
@spectrum-web-components/custom-vars-viewer Patch
example-project-rollup Patch
example-project-webpack Patch
@spectrum-web-components/story-decorator Patch
@spectrum-web-components/bundle Patch
@spectrum-web-components/action-menu Patch
documentation Patch
@spectrum-web-components/eslint-plugin Patch
@spectrum-web-components/accordion Patch
@spectrum-web-components/action-bar Patch
@spectrum-web-components/action-button Patch
@spectrum-web-components/action-group Patch
@spectrum-web-components/alert-banner Patch
@spectrum-web-components/alert-dialog Patch
@spectrum-web-components/asset Patch
@spectrum-web-components/avatar Patch
@spectrum-web-components/badge Patch
@spectrum-web-components/button-group Patch
@spectrum-web-components/button Patch
@spectrum-web-components/card Patch
@spectrum-web-components/checkbox Patch
@spectrum-web-components/clear-button Patch
@spectrum-web-components/close-button Patch
@spectrum-web-components/coachmark Patch
@spectrum-web-components/color-area Patch
@spectrum-web-components/color-field Patch
@spectrum-web-components/color-handle Patch
@spectrum-web-components/color-loupe Patch
@spectrum-web-components/color-slider Patch
@spectrum-web-components/color-wheel Patch
@spectrum-web-components/contextual-help Patch
@spectrum-web-components/dialog Patch
@spectrum-web-components/divider Patch
@spectrum-web-components/dropzone Patch
@spectrum-web-components/field-group Patch
@spectrum-web-components/field-label Patch
@spectrum-web-components/help-text Patch
@spectrum-web-components/icon Patch
@spectrum-web-components/icons-ui Patch
@spectrum-web-components/icons-workflow Patch
@spectrum-web-components/icons Patch
@spectrum-web-components/iconset Patch
@spectrum-web-components/illustrated-message Patch
@spectrum-web-components/infield-button Patch
@spectrum-web-components/link Patch
@spectrum-web-components/meter Patch
@spectrum-web-components/modal Patch
@spectrum-web-components/number-field Patch
@spectrum-web-components/overlay Patch
@spectrum-web-components/picker-button Patch
@spectrum-web-components/popover Patch
@spectrum-web-components/progress-bar Patch
@spectrum-web-components/progress-circle Patch
@spectrum-web-components/radio Patch
@spectrum-web-components/search Patch
@spectrum-web-components/sidenav Patch
@spectrum-web-components/slider Patch
@spectrum-web-components/split-view Patch
@spectrum-web-components/status-light Patch
@spectrum-web-components/swatch Patch
@spectrum-web-components/switch Patch
@spectrum-web-components/table Patch
@spectrum-web-components/tabs Patch
@spectrum-web-components/tags Patch
@spectrum-web-components/textfield Patch
@spectrum-web-components/thumbnail Patch
@spectrum-web-components/toast Patch
@spectrum-web-components/tooltip Patch
@spectrum-web-components/top-nav Patch
@spectrum-web-components/tray Patch
@spectrum-web-components/underlay Patch
@spectrum-web-components/vrt-compare Patch
@spectrum-web-components/base Patch
@spectrum-web-components/grid Patch
@spectrum-web-components/opacity-checkerboard Patch
@spectrum-web-components/reactive-controllers Patch
@spectrum-web-components/shared Patch
@spectrum-web-components/styles Patch
@spectrum-web-components/theme Patch
@spectrum-web-components/truncated Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rajdeepc Rajdeepc marked this pull request as ready for review April 25, 2025 07:12
@Rajdeepc Rajdeepc requested a review from a team as a code owner April 25, 2025 07:12
Copy link

Branch preview

Review the following VRT differences

When a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs:

If the changes are expected, update the current_golden_images_cache hash in the circleci config to accept the new images. Instructions are included in that file.
If the changes are unexpected, you can investigate the cause of the differences and update the code accordingly.

Copy link

github-actions bot commented Apr 25, 2025

Tachometer results

Chrome

menu permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 539 kB 165.76ms - 170.01ms - faster ✔
1% - 4%
2.34ms - 7.09ms
branch 513 kB 171.54ms - 173.66ms slower ❌
1% - 4%
2.34ms - 7.09ms
-
Firefox

menu permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 539 kB 366.07ms - 376.41ms - faster ✔
1% - 4%
3.91ms - 16.85ms
branch 513 kB 377.74ms - 385.50ms slower ❌
1% - 5%
3.91ms - 16.85ms
-

@Rajdeepc Rajdeepc changed the title chore: added system aware icons story in menu fast follows chore: fast-follows - added system aware icons story in menu Apr 25, 2025
@Rajdeepc Rajdeepc changed the title chore: fast-follows - added system aware icons story in menu chore: system aware icons storybook in menu fast follows Apr 25, 2025
@Rajdeepc
Copy link
Contributor Author

Rajdeepc commented Apr 25, 2025

Note: This change has been made for the design to sign off on our Menu fast follows, but to make it more robust we would need to update our context Switcher(System Resolver) to also cascade the context of system down to slotted content also. Lit's context API doesn't allow this out of the box but we can update SystemResolverController to extend this capability.
We would need a high level API design to add this capability to storybook

@Rajdeepc Rajdeepc marked this pull request as draft April 25, 2025 15:57
@Rajdeepc Rajdeepc changed the title chore: system aware icons storybook in menu fast follows [DO NOT MERGE] chore: system aware icons storybook in menu fast follows Apr 25, 2025
@Rajdeepc Rajdeepc marked this pull request as ready for review May 9, 2025 09:47
@Rajdeepc Rajdeepc changed the title [DO NOT MERGE] chore: system aware icons storybook in menu fast follows chore: system aware icons storybook in menu fast follows May 9, 2025
@Rajdeepc Rajdeepc changed the title chore: system aware icons storybook in menu fast follows chore: added S1-S2 icons switch stories in menu fast follows May 9, 2025
@Rajdeepc Rajdeepc changed the title chore: added S1-S2 icons switch stories in menu fast follows fix(menu): convert menu icon stories to class-based components for proper theme rendering May 9, 2025
Copy link
Contributor

@nikkimk nikkimk left a comment

Choose a reason for hiding this comment

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

Lost gold treasure map (LGTM)

Copy link
Contributor

@blunteshwar blunteshwar left a comment

Choose a reason for hiding this comment

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

Damn!
So insightful

Copy link
Contributor

@TarunAdobe TarunAdobe left a comment

Choose a reason for hiding this comment

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

LGTM!

@Rajdeepc Rajdeepc merged commit 3aeafdd into main May 12, 2025
24 checks passed
@Rajdeepc Rajdeepc deleted the rajdeep/menu-system-aware-icons branch May 12, 2025 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants