Make WordPress Core

Opened 5 months ago

Closed 3 months ago

#63878 closed enhancement (fixed)

Backport: add support for text inputs on the elements API

Reported by: onemaggie's profile onemaggie Owned by: scruffian's profile scruffian
Milestone: 6.9 Priority: normal
Severity: normal Version:
Component: Themes Keywords: has-patch needs-testing gutenberg-merge
Focuses: Cc:

Description

Backport for https://github.com/WordPress/gutenberg/pull/70378

What?

Part of https://github.com/WordPress/gutenberg/issues/34198

This PR adds elements support to text based form inputs. This PR also updates the experimental form block and the comments block to implement this.

Why?

So a theme can style consistently how forms should look like regardless of the plugins/blocks installed (if they opt in this new API)

This also opens the possibility to style the new form input blocks more granularly while making use of block tools instead of CSS, opening the option for UI controls in the future if we so desire

How?

By allowing styling of text based inputs using the elements API

Testing Instructions

# Enable the Form block under the experiments section
# Insert a Form block, add inputs of all kinds to it
# Edit your theme.json to style the inputs, this is how I did it on my active theme:

"elements": {
			"textInput": {
				"border": {
					"radius": "0",
					"style": "solid",
					"width": "1px",
					"color": "red"
				},
				"color": {
					"text": "var(--wp--preset--color--theme-2)"
				},
				"typography": {
					"fontFamily": "var(--wp--preset--font-family--inter)"
				}
			},
}

Trunk This PR with theme.json changes This PR with no theme.json changes
https://github.com/user-attachments/assets/e40269bd-5764-4534-a7e4-7d75c6c6bd30 https://github.com/user-attachments/assets/0de0fbe4-a1a4-4849-a9df-90ca3a757cab https://github.com/user-attachments/assets/9c82f929-5aed-428e-a1ac-0567cd56a3ab

Change History (16)

#2 @SirLouen
5 months ago

  • Component changed from General to Themes
  • Keywords needs-testing added
  • Type changed from defect (bug) to enhancement

#3 @rollybueno
5 months ago

Test Report

Description

