From 2b2fc18075af17a5dbf658aa550d03896cc40c7a Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Tue, 9 Apr 2019 11:49:22 +0100 Subject: [PATCH] Add a forwardRef to wp.blockEditor.PlainText (#14866) This is a simple change; it allows users of wp.blockEditor.PlainText to pass a reference to the component. A reference may be useful for users, e.g., to manage the focus. --- packages/block-editor/CHANGELOG.md | 7 ++++--- .../block-editor/src/components/plain-text/README.md | 4 ++++ .../block-editor/src/components/plain-text/index.js | 11 +++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/block-editor/CHANGELOG.md b/packages/block-editor/CHANGELOG.md index 93bfc5a4a9bd3..d5e9d80b71aef 100644 --- a/packages/block-editor/CHANGELOG.md +++ b/packages/block-editor/CHANGELOG.md @@ -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 diff --git a/packages/block-editor/src/components/plain-text/README.md b/packages/block-editor/src/components/plain-text/README.md index 36909597bc6aa..74e8832d519c7 100644 --- a/packages/block-editor/src/components/plain-text/README.md +++ b/packages/block-editor/src/components/plain-text/README.md @@ -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 %} diff --git a/packages/block-editor/src/components/plain-text/index.js b/packages/block-editor/src/components/plain-text/index.js index a186c53ca6a55..2043c46b57b7d 100644 --- a/packages/block-editor/src/components/plain-text/index.js +++ b/packages/block-editor/src/components/plain-text/index.js @@ -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 ( onChange( event.target.value ) } { ...props } /> ); -} +} ); export default PlainText;