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

Search block: Add typography supports #43499

Merged
merged 18 commits into from
Sep 12, 2022

Conversation

ramonjd
Copy link
Member

@ramonjd ramonjd commented Aug 23, 2022

Related:

What?

Adds typography supports to the Search block.

Why?

  • Allows typographic styling of the Search block.
  • Improves consistency of our design tools across blocks.

How?

  • Opts into typography supports and applies them to the:
    • label
    • input (except text decoration)
    • button
  • Sets the font size control to display by default matching most other blocks.

Testing Instructions

  1. Edit a post, add a Search block, and select it. (See example HTML below).
  2. Check that all typography controls are now available.
  3. Test various typography settings ensuring styles are applied in the editor.
  4. Test various search block manifestations, e.g., button position, icon button.
  5. Save and confirm that the frontend appears as expected
  6. Do the same in the site editor. Also, edit global styles and make sure the styles are applied.
  7. Style the Search block via theme.json (see example json below).
  8. Confirm the theme.json style applies correctly in the editor and frontend.
Example block code
<!-- wp:search {"label":"Search","buttonText":"Search","style":{"typography":{"fontStyle":"italic","fontWeight":"600","textTransform":"uppercase","letterSpacing":"55px","lineHeight":3.5,"fontSize":"55px","textDecoration":"underline"}},"fontFamily":"source-serif-pro"} /-->

<!-- wp:separator {"className":"is-style-wide"} -->
<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide"/>
<!-- /wp:separator -->

<!-- wp:search {"label":"Search","showLabel":false,"buttonText":"Search","buttonPosition":"button-inside","style":{"typography":{"fontStyle":"italic","fontWeight":"600","textTransform":"capitalize","letterSpacing":"55px","lineHeight":3.5,"fontSize":"55px","textDecoration":"line-through"}},"fontFamily":"source-serif-pro"} /-->

<!-- wp:separator {"className":"is-style-wide"} -->
<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide"/>
<!-- /wp:separator -->

<!-- wp:search {"label":"Search","buttonText":"Search","style":{"typography":{"fontStyle":"italic","fontWeight":"600","textTransform":"capitalize","letterSpacing":"55px","lineHeight":3.5,"fontSize":"55px","textDecoration":"line-through"}},"fontFamily":"source-serif-pro"} /-->

<!-- wp:separator {"className":"is-style-wide"} -->
<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide"/>
<!-- /wp:separator -->

<!-- wp:search {"label":"Search","buttonText":"Search","buttonUseIcon":true,"style":{"typography":{"fontStyle":"italic","fontWeight":"600","textTransform":"capitalize","letterSpacing":"55px","lineHeight":3.5,"fontSize":"55px","textDecoration":"line-through"}},"fontFamily":"source-serif-pro"} /-->

<!-- wp:separator {"className":"is-style-wide"} -->
<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide"/>
<!-- /wp:separator -->

<!-- wp:search {"label":"Search","buttonText":"Search","buttonPosition":"no-button","style":{"typography":{"fontStyle":"italic","fontWeight":"600","textTransform":"capitalize","letterSpacing":"55px","lineHeight":3.5,"fontSize":"55px","textDecoration":"line-through"}},"fontFamily":"source-serif-pro"} /-->

Example theme.json snippet.

	"styles": {
		"blocks": {
			"core/search": {
				"typography": {
					"textDecoration": "line-through"
					"letterSpacing": "12px",
					"fontSize": "2rem",
					"textTransform": "uppercase",
					"lineHeight": "1",
					"fontStyle": "italic",
					"fontWeight": "600"
				}
			}
		}
	},

Screenshots or screencast

2022-08-25.16.05.55.mp4