This report validates whether the indicated patch works as expected.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/9600

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.29
  • Server: nginx/1.29.0
  • Database: mysqli (Server: 8.4.6 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 139.0.0.0
  • OS: Linux
  • Theme: Twenty Twenty-Five 1.3
  • MU Plugins: None activated
  • Plugins:
    • Gutenberg 21.5.0
    • Test Reports 1.2.0

Steps

  1. Enable Gutenberg → Experiments → Blocks: add Form and input blocks.
  2. Create a new page. Insert one Form block and add text, email, url, password, search, tel, textarea, and a submit button.
  3. Visit the page on the front-end.
  4. In the active theme add the following to theme.json under elements, then refresh:
  "elements": {
    "textInput": {
      "border": {
        "radius": "0",
        "style": "solid",
        "width": "1px",
        "color": "red"
      },
      "color": {
        "text": ""
      },
      "typography": {
        "fontFamily": "var(--wp--preset--font-family--inter)"
      }
    }
  }

✖️ - the patch does not work

Additional Notes

  • Used https://schemas.wp.org/trunk/theme.json as the $schema
  • Got an error Property textInput is not allowed

https://i.imgur.com/DPQmD0Q.png

  • No style updates on the input field

Supplemental Artifacts

Before:
https://i.imgur.com/9NGqgkZ.png

After:
https://i.imgur.com/pU0NMeb.png

#4 @rollybueno
5 months ago

  • Keywords reporter-feedback added; needs-testing removed

Hey @onemaggie,

I wasn't able to make your patch working on my end. Can you check my testing report https://core.trac.wordpress.org/ticket/63878#comment:3 and let me know what I missed?

Interestingly, I got the Property textInput is not allowed error when adding it under the elements key.

Cheers!

#5 follow-up: @wildworks
4 months ago

Interestingly, I got the Property textInput is not allowed error when adding it under the elements key.

The schema should be defined correctly. Could you provide the complete theme.json code you used for testing?

#6 in reply to: ↑ 5 @rollybueno
4 months ago

  • Keywords needs-testing added; reporter-feedback removed

Replying to wildworks:

Interestingly, I got the Property textInput is not allowed error when adding it under the elements key.

The schema should be defined correctly. Could you provide the complete theme.json code you used for testing?

@wildworks - I just added it under styles -> elements in 2025 theme. This issue actually happens because 2025 is using https://schemas.wp.org/wp/6.7/theme.json, but that error is gone if I update to use https://schemas.wp.org/trunk/theme.json. I thought I was using trunk on my first test report.

https://i.imgur.com/1CR8fMb.png

New test result seems confirming this works, but only if the schema is using trunk version. Best if few more reports can confirm:

https://i.imgur.com/mgl43s0.png

Last edited 4 months ago by rollybueno (previous) (diff)

#7 @wildworks
4 months ago

This issue actually happens because 2025 is using https://schemas.wp.org/wp/6.7/theme.json, but that error is gone if I update to use https://schemas.wp.org/trunk/theme.json.

Yes, textInput will not be allowed unless you reference the latest schema (trunk/theme.json).

#8 @wildworks
4 months ago

  • Keywords gutenberg-merge added
  • Milestone changed from Awaiting Review to 6.9

This ticket is a backport from Gutenberg and should be addressed in the 6.9 release.

#9 @scruffian
3 months ago

  • Owner set to scruffian
  • Resolution set to fixed
  • Status changed from new to closed

In 61023:

Editor: Add support for text inputs to theme.json.

Adds support for text input elements to theme.json so that theme builders and extenders can be style text input elements consistently.

Text input elements are textarea, and input with type email, number, password, search, text, tel and url. We are targeting the HTML elements directly rather than adding a CSS class, as we do for other elements that theme.json supports. This commit adds no extra styling unless a theme opts in to use this and the specificity of any generated CSS with the element is 0.

See original Gutenberg PR: https://github.com/WordPress/gutenberg/pull/70378.

Example usage:

	"elements": {
		"textInput": {
			"border": {
				"radius": "0",
				"style": "solid",
				"width": "1px",
				"color": "red"
			},
			"color": {
				"text": "var(--wp--preset--color--theme-2)"
			},
			"typography": {
				"fontFamily": "var(--wp--preset--font-family--inter)"
			}
		}
	}

Reviewed by mukesh27, scruffian.
Merges [9600] to the 6.9 branch.

Props onemaggie, mukesh27, sabernhardt, joen, get_dave, wildworks, ocean90, mikachan, poena.
Fixes #63878. See #63555.

#10 @cbravobernal
3 months ago

In 61024:

Global styles: add element support for text related inputs.

Adds elements support to text based form inputs so a theme can style consistently how forms should look like regardless of the plugins/blocks installed.

Props onemaggie, mukesh27, sabernhardt, scruffian, get_dave, ocean90, mikachan, wildworks.

Fixes #63878.

#11 @scruffian
3 months ago

In 61031:

Editor: Add support for select elements to theme.json.

Adds support for the select element in theme.json so that theme builders and extenders can be style select elements consistently.

We are targeting the select HTML element rather than adding a CSS class, as we do for other elements that theme.json supports. This commit adds no extra styling unless a theme opts in to use this and the specificity of any generated CSS with the element is 0.

See original Gutenberg PR: https://github.com/WordPress/gutenberg/pull/70379.

Example usage:

	"elements": {
		"select": {
			"color": {
				"text": "red",
				"background": "blue"
			}
		}
	}

Props onemaggie, joen, get_dave, wildworks, ocean90, mikachan, poena, SirLouen, tusharbharti, yashjawale, abcd95.
Fixes #63555. See #63878.

#12 @rollybueno
3 months ago

Hi @scruffian @cbravobernal - I was not included in the props for testing here which I believe is a mistake 😅. Can you please add missed props?

#13 @scruffian
3 months ago

Sorry @rollybueno, that's now been done.

This ticket was mentioned in Slack in #core-committers by wildworks. View the logs.


3 months ago

#16 @davidbaumwald
3 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 61046:

Editor: Re-add support for text inputs to theme.json.

Re-adds support for text input elements to theme.json originally included in [61023] that was accidently removed in a subsequent commit.

This change also include the updated docblock for @since 6.9.0.

Follow-up to [61023], [61031].

Props leemon, wildworks, ella, scruffian, cbravobernal, desrosj, davidbaumwald.
Fixes #63878.

Note: See TracTickets for help on using tickets.