-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
UnitControl
: show unit label when units
prop has only one unit
#40784
Conversation
5b4697a
to
08b3d29
Compare
@@ -109,40 +109,10 @@ TweakingTheNumberInput.args = { | |||
/** | |||
* When only one unit is available, the unit selection dropdown becomes static text. | |||
*/ | |||
export const WithSingleUnitControlled: ComponentStory< |
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.
Just undoing some Storybook changes that were left from previous work on #40697
render( | ||
<UnitControl | ||
units={ [ { value: '%', label: '%' } ] } | ||
value="30%" |
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.
Removing value
prop from test, which was added as a temporary fix in #40697 (see #40697 (comment) for context)
77cbc41
to
c86a634
Compare
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.
Thanks for cleaning this up @ciampo 👍
✅ Tests pass
✅ All Storybook examples for UnitControl
function as expected
✅ Works as expected in editor and theme setting only single unit
I did have one minor question/tweak that I've left as an inline comment. Happy to review again and give final approval once that's resolved.
Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
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.
LGTM 🚢
✅ Tests still pass
✅ UnitControl behaves as advertised within Storybook examples
✅ Still working in the editor with varying custom unit configurations
I'd say this should be right to land once all the checks are green. 👍
What?
Fix an issue in
UnitControl
, where the unit label was not being shown if theunits
array prop only had one item.Why?
This is a bug and should be fixed. See #40697 (comment) and #40697 (comment) for more context.
How?
The fix is to use the label of the single unit passed through the
units
prop as the initial unit value (as suggested in this comment by @stokesman ).This PR also restores the
should render label if single units
unit test to how it used to be before the changes applied in #40697.Testing Instructions
Make sure tests pass
Visit the "Single Unit Controlled" Storybook example on
trunk
, verify that there's no unit being displayed when the Story initially renders. Check that the unit is only shown after a numeric value is entered in the input field.Apply this patch below to restore the same Storybook example on this branch, visit the same "Single Unit Controlled" Storybook example, and verify that the initial unit is being displayed during the Story initial render.
Click to show the patch
Screenshots or screencast
Before
unit-control-single-label-before.mp4
After
unit-control-single-label-after.mp4