@ramonjd ramonjd added [Type] Enhancement A suggestion for improvement. [Block] Search Affects the Search Block - used to display a search field [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi labels Aug 23, 2022
@ramonjd ramonjd self-assigned this Aug 23, 2022
@ramonjd ramonjd changed the title Post Author Name: Add typography supports Search block: Add typography supports Aug 23, 2022
@github-actions
Copy link

github-actions bot commented Aug 23, 2022

Size Change: +552 B (0%)

Total Size: 1.25 MB

Filename Size Change
build/block-editor/index.min.js 162 kB +164 B (0%)
build/block-library/blocks/search/style-rtl.css 409 B +13 B (+3%)
build/block-library/blocks/search/style.css 406 B +13 B (+3%)
build/block-library/index.min.js 188 kB +282 B (0%)
build/block-library/style-rtl.css 12.1 kB +10 B (0%)
build/block-library/style.css 12.1 kB +9 B (0%)
build/edit-site/index.min.js 58.5 kB +61 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 982 B
build/annotations/index.min.js 2.76 kB
build/api-fetch/index.min.js 2.26 kB
build/autop/index.min.js 2.14 kB
build/blob/index.min.js 475 B
build/block-directory/index.min.js 7.05 kB
build/block-directory/style-rtl.css 990 B
build/block-directory/style.css 991 B
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-editor/style-rtl.css 15.2 kB
build/block-editor/style.css 15.2 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 65 B
build/block-library/blocks/archives/style.css 65 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 84 B
build/block-library/blocks/avatar/style.css 84 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 482 B
build/block-library/blocks/button/editor.css 482 B
build/block-library/blocks/button/style-rtl.css 523 B
build/block-library/blocks/button/style.css 523 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 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 100 B
build/block-library/blocks/categories/style.css 100 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 103 B
build/block-library/blocks/code/style.css 103 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 406 B
build/block-library/blocks/columns/style.css 406 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 187 B
build/block-library/blocks/comment-template/style.css 185 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 834 B
build/block-library/blocks/comments/editor.css 832 B
build/block-library/blocks/comments/style-rtl.css 632 B
build/block-library/blocks/comments/style.css 630 B
build/block-library/blocks/cover/editor-rtl.css 605 B
build/block-library/blocks/cover/editor.css 607 B
build/block-library/blocks/cover/style-rtl.css 1.57 kB
build/block-library/blocks/cover/style.css 1.55 kB
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 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 253 B
build/block-library/blocks/file/style.css 254 B
build/block-library/blocks/file/view.min.js 346 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 948 B
build/block-library/blocks/gallery/editor.css 950 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 337 B
build/block-library/blocks/group/editor.css 337 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 327 B
build/block-library/blocks/html/editor.css 329 B
build/block-library/blocks/image/editor-rtl.css 876 B
build/block-library/blocks/image/editor.css 873 B
build/block-library/blocks/image/style-rtl.css 627 B
build/block-library/blocks/image/style.css 630 B
build/block-library/blocks/image/theme-rtl.css 126 B
build/block-library/blocks/image/theme.css 126 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 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 463 B
build/block-library/blocks/latest-posts/style.css 462 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 705 B
build/block-library/blocks/navigation-link/editor.css 703 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-submenu/view.min.js 423 B
build/block-library/blocks/navigation/editor-rtl.css 1.99 kB
build/block-library/blocks/navigation/editor.css 2 kB
build/block-library/blocks/navigation/style-rtl.css 2.15 kB
build/block-library/blocks/navigation/style.css 2.14 kB
build/block-library/blocks/navigation/view-modal.min.js 2.78 kB
build/block-library/blocks/navigation/view.min.js 443 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 363 B
build/block-library/blocks/page-list/editor.css 363 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 260 B
build/block-library/blocks/paragraph/style.css 260 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 493 B
build/block-library/blocks/post-comments-form/style.css 493 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 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 507 B
build/block-library/blocks/post-featured-image/editor.css 505 B
build/block-library/blocks/post-featured-image/style-rtl.css 166 B
build/block-library/blocks/post-featured-image/style.css 166 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 282 B
build/block-library/blocks/post-template/style.css 282 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 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 103 B
build/block-library/blocks/preformatted/style.css 103 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 326 B
build/block-library/blocks/pullquote/style.css 325 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 282 B
build/block-library/blocks/query-pagination/style.css 278 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 439 B
build/block-library/blocks/query/editor.css 439 B
build/block-library/blocks/quote/style-rtl.css 213 B
build/block-library/blocks/quote/style.css 213 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 202 B
build/block-library/blocks/rss/editor.css 204 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 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/theme-rtl.css 114 B
build/block-library/blocks/search/theme.css 114 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 464 B
build/block-library/blocks/shortcode/editor.css 464 B
build/block-library/blocks/site-logo/editor-rtl.css 488 B
build/block-library/blocks/site-logo/editor.css 488 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 84 B
build/block-library/blocks/site-title/editor.css 84 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.4 kB
build/block-library/blocks/social-links/style.css 1.39 kB
build/block-library/blocks/spacer/editor-rtl.css 322 B
build/block-library/blocks/spacer/editor.css 322 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 494 B
build/block-library/blocks/table/editor.css 494 B
build/block-library/blocks/table/style-rtl.css 611 B
build/block-library/blocks/table/style.css 609 B
build/block-library/blocks/table/theme-rtl.css 190 B
build/block-library/blocks/table/theme.css 190 B
build/block-library/blocks/tag-cloud/style-rtl.css 239 B
build/block-library/blocks/tag-cloud/style.css 239 B
build/block-library/blocks/template-part/editor-rtl.css 235 B
build/block-library/blocks/template-part/editor.css 235 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/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 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 561 B
build/block-library/blocks/video/editor.css 563 B
build/block-library/blocks/video/style-rtl.css 174 B
build/block-library/blocks/video/style.css 174 B
build/block-library/blocks/video/theme-rtl.css 126 B
build/block-library/blocks/video/theme.css 126 B
build/block-library/common-rtl.css 1.02 kB
build/block-library/common.css 1.02 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/editor-rtl.css 11 kB
build/block-library/editor.css 11 kB
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/reset-rtl.css 478 B
build/block-library/reset.css 478 B
build/block-library/theme-rtl.css 719 B
build/block-library/theme.css 722 B
build/block-serialization-default-parser/index.min.js 1.1 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/blocks/index.min.js 49.6 kB
build/components/index.min.js 198 kB
build/components/style-rtl.css 11.5 kB
build/components/style.css 11.5 kB
build/compose/index.min.js 12 kB
build/core-data/index.min.js 15.5 kB
build/customize-widgets/index.min.js 11.3 kB
build/customize-widgets/style-rtl.css 1.38 kB
build/customize-widgets/style.css 1.38 kB
build/data-controls/index.min.js 653 B
build/data/index.min.js 8.06 kB
build/date/index.min.js 32.1 kB
build/deprecated/index.min.js 507 B
build/dom-ready/index.min.js 324 B
build/dom/index.min.js 4.7 kB
build/edit-navigation/index.min.js 16 kB
build/edit-navigation/style-rtl.css 3.99 kB
build/edit-navigation/style.css 4 kB
build/edit-post/classic-rtl.css 546 B
build/edit-post/classic.css 547 B
build/edit-post/index.min.js 30.7 kB
build/edit-post/style-rtl.css 6.94 kB
build/edit-post/style.css 6.94 kB
build/edit-site/style-rtl.css 8.3 kB
build/edit-site/style.css 8.28 kB
build/edit-widgets/index.min.js 16.5 kB
build/edit-widgets/style-rtl.css 4.34 kB
build/edit-widgets/style.css 4.34 kB
build/editor/index.min.js 41.6 kB
build/editor/style-rtl.css 3.66 kB
build/editor/style.css 3.65 kB
build/element/index.min.js 4.68 kB
build/escape-html/index.min.js 537 B
build/format-library/index.min.js 6.75 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.64 kB
build/html-entities/index.min.js 448 B
build/i18n/index.min.js 3.77 kB
build/is-shallow-equal/index.min.js 527 B
build/keyboard-shortcuts/index.min.js 1.78 kB
build/keycodes/index.min.js 1.81 kB
build/list-reusable-blocks/index.min.js 1.74 kB
build/list-reusable-blocks/style-rtl.css 835 B
build/list-reusable-blocks/style.css 835 B
build/media-utils/index.min.js 2.93 kB
build/notices/index.min.js 953 B
build/nux/index.min.js 2.05 kB
build/nux/style-rtl.css 732 B
build/nux/style.css 728 B
build/plugins/index.min.js 1.94 kB
build/preferences-persistence/index.min.js 2.22 kB
build/preferences/index.min.js 1.3 kB
build/primitives/index.min.js 933 B
build/priority-queue/index.min.js 612 B
build/react-i18n/index.min.js 696 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.74 kB
build/reusable-blocks/index.min.js 2.21 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 10.4 kB
build/server-side-render/index.min.js 1.61 kB
build/shortcode/index.min.js 1.53 kB
build/token-list/index.min.js 644 B
build/url/index.min.js 3.61 kB
build/vendors/react-dom.min.js 38.5 kB
build/vendors/react.min.js 4.34 kB
build/viewport/index.min.js 1.09 kB
build/warning/index.min.js 268 B
build/widgets/index.min.js 7.19 kB
build/widgets/style-rtl.css 1.18 kB
build/widgets/style.css 1.19 kB
build/wordcount/index.min.js 1.06 kB

compressed-size-action

Copy link
Contributor

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

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

Thanks for tackling typography on the search block @ramonjd 👍

In general, this works for me in the editor however I hit a couple of small issues on the frontend.

If we continue with the approach of applying the typography support styles to the root of the Search block, we'll need to also inherit font-weight, font-style, and text-transform on the button as you did for letter-spacing.

Editor Frontend
Screen Shot 2022-08-23 at 4 43 19 pm Screen Shot 2022-08-23 at 4 43 12 pm

Also, I know text-decoration is an extreme edge case in most situations however it feels to me like it's more of a problem when a user is typing a value into the search input and it's appearing with the line-through style.

Additionally, the input with text decoration appears to be rendered differently across browsers. Firefox ignored the text decoration, Safari only rendered the line through for the user entered text, and Chrome rendered it for both the placeholder and entered text.

The current directive is to supply consistent typographical design tools (albeit optionally displayed). Would we be better served here by skipping the serialization of the typography supports and applying them manually to the label and button elements? Then leveraging the feature level selectors so that global styles and theme.json apply their styles only to those same elements.

What do you think?

@ramonjd
Copy link
Member Author

ramonjd commented Aug 23, 2022

skipping the serialization of the typography supports and applying them manually to the label and button elements

I knew it was too good to be true. 😄 Thanks for testing. I'll sort it.

@ramonjd ramonjd requested a review from ellatrix as a code owner August 24, 2022 05:06
@ramonjd
Copy link
Member Author

ramonjd commented Aug 24, 2022

I have the typography styles applied to the label, input (with the exception of text-decoration) and button just so we can test things out. Safari and Firefox looking okay!

I think the input does require at least font-size, otherwise things look a bit uneven:

Screen Shot 2022-08-24 at 3 06 57 pm

TODO

  • Global styles and feature selectors

@ramonjd ramonjd force-pushed the update/search-block-typography-support branch from 8f10249 to bc10961 Compare August 25, 2022 06:09
@@ -360,13 +378,118 @@ function styles_for_block_core_search( $attributes ) {
$button_styles[] = sprintf( 'background: %s;', $attributes['style']['color']['gradient'] );
}

// Add typography styles.
$has_font_size = ! empty( $attributes['style']['typography']['fontSize'] );
Copy link
Member Author

@ramonjd ramonjd Aug 25, 2022

Choose a reason for hiding this comment

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

Note to self: this is possibly something the style engine could optimize, since it will do all the $has_ checks internally, and return the classnames.

E.g.,

$typography_styles = gutenberg_style_engine_get_styles( array( 'typography' => $$attributes['style']['typography'] ) );

$button_styles = $typography_styles['css'];
$input_styles = $typography_styles['css'];

if ( $show_label ) {
    $label_styles = $typography_styles['css'];
}

Doesn't take into account no textDecoration for the input.

Maybe a follow up refactor anyway....

@carolinan
Copy link
Contributor

Styling the placeholder text and the input field text can make the block less accessible, for example by using a too low contrast. I would prefer if these options did not apply to the input field at all. If that is not an option, is there at least a specific color contrast warning?

Copy link
Contributor

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

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

@ramonjd Thanks for taking the leap to skip the serialization of typography styles for the Search block. 🙇

I'm not sure my suggestion to skip serialization and use feature-level selectors works unless we skip applying all typography from the input. As this PR stands now, if you configure text-decoration via theme.json, it will still be applied to the input.

You can test this via the snippet below:

			"core/search": {
				"typography": {
					"textDecoration": "line-through"
				}
			}

I agree with your earlier comment though about things looking odd and out-of-whack if we don't apply the non-decoration typography styles to the input.

At this stage, I don't believe we can exclude text-decoration styles from being included in the theme.json/global styles generated stylesheets. So short of adding that, we could override it via the block's CSS. However, due to the specificity of the generated selector, we'd need to fight that if taking this approach.

I appreciate the next suggestion will be a pain, but maybe we need to tweak the approach again. Could we do something similar to the following?

  • Continue to skip serialization of typography supports
  • Remove use of feature-level selectors
  • Apply the typography supports (excluding text-decoration) on the root wrapper
  • Apply text decoration to the button and label if appropriate
  • Add CSS override (which should only have to be now more specific than .wp-block-search)

What do you think?

I'd be happy to help on this or create an alternative PR for comparison if you think it would help.


Styling the placeholder text and the input field text can make the block less accessible, for example by using a too low contrast

@carolinan, unless I'm misunderstanding something, this PR should only be applying typography styles to the input. The color block support styles remain unchanged.

That said, I appreciate that color isn't the only characteristic that might impact accessibility. How much of an issue is changing font size or weight? Particularly, if it matches the button as per Ramon's earlier example?

packages/block-editor/src/hooks/use-typography-props.js Outdated Show resolved Hide resolved
packages/block-editor/src/hooks/use-typography-props.js Outdated Show resolved Hide resolved
packages/block-editor/src/index.js Outdated Show resolved Hide resolved
packages/block-library/src/search/index.php Outdated Show resolved Hide resolved
@ramonjd
Copy link
Member Author

ramonjd commented Aug 29, 2022

I appreciate the next suggestion will be a pain, but maybe we need to tweak the approach again. Could we do something similar to the following?

No problems at all. Thanks for retesting and the advice. I'll try to work things in the direction you mentioned.

@ramonjd ramonjd force-pushed the update/search-block-typography-support branch from 3bfb881 to 745f682 Compare September 8, 2022 11:48
@ramonjd
Copy link
Member Author

ramonjd commented Sep 8, 2022

Failing tests seem related.
waiting for selector "iframe[title="Site Preview"] >> nth=-1 >> control=enter-frame >> css=.widget-content >> role=searchbox[name="My Search"]"
👀

ramonjd and others added 6 commits September 9, 2022 12:18
Ensuring that letter spacing is inherited.
…ception of text-decoration for the input element) so we can test and eliminate features we think aren't required.
Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
ramonjd and others added 3 commits September 9, 2022 12:18
Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Apply all typography styles except text decoration to block wrapper
Inherit block wrapper styles in CSS for each element
Use getFontSizeClass()
Remove __experimentalSelector
Make getTypographyClassesAndStyles() stable
@ramonjd ramonjd force-pushed the update/search-block-typography-support branch from 432c77c to 3865941 Compare September 9, 2022 02:18
@carolinan
Copy link
Contributor

