Skip to content

Commit

Permalink
[Bug] Add missing textarea control handler. (#1898)
Browse files Browse the repository at this point in the history
* bug(block-editor-utils): add missing TextArea handler

* chore: Add Changeset
  • Loading branch information
theodesp authored Jun 5, 2024
1 parent 456c401 commit f0543e0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .changeset/orange-birds-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'@faustwp/block-editor-utils': patch
---

Adds missing TextAreaControl handler when specifing a `control: 'textarea'` in Component.config.editorFields.

Adding this configuration to your blocks will render TextAreaControls component in the editor.

```js
// Component.js

Component.config = {
name: 'CreateBlockBlockB',
editorFields: {
textArea: {
type: 'string',
label: 'My Message',
location: 'editor',
control: 'textarea' // <--- Render a TextAreaControl field in the Gutenberg editor
},
},
};
```
21 changes: 21 additions & 0 deletions packages/block-editor-utils/src/controls/TextArea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as React from 'react';
import { TextareaControl } from '@wordpress/components';
import { ControlProps } from '../types/index.js';

function TextArea<T extends Record<string, any>>({
config,
props,
}: ControlProps<T>) {
const onChange = (newContent: string) => {
props.setAttributes({ [config.name]: newContent });
};
return (
<TextareaControl
label={config.label}
value={props.attributes[config.name]}
onChange={onChange}
/>
);
}

export default TextArea;
2 changes: 2 additions & 0 deletions packages/block-editor-utils/src/controls/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Select from './Select.js';
import Radio from './Radio.js';
import Range from './Range.js';
import Rich from './RichText.js';
import TextArea from './TextArea.js';

registerControl('text', Text);
registerControl('number', NumberField);
Expand All @@ -16,3 +17,4 @@ registerControl('select', Select);
registerControl('radio', Radio);
registerControl('range', Range);
registerControl('rich-text', Rich);
registerControl('textarea', TextArea);

0 comments on commit f0543e0

Please sign in to comment.