Skip to content
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

LineHeightControl: Allow for more granular control of decimal places #52902

Merged
merged 25 commits into from
Aug 14, 2023

Conversation

mikachan
Copy link
Member

@mikachan mikachan commented Jul 24, 2023

What?

This adds an additional step value to the LineHeightControl of 0.01, which allows for more granular control over the line-height value.

Currently, users are only able to use values with single decimal places, such as 1.5 or 1.6. But there is quite a big difference between just one decimal place, and it would be great if smaller values could be set, such as 1.55, etc.

Please see #42998 and #51754 for more details.

Why?

Closes #42998.

How?

Adds a spinFactor prop to the NumberControl component to opt-in for more granular control over decimal places.

Testing Instructions

  1. Go to the Post or Site editor.
  2. Insert a Paragraph block or any block that supports line-height.
  3. Try changing the line-height using the block controls to a value with two decimal places, e.g. 1.62.
  4. The value should not automatically round up or down to a value with one decimal place and should remain the same value with two decimal places.
  5. Using the arrow keys or the spin controls, increase and decrease the line-height. The value should change by 0.1.

Screenshots or screencast

Screen.Recording.2023-07-27.at.10.35.32.mov

Dev note

A new spinFactor prop has been added to NumberControl, allowing consumers of the components to specify by how much should the input's value increment/decrement with respect to the step prop. This is particularly useful when more granular control is needed (thus allowing for more decimal places and a smaller step) but without sacrificing the UX around manually incrementing/decrementing the value.

Even if the prop was added to NumberControl, all components based on NumberControl can benefit from this change — this includes, for example, UnitControl and LineHeightControl.

