-
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
ToolsPanel: Standardize input control label margin #36387
ToolsPanel: Standardize input control label margin #36387
Conversation
@@ -107,6 +108,15 @@ export const ToolsPanelItem = css` | |||
margin-bottom: 0; | |||
} | |||
} | |||
|
|||
/* Standardize InputControl labels with others inside ToolsPanel. */ | |||
&& ${ LabelWrapper } { |
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.
I ended up using LabelWrapper
from the input control styles here as I couldn't get BaseLabel
to work for me. Open to suggestions to improve this.
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.
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.
I inspected the control components and the corresponding labels:
- The "Appearance" control is based on the
CustomSelectControl
component, which internally uses a "vanilla"<label>
- The "Letter spacing" control is based on the
UnitControl
component, which builds on top of theInputControl
component (including its label)
Instead of solving this problem specifically to ToolsPanel
, I think that a better approach here would be to align the label inCustomSelectControl
to have the same styling (including line height, margins and paddings) to the one of InputControl
.
Not sure if it's the best solution here, but maybe CustomSelectControl
could use the BaseLabel
directly from InputControl
? (Or, in general, have CustomSelectControl
be based off InputControl
as much as possible) ?
Also a side note — should we update this Storybook example to allow single-columns controls? It would be another good way to test for the changes in this PR in an isolated environment
I think there is another type of control missed here, the Just within the Typography panel alone we have
I'd be inclined to believe the
The I wanted to avoid making any breaking changes (even if only styling) outside of the
My understanding was that Storybook example was a playground for developing the new controls for the Typography panel. I'm not sure it makes sense to try and use it to text/develop the current controls at the same time. A small problem with relying on the Storybook and an isolated environment is we still have to make it line up neatly outside that sterile environment and in the real editors. |
Thank you for the sleuthing and the detailed explanation!
Refactoring these components to use the same base control/label sounds definitely like the sensible thing to do
This is definitely a sensible point — I'd be ok with this PR focusing on a "hotfix" specific for But at the same time it'd be great if we could follow up and look into the discrepancies across "control" components, come up with a good understanding/dependency graph, and work towards a normalization (in the direction that you suggested above) soon.
I agree that relying on Storybook alone is not a good idea, since it is a "sterile" environment, and that ultimately things need to look good in the real editors. At the same time, I also believe that it's important to use Storybook as the first "test stage" for our components. As an example, I tried to to update Storybook so that the Line Height and Letter Spacing controls are next to each other, and noticed a misalignment Code used to update Storybookdiff --git a/packages/components/src/tools-panel/stories/typography-panel.js b/packages/components/src/tools-panel/stories/typography-panel.js
index c57ac4c19e..afd8646788 100644
--- a/packages/components/src/tools-panel/stories/typography-panel.js
+++ b/packages/components/src/tools-panel/stories/typography-panel.js
@@ -1,3 +1,8 @@
+/**
+ * External dependencies
+ */
+import { css } from '@emotion/react';
+
/**
* WordPress dependencies
*/
@@ -12,6 +17,7 @@ import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
+import { useCx } from '../../utils/hooks/use-cx';
import FontSizePicker from '../../font-size-picker';
import Panel from '../../panel';
import {
@@ -97,6 +103,10 @@ export const TypographyPanel = () => {
const [ letterSpacing, setLetterSpacing ] = useState();
const [ textTransform, setTextTransform ] = useState();
+ const cx = useCx();
+
+ const singleColumnClassName = cx( css( { gridColumn: 'span 1' } ) );
+
return (
<>
<div style={ { maxWidth: '280px' } }>
@@ -157,6 +167,7 @@ export const TypographyPanel = () => {
label="Line Height"
onDeselect={ () => setLineHeight( undefined ) }
isShownByDefault={ true }
+ className={ singleColumnClassName }
>
<LineHeightControl
value={ lineHeight }
@@ -169,6 +180,7 @@ export const TypographyPanel = () => {
label="Letter Spacing"
onDeselect={ () => setLetterSpacing( undefined ) }
isShownByDefault={ true }
+ className={ singleColumnClassName }
>
<LetterSpacingControl
value={ letterSpacing } What I'm suggesting is a component-first approach (as opposed to an editor-first approach). In order to do that:
|
* Overwrite default component view label styles so that the Typography control labels are uniform Organize imports alphabetically Remove hyphen from label * Rolling back margin changes since they'll be fixed in #36387 * Remove classname
8706d7f
to
3a04a04
Compare
This appears to be due to the lack of a standard line-height applied to labels in the Storybook. I've added a new rule that ensures that standardized line-height for You'll notice that:
|
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.
This appears to be due to the lack of a standard line-height applied to labels in the Storybook.
Yes, my main point is to say that these fixes to the labels:
- should be applied to the individual components (and not to the
ToolsPanel
) - should be tested in Storybook first, and in the editor after
I understand the need to apply this fix to the ToolsPanel
temporarily with this PR, but we should follow-up with an investigation and a refactor of the control components. Ideally, they should all inherit from the same BaseControl
and share the same label styles.
Finally, before merging, could you also add a quick note to the CHANGELOG? Thank you!
🚀
This was in response to issue raised about misalignment of labels only in the Storybook.
a6e27d1
to
ba4e519
Compare
Related: #36334
Description
This PR standardizes the line-height and margin of
InputControl
labels within theToolsPanel
to improve consistency.See: #36334 (comment)
How has this been tested?
Screenshots
Types of changes
Enhancement.
Checklist:
*.native.js
files for terms that need renaming or removal).