Viewport: Highlight toolbar button when custom viewport is active#35075
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughViewportTool's viewport option rendering was refactored to correctly display the active state when a custom viewport is selected. The options computation now conditionally appends a synthetic option matching the current custom viewport, enabling the Select component to render an active toolbar button. ChangesCustom Viewport Selection
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The PR description has been updated:
Labels cannot be added without admin access. Could a maintainer please add the appropriate labels (bug, ci:normal)? |
Sidnioulz
left a comment
There was a problem hiding this comment.
Thanks for handling this @derinbarutcu17!
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 189 | 188 | 🎉 -1 🎉 |
| Self size | 15 KB | 15 KB | 🚨 +18 B 🚨 |
| Dependency size | 30.77 MB | 30.67 MB | 🎉 -101 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
Summary
Closes #35067
When a custom viewport is active (user has manually entered width/height rather than selecting a preset), the viewport toolbar button does not highlight/activate, even though a non-default viewport is in use.
Root Cause
The
Selectcomponent usesdefaultOptionsto find a matching entry in itsoptionsarray. If a match is found,selectedOptions.length > 0andStyledButtonrenders with$hasSelection={true}(the highlighted active state).When a custom viewport is set,
valueis a URL-pattern string (e.g.440-355) that is never present as a key inviewportMap. SosetSelectedFromDefaultreturns[]→$hasSelection={false}→ the button appears inactive.Fix
In
ViewportTool, whenisCustom && valueis true, append a synthetic option entry that uses the currentvalueas its key. This givesdefaultOptions={value}a match in the options list, makingselectedOptionsnon-empty and$hasSelectioncorrect.The synthetic option is hidden from the visible dropdown list. Its sole purpose is to correctly reflect the active state in the toolbar button.
Before / After
Before: Toolbar viewport button stays unhighlighted when a custom viewport size is set.
After: Toolbar viewport button highlights correctly when any non-default viewport is active — whether a preset or a custom size.
Manual testing
storyview mode.Summary by CodeRabbit