@mikachan mikachan added [Package] Block editor /packages/block-editor [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi labels Jul 24, 2023
@mikachan mikachan requested a review from ellatrix as a code owner July 24, 2023 18:44
@mikachan mikachan self-assigned this Jul 24, 2023
@mikachan mikachan added the [Type] Enhancement A suggestion for improvement. label Jul 24, 2023
@github-actions
Copy link

github-actions bot commented Jul 24, 2023

Size Change: +36 B (0%)

Total Size: 1.5 MB

Filename Size Change
build/block-editor/index.min.js 211 kB +7 B (0%)
build/components/index.min.js 245 kB +29 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 955 B
build/annotations/index.min.js 2.69 kB
build/api-fetch/index.min.js 2.28 kB
build/autop/index.min.js 2.1 kB
build/blob/index.min.js 451 B
build/block-directory/index.min.js 7.01 kB
build/block-directory/style-rtl.css 1.02 kB
build/block-directory/style.css 1.02 kB
build/block-editor/content-rtl.css 4.26 kB
build/block-editor/content.css 4.25 kB
build/block-editor/default-editor-styles-rtl.css 381 B
build/block-editor/default-editor-styles.css 381 B
build/block-editor/style-rtl.css 14.9 kB
build/block-editor/style.css 14.9 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 90 B
build/block-library/blocks/archives/style.css 90 B
build/block-library/blocks/audio/editor-rtl.css 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 122 B
build/block-library/blocks/audio/style.css 122 B
build/block-library/blocks/audio/theme-rtl.css 126 B
build/block-library/blocks/audio/theme.css 126 B
build/block-library/blocks/avatar/editor-rtl.css 116 B
build/block-library/blocks/avatar/editor.css 116 B
build/block-library/blocks/avatar/style-rtl.css 104 B
build/block-library/blocks/avatar/style.css 104 B
build/block-library/blocks/block/editor-rtl.css 305 B
build/block-library/blocks/block/editor.css 305 B
build/block-library/blocks/button/editor-rtl.css 584 B
build/block-library/blocks/button/editor.css 582 B
build/block-library/blocks/button/style-rtl.css 624 B
build/block-library/blocks/button/style.css 623 B
build/block-library/blocks/buttons/editor-rtl.css 337 B
build/block-library/blocks/buttons/editor.css 337 B
build/block-library/blocks/buttons/style-rtl.css 332 B
build/block-library/blocks/buttons/style.css 332 B
build/block-library/blocks/calendar/style-rtl.css 239 B
build/block-library/blocks/calendar/style.css 239 B
build/block-library/blocks/categories/editor-rtl.css 113 B
build/block-library/blocks/categories/editor.css 112 B
build/block-library/blocks/categories/style-rtl.css 124 B
build/block-library/blocks/categories/style.css 124 B
build/block-library/blocks/code/editor-rtl.css 53 B
build/block-library/blocks/code/editor.css 53 B
build/block-library/blocks/code/style-rtl.css 121 B
build/block-library/blocks/code/style.css 121 B
build/block-library/blocks/code/theme-rtl.css 124 B
build/block-library/blocks/code/theme.css 124 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 421 B
build/block-library/blocks/columns/style.css 421 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 125 B
build/block-library/blocks/comment-author-avatar/editor.css 125 B
build/block-library/blocks/comment-content/style-rtl.css 92 B
build/block-library/blocks/comment-content/style.css 92 B
build/block-library/blocks/comment-template/style-rtl.css 199 B
build/block-library/blocks/comment-template/style.css 198 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-title/editor-rtl.css 75 B
build/block-library/blocks/comments-title/editor.css 75 B
build/block-library/blocks/comments/editor-rtl.css 840 B
build/block-library/blocks/comments/editor.css 839 B
build/block-library/blocks/comments/style-rtl.css 637 B
build/block-library/blocks/comments/style.css 636 B
build/block-library/blocks/cover/editor-rtl.css 647 B
build/block-library/blocks/cover/editor.css 650 B
build/block-library/blocks/cover/style-rtl.css 1.61 kB
build/block-library/blocks/cover/style.css 1.6 kB
build/block-library/blocks/details/editor-rtl.css 65 B
build/block-library/blocks/details/editor.css 65 B
build/block-library/blocks/details/style-rtl.css 98 B
build/block-library/blocks/details/style.css 98 B
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 B
build/block-library/blocks/embed/style-rtl.css 410 B
build/block-library/blocks/embed/style.css 410 B
build/block-library/blocks/embed/theme-rtl.css 126 B
build/block-library/blocks/embed/theme.css 126 B
build/block-library/blocks/file/editor-rtl.css 316 B
build/block-library/blocks/file/editor.css 316 B
build/block-library/blocks/file/style-rtl.css 280 B
build/block-library/blocks/file/style.css 281 B
build/block-library/blocks/file/view-interactivity.min.js 317 B
build/block-library/blocks/file/view.min.js 375 B
build/block-library/blocks/footnotes/style-rtl.css 201 B
build/block-library/blocks/footnotes/style.css 199 B
build/block-library/blocks/freeform/editor-rtl.css 2.61 kB
build/block-library/blocks/freeform/editor.css 2.61 kB
build/block-library/blocks/gallery/editor-rtl.css 947 B
build/block-library/blocks/gallery/editor.css 952 B
build/block-library/blocks/gallery/style-rtl.css 1.53 kB
build/block-library/blocks/gallery/style.css 1.53 kB
build/block-library/blocks/gallery/theme-rtl.css 108 B
build/block-library/blocks/gallery/theme.css 108 B
build/block-library/blocks/group/editor-rtl.css 654 B
build/block-library/blocks/group/editor.css 654 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 76 B
build/block-library/blocks/heading/style.css 76 B
build/block-library/blocks/html/editor-rtl.css 336 B
build/block-library/blocks/html/editor.css 337 B
build/block-library/blocks/image/editor-rtl.css 834 B
build/block-library/blocks/image/editor.css 833 B
build/block-library/blocks/image/style-rtl.css 1.42 kB
build/block-library/blocks/image/style.css 1.42 kB
build/block-library/blocks/image/theme-rtl.css 126 B
build/block-library/blocks/image/theme.css 126 B
build/block-library/blocks/image/view-interactivity.min.js 1.46 kB
build/block-library/blocks/latest-comments/style-rtl.css 357 B
build/block-library/blocks/latest-comments/style.css 357 B
build/block-library/blocks/latest-posts/editor-rtl.css 213 B
build/block-library/blocks/latest-posts/editor.css 212 B
build/block-library/blocks/latest-posts/style-rtl.css 478 B
build/block-library/blocks/latest-posts/style.css 478 B
build/block-library/blocks/list/style-rtl.css 88 B
build/block-library/blocks/list/style.css 88 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 507 B
build/block-library/blocks/media-text/style.css 505 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 712 B
build/block-library/blocks/navigation-link/editor.css 711 B
build/block-library/blocks/navigation-link/style-rtl.css 115 B
build/block-library/blocks/navigation-link/style.css 115 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 296 B
build/block-library/blocks/navigation-submenu/editor.css 295 B
build/block-library/blocks/navigation/editor-rtl.css 2.26 kB
build/block-library/blocks/navigation/editor.css 2.26 kB
build/block-library/blocks/navigation/style-rtl.css 2.23 kB
build/block-library/blocks/navigation/style.css 2.22 kB
build/block-library/blocks/navigation/view-interactivity.min.js 988 B
build/block-library/blocks/navigation/view-modal.min.js 2.85 kB
build/block-library/blocks/navigation/view.min.js 469 B
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 401 B
build/block-library/blocks/page-list/editor.css 401 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 174 B
build/block-library/blocks/paragraph/editor.css 174 B
build/block-library/blocks/paragraph/style-rtl.css 279 B
build/block-library/blocks/paragraph/style.css 281 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/editor-rtl.css 96 B
build/block-library/blocks/post-comments-form/editor.css 96 B
build/block-library/blocks/post-comments-form/style-rtl.css 508 B
build/block-library/blocks/post-comments-form/style.css 508 B
build/block-library/blocks/post-date/style-rtl.css 61 B
build/block-library/blocks/post-date/style.css 61 B
build/block-library/blocks/post-excerpt/editor-rtl.css 71 B
build/block-library/blocks/post-excerpt/editor.css 71 B
build/block-library/blocks/post-excerpt/style-rtl.css 141 B
build/block-library/blocks/post-excerpt/style.css 141 B
build/block-library/blocks/post-featured-image/editor-rtl.css 588 B
build/block-library/blocks/post-featured-image/editor.css 586 B
build/block-library/blocks/post-featured-image/style-rtl.css 319 B
build/block-library/blocks/post-featured-image/style.css 319 B
build/block-library/blocks/post-navigation-link/style-rtl.css 153 B
build/block-library/blocks/post-navigation-link/style.css 153 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 314 B
build/block-library/blocks/post-template/style.css 314 B
build/block-library/blocks/post-terms/style-rtl.css 96 B
build/block-library/blocks/post-terms/style.css 96 B
build/block-library/blocks/post-time-to-read/style-rtl.css 69 B
build/block-library/blocks/post-time-to-read/style.css 69 B
build/block-library/blocks/post-title/style-rtl.css 100 B
build/block-library/blocks/post-title/style.css 100 B
build/block-library/blocks/preformatted/style-rtl.css 125 B
build/block-library/blocks/preformatted/style.css 125 B
build/block-library/blocks/pullquote/editor-rtl.css 135 B
build/block-library/blocks/pullquote/editor.css 135 B
build/block-library/blocks/pullquote/style-rtl.css 335 B
build/block-library/blocks/pullquote/style.css 335 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 302 B
build/block-library/blocks/query-pagination/style.css 299 B
build/block-library/blocks/query-title/style-rtl.css 63 B
build/block-library/blocks/query-title/style.css 63 B
build/block-library/blocks/query/editor-rtl.css 450 B
build/block-library/blocks/query/editor.css 449 B
build/block-library/blocks/quote/style-rtl.css 222 B
build/block-library/blocks/quote/style.css 222 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 132 B
build/block-library/blocks/read-more/style.css 132 B
build/block-library/blocks/rss/editor-rtl.css 149 B
build/block-library/blocks/rss/editor.css 149 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 178 B
build/block-library/blocks/search/editor.css 178 B
build/block-library/blocks/search/style-rtl.css 608 B
build/block-library/blocks/search/style.css 608 B
build/block-library/blocks/search/theme-rtl.css 114 B
build/block-library/blocks/search/theme.css 114 B
build/block-library/blocks/search/view.min.js 631 B
build/block-library/blocks/separator/editor-rtl.css 146 B
build/block-library/blocks/separator/editor.css 146 B
build/block-library/blocks/separator/style-rtl.css 234 B
build/block-library/blocks/separator/style.css 234 B
build/block-library/blocks/separator/theme-rtl.css 194 B
build/block-library/blocks/separator/theme.css 194 B
build/block-library/blocks/shortcode/editor-rtl.css 323 B
build/block-library/blocks/shortcode/editor.css 323 B
build/block-library/blocks/site-logo/editor-rtl.css 754 B
build/block-library/blocks/site-logo/editor.css 754 B
build/block-library/blocks/site-logo/style-rtl.css 203 B
build/block-library/blocks/site-logo/style.css 203 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 116 B
build/block-library/blocks/site-title/editor.css 116 B
build/block-library/blocks/site-title/style-rtl.css 57 B
build/block-library/blocks/site-title/style.css 57 B
build/block-library/blocks/social-link/editor-rtl.css 184 B
build/block-library/blocks/social-link/editor.css 184 B
build/block-library/blocks/social-links/editor-rtl.css 674 B
build/block-library/blocks/social-links/editor.css 673 B
build/block-library/blocks/social-links/style-rtl.css 1.44 kB
build/block-library/blocks/social-links/style.css 1.43 kB
build/block-library/blocks/spacer/editor-rtl.css 348 B
build/block-library/blocks/spacer/editor.css 348 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 433 B
build/block-library/blocks/table/editor.css 433 B
build/block-library/blocks/table/style-rtl.css 645 B
build/block-library/blocks/table/style.css 644 B
build/block-library/blocks/table/theme-rtl.css 146 B
build/block-library/blocks/table/theme.css 146 B
build/block-library/blocks/tag-cloud/style-rtl.css 251 B
build/block-library/blocks/tag-cloud/style.css 253 B
build/block-library/blocks/template-part/editor-rtl.css 403 B
build/block-library/blocks/template-part/editor.css 403 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/term-description/style-rtl.css 111 B
build/block-library/blocks/term-description/style.css 111 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 99 B
build/block-library/blocks/verse/style.css 99 B
build/block-library/blocks/video/editor-rtl.css 552 B
build/block-library/blocks/video/editor.css 555 B
build/block-library/blocks/video/style-rtl.css 185 B
build/block-library/blocks/video/style.css 185 B
build/block-library/blocks/video/theme-rtl.css 126 B
build/block-library/blocks/video/theme.css 126 B
build/block-library/classic-rtl.css 179 B
build/block-library/classic.css 179 B
build/block-library/common-rtl.css 1.1 kB
build/block-library/common.css 1.1 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/editor-rtl.css 12.1 kB
build/block-library/editor.css 12.1 kB
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/index.min.js 203 kB
build/block-library/reset-rtl.css 478 B
build/block-library/reset.css 478 B
build/block-library/style-rtl.css 13.7 kB
build/block-library/style.css 13.8 kB
build/block-library/theme-rtl.css 686 B
build/block-library/theme.css 691 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.87 kB
build/blocks/index.min.js 51.2 kB
build/commands/index.min.js 15.3 kB
build/commands/style-rtl.css 863 B
build/commands/style.css 857 B
build/components/style-rtl.css 11.8 kB
build/components/style.css 11.8 kB
build/compose/index.min.js 12.1 kB
build/core-commands/index.min.js 2.44 kB
build/core-data/index.min.js 16.8 kB
build/customize-widgets/index.min.js 12 kB
build/customize-widgets/style-rtl.css 1.46 kB
build/customize-widgets/style.css 1.45 kB
build/data-controls/index.min.js 640 B
build/data/index.min.js 8.38 kB
build/date/index.min.js 17.8 kB
build/deprecated/index.min.js 451 B
build/dom-ready/index.min.js 324 B
build/dom/index.min.js 4.64 kB
build/edit-post/classic-rtl.css 544 B
build/edit-post/classic.css 545 B
build/edit-post/index.min.js 35.7 kB
build/edit-post/style-rtl.css 7.59 kB
build/edit-post/style.css 7.59 kB
build/edit-site/index.min.js 91 kB
build/edit-site/style-rtl.css 13.2 kB
build/edit-site/style.css 13.2 kB
build/edit-widgets/index.min.js 16.9 kB
build/edit-widgets/style-rtl.css 4.53 kB
build/edit-widgets/style.css 4.53 kB
build/editor/index.min.js 45.5 kB
build/editor/style-rtl.css 3.55 kB
build/editor/style.css 3.55 kB
build/element/index.min.js 4.82 kB
build/escape-html/index.min.js 537 B
build/format-library/index.min.js 7.59 kB
build/format-library/style-rtl.css 554 B
build/format-library/style.css 553 B
build/hooks/index.min.js 1.55 kB
build/html-entities/index.min.js 448 B
build/i18n/index.min.js 3.58 kB
build/interactivity/index.min.js 10.4 kB
build/is-shallow-equal/index.min.js 527 B
build/keyboard-shortcuts/index.min.js 1.64 kB
build/keycodes/index.min.js 1.87 kB
build/list-reusable-blocks/index.min.js 2.2 kB
build/list-reusable-blocks/style-rtl.css 836 B
build/list-reusable-blocks/style.css 836 B
build/media-utils/index.min.js 2.9 kB
build/notices/index.min.js 948 B
build/nux/index.min.js 1.99 kB
build/nux/style-rtl.css 735 B
build/nux/style.css 732 B
build/plugins/index.min.js 1.79 kB
build/preferences-persistence/index.min.js 1.84 kB
build/preferences/index.min.js 1.24 kB
build/primitives/index.min.js 943 B
build/priority-queue/index.min.js 1.52 kB
build/private-apis/index.min.js 951 B
build/react-i18n/index.min.js 615 B
build/react-refresh-entry/index.min.js 9.47 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.7 kB
build/reusable-blocks/index.min.js 2.71 kB
build/reusable-blocks/style-rtl.css 243 B
build/reusable-blocks/style.css 243 B
build/rich-text/index.min.js 11 kB
build/router/index.min.js 1.78 kB
build/server-side-render/index.min.js 1.94 kB
build/shortcode/index.min.js 1.39 kB
build/style-engine/index.min.js 1.85 kB
build/sync/index.min.js 53.8 kB
build/token-list/index.min.js 582 B
build/url/index.min.js 3.73 kB
build/vendors/inert-polyfill.min.js 2.48 kB
build/vendors/react-dom.min.js 41.8 kB
build/vendors/react.min.js 4.02 kB
build/viewport/index.min.js 958 B
build/warning/index.min.js 268 B
build/widgets/index.min.js 7.16 kB
build/widgets/style-rtl.css 1.15 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.02 kB

compressed-size-action

@github-actions
Copy link

github-actions bot commented Jul 24, 2023

Flaky tests detected in 1984787.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5679123569
📝 Reported issues:

@richtabor
Copy link
Member

I don't think this is a good idea.

Pressing 10x more times to get + 0.1 point change doesn't seem ideal.

The current implementation is 0.1 stepped, which provides enough of a difference in a short enough process, if you're using the + and - controls. If you want something more specific, it's easier to type in, say 1.55 instead of pressing the + five times (assuming you start at 1.5).

And if you want to go from 1.5 to 1.7, it's quite a heavy UX lift, whereas today it's only two clicks.

@hanneslsm
Copy link

hanneslsm commented Jul 26, 2023

Pressing 10x more times to get + 0.1 point change doesn't seem ideal.

The current implementation is 0.1 stepped, which provides enough of a difference in a short enough process, if you're using the + and - controls. If you want something more specific, it's easier to type in, say 1.55 instead of pressing the + five times (assuming you start at 1.5).

And if you want to go from 1.5 to 1.7, it's quite a heavy UX lift, whereas today it's only two clicks.

I was about to comment the same.
While I absolutely think that it should be possible to have line-heights of 1.23, I think it's an issue of the input element
From what I can tell, the input with + and - is a custom one, @richtabor do you know when and why it was introduced?
We also do have other situations where 10-step is only possible but another input field is used. (#51625)

I think the best solution would be to make it possible to enter values 1.23 manually, but have the plus and minus to jump/reset the value to 1.3 or 1.2

@mikachan mikachan requested a review from ajitbohra as a code owner July 27, 2023 09:26
@mikachan mikachan changed the title LineHeightControl: Change default step value from 0.1 to 0.01 LineHeightControl: Allow for more granular control of decimal places Jul 27, 2023
@mikachan
Copy link
Member Author

Thanks, both, for the feedback! I agree; whilst that solution allowed for 2 decimal places, it introduced a UX regression.

I've updated the PR with another idea, which allows the user to manually enter up to 2 decimal places but will also maintain the step value of 0.1 when using the spin controls or arrow keys. I've updated the screencast in the video so you can see how it works.

The value in the NumberControl line-height input is calculated using roundClamp(), which rounds the input value based on the step value. In order to allow both the 0.1 step input controls and the 0.01 for manually adding 2 decimal places, the 0.01 step value needs to be passed to roundClamp, otherwise this function removes the second decimal place (as it's rounding the value based on 0.1).

So I've introduced an optional prop that can be passed to the NumberControl component called roundingStep, which is used instead of the default step value if it exists, and is only used in the rounding calculation. I tried to use a solution that didn't interfere too much with the existing calculations but also wasn't specific to the line-height control, so other components using the NumberControl can use it where needed.

@mikachan mikachan added the [Package] Components /packages/components label Jul 27, 2023
@hanneslsm
Copy link

hanneslsm commented Jul 27, 2023

Thanks @mikachan !
From what I can tell from the video, after entering 1.25 and clicking - once I'd end up at 1.15?
Not sure if this is a common usage. I think it'd be better to click once - and get back to a rounded value, meaning 1.2. This way I can quickly test if 1.25 (manually typed in) 1.2 (click) or 1.0 (click click) works best.

For context, for most font sizes it's common to have rounded values. However, sometimes it's needed to have the second decimal number. That's what this PR is for. For the input field controls, I'd go with the rounding. Examples: https://typescale.com/

@richtabor
Copy link
Member

We also do have other situations where 10-step is only possible but another input field is used. (#51625)

This is a limitation because of how the block was originally introduced; it's manually applying CSS classes for every tenth value. 😅

I've updated the PR with another idea, which allows the user to manually enter up to 2 decimal places but will also maintain the step value of 0.1 when using the spin controls or arrow keys. I've updated the screencast in the video so you can see how it works.

Looks ace!

@richtabor richtabor self-requested a review July 27, 2023 15:33
Copy link
Member

@richtabor richtabor left a comment

Choose a reason for hiding this comment

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

Design + UX wise this feels much better than what we have in trunk. 🚀

@mirka mirka requested review from mirka and stokesman July 27, 2023 23:45
Copy link
Contributor

@stokesman stokesman left a comment

Choose a reason for hiding this comment

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

Thank you for taking this up 🙌 The current changes do resolve the issue. While it doesn't cause practical problems that I'm aware of, this part bugs me:

image

That's Chrome on macOS if you hover the input. This is due to step being more a validation attribute than anything else.

Because of that, I think your first pass of setting the line height control’s step to .01 was the way to go. Since the granularity of the stepping UX should be preserved, we could introduce a prop to specify that instead. I'd feel better about that direction. WDYT?

A diff of quick and dirty changes toward suggested direction
diff --git a/packages/block-editor/src/components/line-height-control/index.js b/packages/block-editor/src/components/line-height-control/index.js
index dc0cf05d18..62233c9d93 100644
--- a/packages/block-editor/src/components/line-height-control/index.js
+++ b/packages/block-editor/src/components/line-height-control/index.js
@@ -111,8 +111,8 @@ const LineHeightControl = ( {
 				onChange={ handleOnChange }
 				label={ __( 'Line height' ) }
 				placeholder={ BASE_DEFAULT_VALUE }
-				step={ STEP }
-				roundingStep={ ROUNDING_STEP }
+				step={ ROUNDING_STEP }
+				spincrement={ STEP }
 				value={ value }
 				min={ 0 }
 				spinControls="custom"
diff --git a/packages/components/src/number-control/index.tsx b/packages/components/src/number-control/index.tsx
index 1909937b97..bbb900ec4e 100644
--- a/packages/components/src/number-control/index.tsx
+++ b/packages/components/src/number-control/index.tsx
@@ -43,7 +43,7 @@ function UnforwardedNumberControl(
 		required = false,
 		shiftStep = 10,
 		step = 1,
-		roundingStep,
+		spincrement = step,
 		type: typeProp = 'number',
 		value: valueProp,
 		size = 'default',
@@ -65,7 +65,8 @@ function UnforwardedNumberControl(
 	const mergedRef = useMergeRefs( [ inputRef, forwardedRef ] );
 
 	const isStepAny = step === 'any';
-	const baseStep = isStepAny ? 1 : ensureNumber( step );
+	let baseStep = ensureNumber( spincrement );
+	if ( spincrement === step ) baseStep = isStepAny ? 1 : ensureNumber( step );
 	const baseValue = roundClamp( 0, min, max, baseStep );
 	const constrainValue = (
 		value: number | string,
@@ -73,15 +74,11 @@ function UnforwardedNumberControl(
 	): string => {
 		// When step is "any" clamp the value, otherwise round and clamp it.
 		// Use '' + to convert to string for use in input value attribute.
-		return isStepAny
-			? '' + Math.min( max, Math.max( min, ensureNumber( value ) ) )
-			: '' +
-					roundClamp(
-						value,
-						min,
-						max,
-						stepOverride ?? ( roundingStep || baseStep )
-					);
+		return `${
+			isStepAny
+				? Math.min( max, Math.max( min, ensureNumber( value ) ) )
+				: roundClamp( value, min, max, stepOverride ?? baseStep )
+		}`;
 	};
 
 	const autoComplete = typeProp === 'number' ? 'off' : undefined;

@richtabor
Copy link
Member

Because of that, I think your first pass of setting the line height control’s step to .01 was the way to go. Since the granularity of the stepping UX should be preserved, we could introduce a prop to specify that instead. I'd feel better about that direction. WDYT?

I mentioned earlier why .01 stepping holistically would make line height + and - quite tedious. I wouldn’t want to press + numerous times to really modify the line height.

@stokesman
Copy link
Contributor

stokesman commented Jul 28, 2023

My bad if I didn't make that very clear but in part of what you quoted:

Since the granularity of the stepping UX should be preserved, we could introduce a prop to specify that instead

Meaning that the direction I've suggested maintains the current UX.

mikachan and others added 2 commits August 7, 2023 10:01
Co-Authored-By: Mitchell Austin <9000376+stokesman@users.noreply.github.com>
@mikachan
Copy link
Member Author

mikachan commented Aug 7, 2023

Thanks all, for all the feedback and input! 🙇

I really like the spincrement diff from @stokesman, so I've applied the ideas from that diff and then added some additional logic to handle the rounding calculations mentioned by @chad1008. I used roundClamp to round the line-height based on the STEP value rather than the ROUNDING_STEP value when there are two decimal places. This means that if a value ends in .x5, incrementing the value will round up to the next 0.1 value, and decrementing the value will round down to the current 0.1 value.

I think this is ready for another review!

@stokesman
Copy link
Contributor

Thanks for the updates Sarah!

added some additional logic to handle the rounding calculations mentioned by @chad1008.

I agree with fixing the issue Chad pointed out and ideally doing so in NumberControl so that it’s not an issue elsewhere. However, I don't think the rounding should be coarser than the step. My expectation is that from 1.45, hitting +/up arrow results in 1.55.

A diff fixing the spin issue in NumberControl
diff --git a/packages/components/src/number-control/index.tsx b/packages/components/src/number-control/index.tsx
index 6526b93694..678b88d62f 100644
--- a/packages/components/src/number-control/index.tsx
+++ b/packages/components/src/number-control/index.tsx
@@ -65,8 +65,9 @@ function UnforwardedNumberControl(
 	const mergedRef = useMergeRefs( [ inputRef, forwardedRef ] );
 
 	const isStepAny = step === 'any';
-	let baseStep = ensureNumber( spincrement );
-	if ( spincrement === step ) baseStep = isStepAny ? 1 : ensureNumber( step );
+	const [ baseSpin, baseStep ] = isStepAny
+		? [ 1, 1 ]
+		: [ ensureNumber( spincrement ), ensureNumber( step ) ];
 	const baseValue = roundClamp( 0, min, max, baseStep );
 	const constrainValue = (
 		value: number | string,
@@ -91,7 +92,7 @@ function UnforwardedNumberControl(
 	) => {
 		event?.preventDefault();
 		const shift = event?.shiftKey && isShiftStepEnabled;
-		const delta = shift ? ensureNumber( shiftStep ) * baseStep : baseStep;
+		const delta = shift ? ensureNumber( shiftStep ) * baseSpin : baseSpin;
 		let nextValue = isValueEmpty( value ) ? baseValue : value;
 		if ( direction === 'up' ) {
 			nextValue = add( nextValue, delta );
@@ -137,8 +138,8 @@ function UnforwardedNumberControl(
 				const [ x, y ] = payload.delta;
 				const enableShift = payload.shiftKey && isShiftStepEnabled;
 				const modifier = enableShift
-					? ensureNumber( shiftStep ) * baseStep
-					: baseStep;
+					? ensureNumber( shiftStep ) * baseSpin
+					: baseSpin;
 
 				let directionModifier;
 				let delta;

If you apply the diff as is, the line height control is still going to round off the hundredth so to test you'd have to either try a similar setup of NumberControl in Storybook or revert the changes for the special rounding in the line height control.


I also realized a more general concern about the spincrement prop. It seems a bad idea to implement as an amount independent of step because it sets up more potential to create inputs that "spin" to invalid values. I think I should have proposed it as a multiplier of step instead. That way a spin should always land on a valid step. I've push a branch based on this one to demonstrate the idea. In that branch I reverted the special rounding of the line height control because I think the fixed baseline in NumberControl suffices and to make it easy to try it that way.

@stokesman
Copy link
Contributor

stokesman commented Aug 7, 2023

Hannes, thanks for bringing that up again. I did see and consider your earlier comment yet it seems quite arbitrary. I.e. it's not clear which behavior is favorable in common use.

This way I can quickly test if 1.25 (manually typed in) 1.2 (click) or 1.0 (click click) works best.

As example of why this seems arbitrary, this alternative way is as quick or quicker:
I can quickly test if 1.25 (manually typed in) 1.2 (backspace) or 1.0 () works best.

I’m not really opposed to it but I think we might hold off on specializing it that way for the moment.

@hanneslsm
Copy link

@stokesman
I posted my comment and reevaluated shortly after. I deleted the comment but had to run before I could finish my new answer. Sorry.

I think the biggest challenge on deciding how the component should behave is that the plus and minus are visually very prominent and the element is not not known for it's behaviour yet.
Usually, we'd have an input field with arrows and they would probably in- & decrease the value by 0.01. As already discussed, not ideal here. The plus and minus definitely has its advantages.

I’m not really opposed to it but I think we might hold off on specializing it that way for the moment.

I agree and can see that people expect them to change the value by 0.1 (meaning 1.15 will become 1.25) no matter what the original value is. Actually, I am leaning more to agreeing with you and (for now) not specialising the input field even more.

I can quickly test if 1.25 (manually typed in) 1.2 (backspace) or 1.0 (↓↓) works best.

This is a very valid point emphasises the argument.

I guess I have change my mind and agree with you that we should (for now) avoid a special rounding.
Let's see how the users react.

mikachan and others added 3 commits August 8, 2023 17:32
Co-Authored-By: Mitchell Austin <9000376+stokesman@users.noreply.github.com>
Co-Authored-By: Mitchell Austin <9000376+stokesman@users.noreply.github.com>
@mikachan
Copy link
Member Author

mikachan commented Aug 8, 2023

Thanks both! I really appreciate the speedy feedback.

I agree and can see that people expect them to change the value by 0.1 (meaning 1.15 will become 1.25) no matter what the original value is.

I'm not too opinionated either way, but I also agree here, and it's potentially complicating things by specialising the logic, at least for now.

I've tried out both of @stokesman's diffs from the above comment, and I really like how this is working. I agree that the new prop (spinFactor) works better as a multiplier of step. I also agree with fixing the rounding logic directly in NumberControl - I tried out a few things with my previous attempt and decided it was specific to line-height values, but this iteration along with the spinFactor prop works very nicely within NumberControl@stokesman, thank you for providing such specific technical feedback!

Copy link
Contributor

@stokesman stokesman left a comment

Choose a reason for hiding this comment

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

Thanks again for the updates! I've taken it for another 🙊spin and everything behaves as expected. I noticed there were some unit tests that failed and manually tested to verify the behaviors still work. It was merely an implementation detail in the tests that needed an update. I pushed a commit for that so the tests should pass now.

Maybe we want sign off from one of the components crew but this looks good to go. I ❤️ the feature being added to NumberControl so the finer UX can be supported. Thanks again for tackling this Sarah 🙌 .

@mikachan
Copy link
Member Author

mikachan commented Aug 9, 2023

Thanks for updating that unit test! I stepped away from my computer before the tests finished yesterday and didn't run them locally 🙈 Thanks also for all your help with this PR!

@mikachan
Copy link
Member Author

mikachan commented Aug 9, 2023

@mirka Would you be able to review this please, as someone who knows the components well? Or suggest a good person for a review. Thank you 🙇

Copy link
Member

@mirka mirka left a comment

Choose a reason for hiding this comment

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

Loved seeing the collaboration here 🚀

To be honest though I'm a little confused as to what the ultimate change is supposed to be here 🤔 This is the behavior I'm seeing, and it seems to contradict what's written in the code comments ("A line-height value of 1.55 will increment to 1.65"):

CleanShot.2023-08-11.at.06.15.38.mp4

What exactly is supposed to happen after the changes in this PR?

In that vein, I think it'd be good to add some tests for the new behavior as well.

packages/components/src/number-control/index.tsx Outdated Show resolved Hide resolved
packages/components/src/number-control/index.tsx Outdated Show resolved Hide resolved
@stokesman
Copy link
Contributor

stokesman commented Aug 11, 2023

This is the behavior I'm seeing, and it seems to contradict what's written in the code comments…

I just double-checked and don't see what you are seeing. Perhaps there was a build hiccup of some sort. This is what I'm seeing:

Google.Chrome.-.Add.New.Post.My.WordPress.Website.WordPress.2023-08-10.at.4.38.07.PM.mp4

What exactly is supposed to happen after the changes in this PR?

Simply that the line height control accepts numbers with a hundredth decimal place and its behavior remains otherwise unchanged. It already "spins" by tenths and showing that it still does that is proof of preserved UX.

I think it'd be good to add some tests for the new behavior as well.

That's a fine idea. I'm not sure we'd need one for LineHeightControl’s acceptance of hundredth place values, WDYT? I think we’d mostly want something covering that the new spinFactor prop of NumberControl works as intended.

@mikachan
Copy link
Member Author

Thanks @mirka! To confirm, I'm seeing the same as @stokesman on this branch, and the biggest difference is that users can now manually add and save a line-height value with a hundredth decimal place. Currently, this decimal place is removed on blur or when interacting with the spin controls. Here's an example from trunk to compare to @stokesman's video:

Screen.Recording.2023-08-11.at.14.30.46.mov

I've added some tests for the spinFactor prop, following the patterns already used in the NumberControl tests. Everything worked as expected, but I'm not sure if I've added the correct number of tests (too many/too few). They're in these commits: 4c7d545 & facc66f.

Copy link
Member

@mirka mirka left a comment

Choose a reason for hiding this comment

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

Thank you both for clarifying! I got it working as expected now, it must've been a build hiccup indeed. The tests look good — I think it nicely captures how the feature is supposed to work.

🚀

@mikachan
Copy link
Member Author

Woop, thanks @mirka! I'll bring this in 🎉

(I had loads of fun working on this, thanks everyone!)

@mikachan mikachan merged commit 4388c48 into trunk Aug 14, 2023
@mikachan mikachan deleted the update/line-height-step branch August 14, 2023 09:39
@github-actions github-actions bot added this to the Gutenberg 16.5 milestone Aug 14, 2023
@ciampo ciampo added the has dev note when dev note is done (for upcoming WordPress release) label Oct 12, 2023
@ciampo
Copy link
Contributor

ciampo commented Oct 12, 2023

Added a dev note in the PR description

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi has dev note when dev note is done (for upcoming WordPress release) [Package] Block editor /packages/block-editor [Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug report: Line-height used to set more than 1 decimal
7 participants