-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
TextareaAutosize: Refactor to TextareaControl
with field-sizing
#64208
base: trunk
Are you sure you want to change the base?
Conversation
Size Change: -5.15 kB (-0.29%) Total Size: 1.76 MB
ℹ️ View Unchanged
|
className="block-editor-block-list__block-html-textarea" | ||
value={ html } | ||
onBlur={ onChange } | ||
onChange={ ( event ) => setHtml( event.target.value ) } | ||
onChange={ setHtml } | ||
__nextHasNoMarginBottom |
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 is necessary for our effort to deprecate bottom margins - see #38730.
ref={ ref } | ||
className={ clsx( 'block-editor-plain-text', className ) } | ||
onChange={ ( event ) => onChange( event.target.value ) } | ||
__nextHasNoMarginBottom |
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 is necessary for our effort to deprecate bottom margins - see #38730.
blocks: undefined, | ||
selection: undefined, | ||
} ); | ||
} } | ||
className="editor-post-text-editor" | ||
id={ `post-content-${ instanceId }` } | ||
placeholder={ __( 'Start writing with text or HTML' ) } | ||
__nextHasNoMarginBottom |
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 is necessary for our effort to deprecate bottom margins - see #38730.
border: $border-width solid $gray-600; | ||
border-radius: 0; | ||
display: block; | ||
margin: 0; | ||
width: 100%; | ||
box-shadow: none; | ||
resize: none; | ||
/* stylelint-disable-next-line property-no-unknown -- TODO: Update stylelint to support a fresh list of https://github.com/known-css/known-css-properties */ |
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.
Introduced in known-css-properties@0.30.0. Our stylelint
currently uses v0.24.0
.
margin: 0; | ||
width: 100%; | ||
max-height: 248px; // 250, minus the top and bottom border (1px each) | ||
/* stylelint-disable-next-line property-no-unknown -- TODO: Update stylelint to support a fresh list of https://github.com/known-css/known-css-properties */ |
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.
Introduced in known-css-properties@0.30.0. Our stylelint
currently uses v0.24.0
.
@@ -1,11 +1,27 @@ | |||
.block-editor-plain-text { | |||
.block-library-html__edit .block-editor-plain-text.components-base-control { | |||
padding: 0 !important; |
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's an unfortunate padding: 12px !important
that we're trying to override here. Ideally, it wouldn't be there in the first place, but that might be work for another PR.
margin: 0; | ||
width: 100%; | ||
max-height: 248px; // 250, minus the top and bottom border (1px each) |
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.
The wrapper has 250px
max-height declared somewhere else, so we're adapting the textarea
element to match it.
box-shadow: none; | ||
font-family: inherit; | ||
font-size: inherit; | ||
color: inherit; | ||
line-height: inherit; | ||
border: none; | ||
padding: 0; | ||
padding: 12px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with the existing design.
&:focus { | ||
border-color: var(--wp-admin-theme-color); | ||
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color); | ||
|
||
// Elevate the z-index on focus so the focus style is uncropped. | ||
position: relative; | ||
} |
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.
Needed to preserve the original focused field design.
@@ -422,7 +422,7 @@ _::-webkit-full-page-media, _:future, :root .has-multi-selection .block-editor-b | |||
} | |||
} | |||
|
|||
.block-editor-block-list__block .block-editor-block-list__block-html-textarea { | |||
.block-editor-block-list__block .block-editor-block-list__block-html-textarea textarea { |
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 is necessary because TextareaControl
has a couple of wrappers around the textarea
element.
FWIW, it looks like it's been implemented in Webkit (WebKit/WebKit#24195) and like there is some activity on the Firefox side. Let's keep an eye on release notes and on the Google baseline recap site |
What?
Remove the
react-autosize-textarea
package in favor of our built-inTextareaControl
component with the help of thefield-sizing
CSS property.DO NOT MERGE - unfortunately,
field-sizing
is still not supported on Firefox and Safari, so this PR is blocked for the time being. I just wanted to get it working so we have it ready for whenfield-sizing
is widely supported.Why?
The
react-autosize-textarea
package is abandoned and requires additional patching. Using a CSS alternative results in lighter and less code to maintain and ship.It also causes some issues, see the related issues:
Fixes #39619
Fixes #59728
Fixes #61568
Related to #48009 and might potentially be the last one to fix it.
How?
We're using
field-sizing: content;
, which does the magic of auto-resizing the textarea fields.There are a few little implementation details - see my self-review for more information.
Testing Instructions
Testing Instructions for Keyboard
None
Screenshots or screencast
HTML block
Post editor - "Code editor" view.
Edit block as HTML