-
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
ToggleControl: Convert to TypeScript #43717
Conversation
const classes = cx( | ||
'components-toggle-control', | ||
className, | ||
! __nextHasNoMarginBottom && css( { marginBottom: space( 3 ) } ) |
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.
For back compat, we set a custom value (12px) here instead of simply passing through the __nextHasNoMarginBottom
to BaseControl. This is because ToggleControl was setting a custom margin-bottom value (12px) that was different from BaseControl's margin-bottom (8px).
Size Change: -87 B (0%) Total Size: 1.24 MB
ℹ️ View Unchanged
|
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.
素晴らしい 🚀
We can merge once test failures are addressed
(also, pinging @jasmussen as promised in #39209 (comment))
import ToggleControl from '../'; | ||
|
||
describe( 'ToggleControl', () => { | ||
it( 'triggers change callback with numeric value', () => { |
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.
Curious test name, I don't understand the "numeric value" part
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.
Yeah, likely copypasta 🍝
render( <ToggleControl label="My toggle" onChange={ () => {} } /> ); | ||
expect( | ||
screen.getByRole( 'checkbox' ) | ||
).not.toHaveAccessibleDescription(); |
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.
Neat assertion!
cb823cf
to
acd3541
Compare
.components-base-control { | ||
.components-base-control__field { | ||
align-items: center; | ||
display: flex; | ||
margin-bottom: 0; | ||
|
||
& > label { | ||
flex-grow: 1; | ||
padding: 0.6rem 0 0.6rem 10px; | ||
} | ||
} | ||
& + & { | ||
margin-top: $grid-unit-20; | ||
} | ||
|
||
.components-base-control__help { | ||
margin: -$grid-unit-10 0 $grid-unit-10 58px; | ||
font-size: $helptext-font-size; | ||
font-style: normal; | ||
color: $gray-700; |
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.
Chipping at it a little bit at a time ⏳
@@ -74,7 +74,6 @@ | |||
"src/search-control", | |||
"src/snackbar", | |||
"src/tab-panel", | |||
"src/toggle-control", |
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.
🎉
Storybook looks good to me. That is — I don't see anything wrong with the toggle control. |
In my review I missed the case where the toggle has help text. This is how the toggle use to look with the spacing between toggle and help text: This is how it looks now: The space may have been a teensy bit too big in the previous case — it should be 8px — but it's gone at the moment. Sorry for not catching this! |
No worries, that style breakage is due to overrides in the Inspector, not the component itself. It should be fine in Storybook. I'll see what I can do about the override breakage. |
Part of #35744 #38730
What?
__nextHasNoMarginBottom
prop for removing margins.Why?
Better devex.
Testing Instructions
npm run storybook:dev
and check the stories for ToggleControl.Note that the space between the toggle and the
help
text is narrower than on trunk. This is intentional, to address #39209 (comment).