How much of an issue is changing font size or weight? Particularly, if it matches the button as per Ramon's earlier example?

I think it was the font weight that I got confused with color, as in the example, the light font weight (left image) is barely readable. Font size should not be an issue (disregarding cases where a user choose a font size that is too small in general)

Copy link
Contributor

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

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

Props for the continued iterations on this while wrangling everything else you are doing for 6.1 @ramonjd 🙇 Nice work.

✅ Typography styles are appropriately applied for individual blocks in both editors and the front end
✅ Search block typography can be styled via theme.json or Global Styles (with small compromise)

As we've encountered previously, without using a feature-level selector, we can't prevent theme.json or global styles text decoration from being applied to the input. The downside of omitting styles for the input, resulting in its font size not matching the label and button, is more severe. I think the current approach is a fair compromise, particularly given how extremely niche any use of text-decoration would be for this block.

I also left an inline comment regarding a small unnecessary change we should remove before landing this.

Comment on lines 216 to 220
const textFieldStyles = {
...( isButtonPositionInside
? { borderRadius }
: borderProps.style ),
};
Copy link
Contributor

Choose a reason for hiding this comment

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

After rolling back previous changes, I don't think we need this change anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for testing again @aaronrobertshaw, and for spotting the unnecessary code snippet here.

It made me see something else: I'd forgotten to roll back the application of the font size and family preset classnames to the individual elements. I've applied them to the wrapper only now.

