-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TextareaAutosize: Refactor to TextareaControl
with field-sizing
#64208
base: trunk
Are you sure you want to change the base?
Changes from all commits
01df91a
ca6b1a7
a5df914
57588a1
3b44b14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import TextareaAutosize from 'react-autosize-textarea'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { TextareaControl } from '@wordpress/components'; | ||
import { useEffect, useState } from '@wordpress/element'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { | ||
|
@@ -68,11 +64,12 @@ function BlockHTML( { clientId } ) { | |
}, [ block ] ); | ||
|
||
return ( | ||
<TextareaAutosize | ||
<TextareaControl | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary for our effort to deprecate bottom margins - see #38730. |
||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary because |
||
display: block; | ||
margin: 0; | ||
padding: $grid-unit-15; | ||
|
@@ -432,6 +432,8 @@ _::-webkit-full-page-media, _:future, :root .has-multi-selection .block-editor-b | |
border-radius: 2px; | ||
box-shadow: inset 0 0 0 $border-width $gray-900; | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Introduced in [email protected]. Our |
||
field-sizing: content; | ||
overflow: hidden; | ||
font-family: $editor-html-font; | ||
font-size: $text-editor-font-size; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. There's an unfortunate |
||
|
||
.block-editor-plain-text textarea { | ||
box-shadow: none; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary because |
||
font-family: inherit; | ||
font-size: inherit; | ||
color: inherit; | ||
line-height: inherit; | ||
border: none; | ||
padding: 0; | ||
padding: 12px; | ||
margin: 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency with the existing design. |
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. The wrapper has |
||
field-sizing: content; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Introduced in [email protected]. Our |
||
|
||
&: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; | ||
} | ||
|
||
Comment on lines
+19
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needed to preserve the original focused field design. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import TextareaAutosize from 'react-autosize-textarea'; | ||
import clsx from 'clsx'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { TextareaControl } from '@wordpress/components'; | ||
import { forwardRef } from '@wordpress/element'; | ||
|
||
/** | ||
|
@@ -22,13 +22,13 @@ const PlainText = forwardRef( ( { __experimentalVersion, ...props }, ref ) => { | |
return <EditableText ref={ ref } { ...props } />; | ||
} | ||
|
||
const { className, onChange, ...remainingProps } = props; | ||
const { className, ...remainingProps } = props; | ||
|
||
return ( | ||
<TextareaAutosize | ||
<TextareaControl | ||
ref={ ref } | ||
className={ clsx( 'block-editor-plain-text', className ) } | ||
onChange={ ( event ) => onChange( event.target.value ) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
__nextHasNoMarginBottom | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary for our effort to deprecate bottom margins - see #38730. |
||
{ ...remainingProps } | ||
/> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
|
||
.block-editor-plain-text { | ||
.block-editor-plain-text textarea { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary because |
||
font-family: $default-regular-font; | ||
box-shadow: none; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import Textarea from 'react-autosize-textarea'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
|
@@ -12,7 +7,7 @@ import { useMemo } from '@wordpress/element'; | |
import { __unstableSerializeAndClean } from '@wordpress/blocks'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { useInstanceId } from '@wordpress/compose'; | ||
import { VisuallyHidden } from '@wordpress/components'; | ||
import { TextareaControl, VisuallyHidden } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -62,20 +57,21 @@ export default function PostTextEditor() { | |
> | ||
{ __( 'Type text or HTML' ) } | ||
</VisuallyHidden> | ||
<Textarea | ||
<TextareaControl | ||
autoComplete="off" | ||
dir="auto" | ||
value={ value } | ||
onChange={ ( event ) => { | ||
onChange={ ( newContent ) => { | ||
editEntityRecord( 'postType', type, id, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
content: event.target.value, | ||
content: newContent, | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary for our effort to deprecate bottom margins - see #38730. |
||
</> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
textarea.editor-post-text-editor { | ||
.editor-post-text-editor textarea { | ||
border: $border-width solid $gray-600; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary because |
||
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 */ | ||
field-sizing: content; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Introduced in [email protected]. Our |
||
overflow: hidden; | ||
font-family: $editor-html-font; | ||
line-height: 2.4; | ||
|
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.
TextareaControl
'sonChange
works directly with the value.