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

Add a forwardRef to wp.blockEditor.PlainText #14866

Merged
merged 2 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/block-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
- Added the `addToGallery` property to the `MediaPlaceholder` component. The component passes the property to the `MediaUpload` component used inside the placeholder.
- Added the `isAppender` property to the `MediaPlaceholder` component. The property changes the look of the placeholder to be adequate to scenarios where new files are added to an already existing set of files, e.g., adding files to a gallery.
- Added the `dropZoneUIOnly` property to the `MediaPlaceholder` component. The property makes the `MediaPlaceholder` only render a dropzone without any other additional UI.
- Added a cancel link to the list of buttons in the `MediaPlaceholder` component which appears if an `onCancel` handler exists
- Added the usage of `mediaPreview` for the `Placeholder` component to the `MediaPlaceholder` component
- Added a an `onDoubleClick` event handler to the `MediaPlaceholder` component
- Added a cancel link to the list of buttons in the `MediaPlaceholder` component which appears if an `onCancel` handler exists.
- Added the usage of `mediaPreview` for the `Placeholder` component to the `MediaPlaceholder` component.
- Added a an `onDoubleClick` event handler to the `MediaPlaceholder` component.
- Added a way to pass special `ref` property to the `PlainText` component.

### Breaking Changes

Expand Down
4 changes: 4 additions & 0 deletions packages/block-editor/src/components/plain-text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Render an auto-growing textarea allow users to fill any textual content.

You can also pass any extra prop to the textarea rendered by this component.

### `ref: Object`

*Optional.* The component forwards the `ref` property to the `TextareaAutosize` component.

## Example

{% codetabs %}
Expand Down
11 changes: 9 additions & 2 deletions packages/block-editor/src/components/plain-text/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@

/**
* WordPress dependencies
*/
import { forwardRef } from '@wordpress/element';

/**
* External dependencies
*/
import TextareaAutosize from 'react-autosize-textarea';
import classnames from 'classnames';

function PlainText( { onChange, className, ...props } ) {
const PlainText = forwardRef( ( { onChange, className, ...props }, ref ) => {
return (
<TextareaAutosize
ref={ ref }
className={ classnames( 'editor-plain-text block-editor-plain-text', className ) }
onChange={ ( event ) => onChange( event.target.value ) }
{ ...props }
/>
);
}
} );

export default PlainText;