You shouldn't see any differences in testing.

If it looks okay on Monday, please feel free to merge this PR. 🙇 🙇 🙇 🙇

ramonjd and others added 6 commits September 9, 2022 20:57
…he wrapper, not on the individual elements."

This reverts commit 384ce7d.
This commit reverts the approach to an earlier option tried so we can more reliably apply user-made typography selections without simple theme styles overriding the previous inherit styles.

This includes changes refining the previous approach so that text decoration isn't applied to the input by theme.json or global styles. It also fixes a bug around font family class generation in the render callback.
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

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

Thanks for refining this PR further, @ramonjd . 👍

While re-testing, I found some themes adding a simple .wp-block-search__button style would break the application of user-made typography selections due to the low specificity of the inherit rule.

I wrestled a bit with trying to find a neat way to overcome this. Including:

  • Applying just styles like font-size and font-family to the button and label elements. The result is pretty inconsistent in terms of where styles are being applied as well as which styles should be.

  • Adding custom classnames that we could hook onto to increase the specificity of the inherit styles. This worked for individual blocks but not the styles generated by theme.json or global styles.

  • Ultimately, I circled back on one of your previous approaches where we apply all the styles to the inner elements and use feature-level selectors so the theme.json and global styles generated styles target the inner elements.

    • Without text-decoration being applied on the parent we can override the theme.json and global styles generated class and forcibly unset the text-decoration for the input.
    • Applying the styles on the inner elements helps mitigate the risk of themes such as TwentyTwentyTwo overriding user-made selections.
    • Via the feature-level selectors we can better control the specificity of the search block's styles via theme.json and global styles.

    Given the heavy changes I've made to the PR and going around in circles a bit. I think we need some fresh eyes to review this again.

Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

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

