Skip to content

Commit

Permalink
Allowing for more fine tuning of Quill without rewriting RichTextInput (
Browse files Browse the repository at this point in the history
#3714)

* allowing for more fine tuning of Quill without rewriting RichTextInput

* Adding coma to pass travis-ci

* Adding coma to pass travis-ci

* documenting new  prop for RichTextInput

* Renaming new props as per @Kmaschta's request
  • Loading branch information
Sheraff authored and fzaninotto committed Oct 9, 2019
1 parent d03447c commit 7419ff1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/Inputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,18 @@ You can customize the rich text editor toolbar using the `toolbar` attribute, as
<RichTextInput source="body" toolbar={[ ['bold', 'italic', 'underline', 'link'] ]} />
```
If you need more customization, you can access the quill object through the `configureQuill` callback that will be called just after its initialization.
```js
const configureQuill = quill => quill.getModule('toolbar').addHandler('bold', function (value) {
this.quill.format('bold', value)
});

// ...

<RichTextInput source="text" configureQuill={configureQuill}/>
```
## `<SelectInput>`
To let users choose a value in a list using a dropdown, use `<SelectInput>`. It renders using [Material ui's `<Select>`](http://material-ui.com/api/select). Set the `choices` attribute to determine the options (with `id`, `name` tuples):
Expand Down
12 changes: 12 additions & 0 deletions packages/ra-input-rich-text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ You can customize the rich text editor toolbar using the `toolbar` attribute, as
<RichTextInput source="body" toolbar={[ ['bold', 'italic', 'underline', 'link'] ]} />
```

If you need more customization, you can access the quill object through the `configureQuill` callback that will be called just after its initialization.

```js
const configureQuill = quill => quill.getModule('toolbar').addHandler('bold', function (value) {
this.quill.format('bold', value)
});

// ...

<RichTextInput source="text" configureQuill={configureQuill}/>
```

## License

This library is licensed under the MIT License, and sponsored by [marmelab](http://marmelab.com).
5 changes: 5 additions & 0 deletions packages/ra-input-rich-text/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class RichTextInput extends Component {
}),
]),
fullWidth: PropTypes.bool,
configureQuill: PropTypes.func,
};

static defaultProps = {
Expand All @@ -52,6 +53,10 @@ export class RichTextInput extends Component {
...options,
});

if (this.props.configureQuill) {
this.props.configureQuill(this.quill);
}

this.quill.setContents(this.quill.clipboard.convert(value));

this.editor = this.divRef.querySelector('.ql-editor');
Expand Down

0 comments on commit 7419ff1

Please sign in to comment.