Looks pretty close! It's working well in testing, except for a small detail: with big line heights the button icon is slightly off-center:
Screen Shot 2022-09-12 at 4 30 21 pm
Adding vertical-align: text-bottom; to .wp-block-search__button svg seems to fix it.

Apart from that, just a couple questions below.

@@ -6,6 +6,7 @@ export {
getBorderClassesAndStyles as __experimentalGetBorderClassesAndStyles,
useBorderProps as __experimentalUseBorderProps,
getColorClassesAndStyles as __experimentalGetColorClassesAndStyles,
getTypographyClassesAndStyles,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be marking this experimental?

Copy link
Contributor

Choose a reason for hiding this comment

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

@ramonjd initially had this as experimental until I suggested it be stabilized as we'll be stabilizing all experimental block support APIs post-6.1. This would just be another experimental API to process. Given it follows the same pattern as the other block supports, e.g. color and border, and they're due for stabilization. I figure we can save double handling this one.

We can change this if you have strong concerns.

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense to me! If color/border are similar and we're not planning on making further changes before stabilising, I wouldn't be opposed to doing it pre-6.1 either. Or were we aiming to stabilise all block supports together? It might take a while to get layout up to spec 😬

Copy link
Contributor

Choose a reason for hiding this comment

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

To my knowledge, there are no plans for further changes to these util functions. I was under the impression that we'd stabilize each block support in full, e.g. all the typography support APIs, then color, and so on. Layout support has always been a special case, so I don't think there is a rush to stabilize it before it's ready.

Regarding stabilizing the others pre-6.1, I don't think that's on the cards. My focus has been on adopting the block supports more consistently within Gutenberg and then seeing if there is anything we should alter before stabilizating them.

That said, if there's a window in which we could actually get it all done, I wouldn't be against it.

@aaronrobertshaw
Copy link
Contributor

with big line heights the button icon is slightly off-center

Good catch @tellthemachines, I'll tweak the styles accordingly. Thanks.

This centres the icon for the icon only button on the frontend when it has a tall line-height.
Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM!

@aaronrobertshaw aaronrobertshaw merged commit dff616f into trunk Sep 12, 2022
@aaronrobertshaw aaronrobertshaw deleted the update/search-block-typography-support branch September 12, 2022 08:23
@github-actions github-actions bot added this to the Gutenberg 14.1 milestone Sep 12, 2022
@femkreations femkreations added the Needs User Documentation Needs new user documentation label Sep 20, 2022
@annezazu annezazu mentioned this pull request Sep 29, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Search Affects the Search Block - used to display a search field [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi Needs User Documentation Needs new user documentation [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants